graview 0.1.53 → 0.1.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +6 -6
  3. package/dist/index.js.map +1 -1
  4. package/dist/preview/{chunk.Z4YSCHZT.js → chunk.27ZSRO3O.js} +1 -1
  5. package/dist/preview/{chunk.PEA4D66Y.js → chunk.2HANQ737.js} +1 -1
  6. package/dist/preview/{chunk.VRJ4TULC.js → chunk.2KH2LWZL.js} +1 -1
  7. package/dist/preview/{chunk.YI7WHBAD.js → chunk.2ORJGMRT.js} +2 -2
  8. package/dist/preview/{chunk.AQJD23AN.js → chunk.2SWQI4HF.js} +1 -1
  9. package/dist/preview/{chunk.5XFRWXYQ.js → chunk.354A4QCG.js} +1 -1
  10. package/dist/preview/chunk.35O5H5L7.js +2 -0
  11. package/dist/preview/chunk.3IZOXNJH.js +1 -0
  12. package/dist/preview/{chunk.HDXDYS4C.js → chunk.4BFJWNVM.js} +1 -1
  13. package/dist/preview/{chunk.GANAZIRD.js → chunk.4OMSQFIY.js} +1 -1
  14. package/dist/preview/{chunk.4SVAHPJA.js → chunk.4TLWZVVG.js} +1 -1
  15. package/dist/preview/chunk.5D6SIBOK.js +1 -0
  16. package/dist/preview/{chunk.ICYJ7QJG.js → chunk.5DPFAVCZ.js} +1 -1
  17. package/dist/preview/{chunk.5K5D4IMM.js → chunk.5EOSEVZB.js} +1 -1
  18. package/dist/preview/{chunk.MT45H2T5.js → chunk.5EZDXWOE.js} +1 -1
  19. package/dist/preview/{chunk.OPKXCL5R.js → chunk.5L4J2XAI.js} +1 -1
  20. package/dist/preview/{chunk.U4T4Y2MT.js → chunk.5MCXTY2P.js} +1 -1
  21. package/dist/preview/{chunk.K7WME4P4.js → chunk.5MSNKSTE.js} +1 -1
  22. package/dist/preview/{chunk.3FRVG6JW.js → chunk.5SANELJT.js} +2 -2
  23. package/dist/preview/chunk.5XUVCM7X.js +1 -0
  24. package/dist/preview/{chunk.CIUQWCU4.js → chunk.62LPYPP3.js} +1 -1
  25. package/dist/preview/{chunk.S6TN3MLY.js → chunk.644FUGSX.js} +1 -1
  26. package/dist/preview/{chunk.UYCPQ6IW.js → chunk.6JYNNPAI.js} +1 -1
  27. package/dist/preview/chunk.6NGSR2ZQ.js +1 -0
  28. package/dist/preview/{chunk.6ESAZJBN.js → chunk.6NQQUIBX.js} +1 -1
  29. package/dist/preview/{chunk.CSA6SWTI.js → chunk.6UAUME5U.js} +1 -1
  30. package/dist/preview/{chunk.G226CUJQ.js → chunk.6ZJE5M2A.js} +1 -1
  31. package/dist/preview/chunk.7ECBGIUK.js +1 -0
  32. package/dist/preview/chunk.7KERB5CH.js +1 -0
  33. package/dist/preview/chunk.7WEQHJ3N.js +6 -0
  34. package/dist/preview/{chunk.OCWZJNZF.js → chunk.7Y6NK5CT.js} +1 -1
  35. package/dist/preview/{chunk.I6W3IQ4W.js → chunk.AFEEXRN3.js} +1 -1
  36. package/dist/preview/{chunk.YA7ZMGOL.js → chunk.AFK5HHLL.js} +1 -1
  37. package/dist/preview/{chunk.MSPRCR3Q.js → chunk.ATXSLBE3.js} +1 -1
  38. package/dist/preview/chunk.AVNOLMCV.js +1 -0
  39. package/dist/preview/chunk.AVVNQKA7.js +1 -0
  40. package/dist/preview/chunk.AZ6Q3WT2.js +1 -0
  41. package/dist/preview/chunk.BJUUSIQY.js +1 -0
  42. package/dist/preview/{chunk.4DCPB67O.js → chunk.BRCKXL7B.js} +1 -1
  43. package/dist/preview/{chunk.LAOZEYYQ.js → chunk.CM2ETM2A.js} +2 -2
  44. package/dist/preview/{chunk.Y4VOCJ7R.js → chunk.CPNE6HPQ.js} +1 -1
  45. package/dist/preview/{chunk.UVMLX4US.js → chunk.DB3HOKZD.js} +1 -1
  46. package/dist/preview/{chunk.W54NXXC5.js → chunk.DBCVZGCC.js} +1 -1
  47. package/dist/preview/{chunk.USAGE5C6.js → chunk.DH4AC7TC.js} +1 -1
  48. package/dist/preview/{chunk.CANTHIRO.js → chunk.DKJK2MMV.js} +1 -1
  49. package/dist/preview/{chunk.XBNASVTY.js → chunk.DNJM6WQO.js} +1 -1
  50. package/dist/preview/{chunk.NAEEPUWJ.js → chunk.DU75P3Y7.js} +1 -1
  51. package/dist/preview/chunk.DVG47BK3.js +1 -0
  52. package/dist/preview/{chunk.FGJM4LJO.js → chunk.DXJFAAOI.js} +1 -1
  53. package/dist/preview/{chunk.NCTTPW7A.js → chunk.EGSE6NNE.js} +1 -1
  54. package/dist/preview/{chunk.MKWVNW4Q.js → chunk.EJXUOL2C.js} +3 -3
  55. package/dist/preview/{chunk.3FUFVVR4.js → chunk.EKP3HQAX.js} +1 -1
  56. package/dist/preview/{chunk.SLBWPVIY.js → chunk.FQLNBIQ5.js} +1 -1
  57. package/dist/preview/chunk.FTW3K3G6.js +5 -0
  58. package/dist/preview/{chunk.BB5XKTVC.js → chunk.FUS2FJS3.js} +1 -1
  59. package/dist/preview/{chunk.LCG3VLCB.js → chunk.FUZWXKTN.js} +1 -1
  60. package/dist/preview/chunk.FVOFTM5J.js +1 -0
  61. package/dist/preview/{chunk.WDEMPWS4.js → chunk.G2XDQPE4.js} +1 -1
  62. package/dist/preview/{chunk.N6A3DIOY.js → chunk.G5XTASMO.js} +1 -1
  63. package/dist/preview/chunk.H536YUAZ.js +3 -0
  64. package/dist/preview/chunk.HNJFBI7J.js +1 -0
  65. package/dist/preview/{chunk.VTCPA4V4.js → chunk.HUABTCQE.js} +1 -1
  66. package/dist/preview/{chunk.HIFLBWQJ.js → chunk.HXHFWZ2U.js} +2 -2
  67. package/dist/preview/{chunk.GZBODS7Z.js → chunk.HXR7EEXR.js} +1 -1
  68. package/dist/preview/chunk.INBHY3SA.js +1 -0
  69. package/dist/preview/{chunk.OZYZBRWO.js → chunk.IXHLP2CL.js} +1 -1
  70. package/dist/preview/{chunk.RIS3OKAI.js → chunk.JRRVLGEK.js} +1 -1
  71. package/dist/preview/{chunk.GPYZR6HE.js → chunk.K5WPS4RR.js} +1 -1
  72. package/dist/preview/{chunk.KAKJYAHM.js → chunk.KHJ2MCMS.js} +1 -1
  73. package/dist/preview/{chunk.56UFDIX5.js → chunk.KIMIPHAI.js} +1 -1
  74. package/dist/preview/{chunk.MDIAWTNK.js → chunk.KVQZ5FR6.js} +1 -1
  75. package/dist/preview/chunk.KXNWZ33P.js +1 -0
  76. package/dist/preview/{chunk.6S3B4XC4.js → chunk.LEPKPNPA.js} +1 -1
  77. package/dist/preview/chunk.LLXEWLIP.js +1 -0
  78. package/dist/preview/{chunk.G6DISMVT.js → chunk.LMXNHBGH.js} +2 -2
  79. package/dist/preview/{chunk.QATG5HNV.js → chunk.LQCH2NFE.js} +1 -1
  80. package/dist/preview/{chunk.KCM2VOC7.js → chunk.LWLI5PI4.js} +1 -1
  81. package/dist/preview/{chunk.FCAKLO5U.js → chunk.LYVRXRIH.js} +1 -1
  82. package/dist/preview/{chunk.5E4UGVAD.js → chunk.MFCBAQS3.js} +1 -1
  83. package/dist/preview/{chunk.TXEWSZGO.js → chunk.MFOSEOF4.js} +1 -1
  84. package/dist/preview/{chunk.S2ATSY6P.js → chunk.MIQMPOWF.js} +1 -1
  85. package/dist/preview/{chunk.7BXOQEUP.js → chunk.MNSKBGRM.js} +1 -1
  86. package/dist/preview/chunk.MSM6E6JK.js +1 -0
  87. package/dist/preview/{chunk.ULTYDYTS.js → chunk.NDLQXQV2.js} +2 -2
  88. package/dist/preview/chunk.NS6KWKF5.js +1 -0
  89. package/dist/preview/{chunk.JKCLYLT4.js → chunk.NXM73RZA.js} +1 -1
  90. package/dist/preview/{chunk.A2RQFAZ6.js → chunk.O752PM42.js} +1 -1
  91. package/dist/preview/{chunk.6CVW53WA.js → chunk.O7RMVGAB.js} +1 -1
  92. package/dist/preview/{chunk.65F3DF5Q.js → chunk.OIMYSR2J.js} +1 -1
  93. package/dist/preview/{chunk.TTFYXKLI.js → chunk.OL2N5NUV.js} +1 -1
  94. package/dist/preview/chunk.OS5EALHY.js +1 -0
  95. package/dist/preview/{chunk.XDEKL6TJ.js → chunk.OT6EWYK2.js} +1 -1
  96. package/dist/preview/chunk.P4ZZSFOQ.js +1 -0
  97. package/dist/preview/{chunk.BPPDBPTL.js → chunk.PCKX2FHR.js} +1 -1
  98. package/dist/preview/{chunk.VOHDRH3P.js → chunk.PHLMQO7V.js} +2 -2
  99. package/dist/preview/{chunk.FJN4OGAS.js → chunk.PIHCXN5U.js} +2 -2
  100. package/dist/preview/{chunk.FBRARPGR.js → chunk.PIQ52FCI.js} +2 -2
  101. package/dist/preview/{chunk.XFIZLWYA.js → chunk.PM64C5PX.js} +1 -1
  102. package/dist/preview/chunk.PSLCI3GO.js +2 -0
  103. package/dist/preview/chunk.QBMIET7P.js +1 -0
  104. package/dist/preview/{chunk.R3DWF35R.js → chunk.QIAH7HHO.js} +1 -1
  105. package/dist/preview/chunk.QJ42D5GM.js +1 -0
  106. package/dist/preview/{chunk.IYVBJDR7.js → chunk.QQ3YWKWU.js} +1 -1
  107. package/dist/preview/{chunk.36XV4ZMC.js → chunk.QWICAV2C.js} +2 -2
  108. package/dist/preview/chunk.R3ZS4QO6.js +18 -0
  109. package/dist/preview/{chunk.LDLWYAHK.js → chunk.RNYLNBIB.js} +1 -1
  110. package/dist/preview/{chunk.H6EMDQP5.js → chunk.RPVJ5IXD.js} +1 -1
  111. package/dist/preview/{chunk.CWPRQSED.js → chunk.RZQKCLTW.js} +1 -1
  112. package/dist/preview/chunk.SDLUWRGI.js +1 -0
  113. package/dist/preview/chunk.SG67ID6C.js +1 -0
  114. package/dist/preview/{chunk.UQENE3VE.js → chunk.SIABGHF2.js} +1 -1
  115. package/dist/preview/{chunk.UQ4CASST.js → chunk.SUGOENC4.js} +1 -1
  116. package/dist/preview/chunk.SYX7AEHU.js +1 -0
  117. package/dist/preview/{chunk.72Q4R7N6.js → chunk.T66UK7PQ.js} +1 -1
  118. package/dist/preview/{chunk.3377DLPA.js → chunk.TAQB64FZ.js} +1 -1
  119. package/dist/preview/{chunk.ASCTAUFD.js → chunk.TDV7JGIQ.js} +1 -1
  120. package/dist/preview/chunk.TEE23CVQ.js +1 -0
  121. package/dist/preview/{chunk.HAIHXBVX.js → chunk.TT6GKRBE.js} +1 -1
  122. package/dist/preview/{chunk.DQPEVPKQ.js → chunk.TUBAFVV4.js} +2 -2
  123. package/dist/preview/chunk.TZTRGNAA.js +1 -0
  124. package/dist/preview/{chunk.DUZS52WX.js → chunk.U5AX4DD5.js} +1 -1
  125. package/dist/preview/chunk.UADL2LHO.js +1 -0
  126. package/dist/preview/{chunk.TLQTDKOL.js → chunk.UE5GAP67.js} +2 -2
  127. package/dist/preview/{chunk.HBVURYWY.js → chunk.URDCHVH3.js} +2 -2
  128. package/dist/preview/{chunk.GBIVIHGD.js → chunk.USJ4J3GL.js} +2 -2
  129. package/dist/preview/{chunk.E647LWH5.js → chunk.V5PAFSWP.js} +2 -2
  130. package/dist/preview/chunk.WR63RQGU.js +5 -0
  131. package/dist/preview/chunk.WSMYFEGU.js +25 -0
  132. package/dist/preview/{chunk.2LQ37DC2.js → chunk.WUFCRE7O.js} +1 -1
  133. package/dist/preview/{chunk.7NFCI4LH.js → chunk.WVKXELAF.js} +2 -2
  134. package/dist/preview/{chunk.UXNZPPWR.js → chunk.XEHLSKHP.js} +1 -1
  135. package/dist/preview/{chunk.CYP5KXIQ.js → chunk.XSMXSNDR.js} +1 -1
  136. package/dist/preview/chunk.XTP5DGPJ.js +88 -0
  137. package/dist/preview/{chunk.BG2SC77J.js → chunk.XUHY4XO2.js} +1 -1
  138. package/dist/preview/{chunk.EZXGVTT2.js → chunk.Y3BEKXYB.js} +1 -1
  139. package/dist/preview/chunk.YG2WZO53.js +1 -0
  140. package/dist/preview/{chunk.KWMBRB6O.js → chunk.YGZGMRDC.js} +1 -1
  141. package/dist/preview/{chunk.P7FN3SFB.js → chunk.YOBRVKJT.js} +1 -1
  142. package/dist/preview/{chunk.E52UTLQ2.js → chunk.YRFN4VDD.js} +1 -1
  143. package/dist/preview/{chunk.T56SOSIR.js → chunk.YYWANGIC.js} +1 -1
  144. package/dist/preview/{chunk.JCJ7NTW4.js → chunk.ZAHVKXYQ.js} +1 -1
  145. package/dist/preview/{chunk.RUTZEEBR.js → chunk.ZOW7AC7U.js} +1 -1
  146. package/dist/preview/{chunk.J6OT74RM.js → chunk.ZPXAKRKG.js} +1 -1
  147. package/dist/preview/{chunk.JQTO52Q7.js → chunk.ZXOD5GM3.js} +1 -1
  148. package/dist/preview/index.html +52 -52
  149. package/dist/preview/page.js +2 -2
  150. package/package.json +6 -6
  151. package/dist/preview/chunk.2IKVO743.js +0 -1
  152. package/dist/preview/chunk.34Q7OKK3.js +0 -1
  153. package/dist/preview/chunk.3Y7BDRP3.js +0 -1
  154. package/dist/preview/chunk.4DFO43VM.js +0 -1
  155. package/dist/preview/chunk.4QVZXCV5.js +0 -1
  156. package/dist/preview/chunk.52Y37IAD.js +0 -1
  157. package/dist/preview/chunk.5H3VCAPN.js +0 -1
  158. package/dist/preview/chunk.6W2DUW5S.js +0 -5
  159. package/dist/preview/chunk.7R6GXJS4.js +0 -6
  160. package/dist/preview/chunk.B3T4N2XM.js +0 -25
  161. package/dist/preview/chunk.BQHRZJ5Z.js +0 -1
  162. package/dist/preview/chunk.D3A24PQ6.js +0 -1
  163. package/dist/preview/chunk.EG2N5F6L.js +0 -1
  164. package/dist/preview/chunk.FXNUR5JI.js +0 -88
  165. package/dist/preview/chunk.GGHZEAAT.js +0 -1
  166. package/dist/preview/chunk.GYO57LKD.js +0 -1
  167. package/dist/preview/chunk.GZWC72HS.js +0 -1
  168. package/dist/preview/chunk.H2B3SEI7.js +0 -1
  169. package/dist/preview/chunk.HE545Z6I.js +0 -1
  170. package/dist/preview/chunk.HIDLE6BN.js +0 -18
  171. package/dist/preview/chunk.I62MCBQM.js +0 -1
  172. package/dist/preview/chunk.I6SUHXJF.js +0 -1
  173. package/dist/preview/chunk.JRU5BT7K.js +0 -5
  174. package/dist/preview/chunk.LEKML4S4.js +0 -1
  175. package/dist/preview/chunk.MXTDQXVW.js +0 -1
  176. package/dist/preview/chunk.OP3ZUI4W.js +0 -1
  177. package/dist/preview/chunk.OXLYDXQV.js +0 -1
  178. package/dist/preview/chunk.P2W727C7.js +0 -1
  179. package/dist/preview/chunk.PFXGWY3P.js +0 -1
  180. package/dist/preview/chunk.Q5JVKSEN.js +0 -1
  181. package/dist/preview/chunk.Q5WEOX3Q.js +0 -1
  182. package/dist/preview/chunk.SHNYYBNW.js +0 -1
  183. package/dist/preview/chunk.THL67D77.js +0 -1
  184. package/dist/preview/chunk.TI4OSTQV.js +0 -1
  185. package/dist/preview/chunk.TRPPN2GD.js +0 -2
  186. package/dist/preview/chunk.VTRI2MT2.js +0 -2
  187. package/dist/preview/chunk.XXCT6DLX.js +0 -1
  188. package/dist/preview/chunk.ZJXUWOG3.js +0 -1
  189. package/dist/preview/chunk.ZQWKS6K5.js +0 -1
  190. package/dist/preview/chunk.ZYYM52N5.js +0 -1
@@ -1 +0,0 @@
1
- import"./chunk.AJZBJBMO.js";var W=1200,Y="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",q=4e7,A=e=>/^image\//i.test(e.type)&&!/^image\/svg/i.test(e.type);function w(e,t={}){let u={name:e.name,type:e.type,bytes:e.bytes};return/^video\//i.test(e.type)?{...u,...e.width!==void 0?{width:e.width}:{},...e.height!==void 0?{height:e.height}:{},...e.caption!==void 0?{caption:e.caption}:{},...e.duration!==void 0?{duration:e.duration}:{}}:A(e)?{...u,...e.width!==void 0?{width:e.width}:{},...e.height!==void 0?{height:e.height}:{},...e.caption!==void 0?{caption:e.caption}:{},...t.src!==void 0?{src:t.src}:{},...t.left!==void 0?{left:t.left}:{}}:u}var z=new Set(["id","kind","label"]),L=e=>{let t=e;return typeof t=="object"&&t!==null&&typeof t.href=="string"&&typeof t.name=="string"&&typeof t.type=="string"&&typeof t.bytes=="number"};function R(e,t){let u=o=>{let d;for(let[f,c]of Object.entries(o)){if(z.has(f))continue;let l=L(c)?t(c,o):Array.isArray(c)&&c.length>0&&c.every(L)?c.map(a=>t(a,o)):void 0;l!==void 0&&((d??={...o})[f]=l)}return d??o};return{...e,...e.node?{node:u(e.node)}:{},...e.nodes?{nodes:e.nodes.map(u)}:{}}}var B=e=>e.toLocaleString("en-US"),_=(e,t)=>`The picture "${e.name}" on ${t.label?`"${t.label}"`:"a record"}`;function C(e,t,u){let o=e===!0?1200:e.width??1200,d=t?.pictureBytes??15e5,f=t?.picturesBytes??12e6,c=Math.round(o*Math.min(2,Math.max(1,u||1)));return{width:o,perFile:d,perView:f,need:c,reckon:a=>Math.min(d,Math.ceil(a.bytes*(a.width&&a.width>c?(c/a.width)**2:1)))}}var M=(e,t)=>`${_(e,t)} is left out: at ${B(e.bytes)} bytes it is more than the host fetches for a view.`,N=(e,t,u,o)=>`${_(e,t)} is left out: the view ${u} is handed at most ${B(o)} bytes of pictures, and the pictures before it took them.`;function K(e,t){let{perView:u,reckon:o}=C(t.pictures,t.limits,2),d=[],f=0;return{props:R(e,(l,a)=>{if(!A(l))return w(l);let p=y=>(d.includes(y)||d.push(y),w(l,{left:y}));if(l.bytes>4e7)return p(M(l,a));let P=o(l);return f+P>u?p(N(l,a,t.view,u)):(f+=P,w(l,{src:t.standIn}))}),left:d}}function Q(e,t){let{width:u,perFile:o,perView:d,need:f,reckon:c}=C(t.pictures,t.limits,e.devicePixelRatio),l=t.shrink??((n,r,s)=>D(e,n,r,s)),a=new Map,p=new Map,P=new Set,y=!1,v=!1,F=()=>{v||y||(v=!0,queueMicrotask(()=>{v=!1,y||t.moved()}))},G=n=>{P.has(n)||(P.add(n),t.onLeft?.(n))},T=n=>{n?.state==="ready"&&(p.delete(n.url),n.url.startsWith("blob:")&&e.URL.revokeObjectURL(n.url))},E=_,k,S=n=>new Promise(r=>{let s=new e.Image;s.onload=()=>r(!0),s.onerror=()=>r(!1),e.setTimeout(()=>r(!1),2e3),s.src=n}),x=n=>new Promise((r,s)=>{let b=new e.FileReader;b.onload=()=>r(String(b.result)),b.onerror=s,b.readAsDataURL(n)}),H=async n=>{if(t.as==="blob"){let s=e.URL.createObjectURL(n);return k??=S(s),await k?{url:s,drawn:s}:{url:s,drawn:await x(n)}}let r=await x(n);return{url:r,drawn:r}},I=(n,r,s)=>({state:"left",said:`${E(n,r)} could not be loaded for the view ${t.view}${s?`: the host answered ${s}.`:"."}${s&&!t.file?" A host that serves the app under a base says where a record's files are (file, on the view's definition).":""}`}),O=async(n,r)=>{let s=I(n,r),b=t.file?t.file(n.href):n.href;if(b===void 0)return s;let i=new e.URL(b,e.document.baseURI);if(i.origin!==e.location.origin||!/^https?:$/.test(i.protocol))return s;let m=await e.fetch(i.href,{credentials:"same-origin"}),h=(m.headers.get("content-type")??"").split(";")[0].trim();if(!m.ok)return I(n,r,String(m.status));if(!A({type:h}))return I(n,r,`${h||"no type"}, not a picture`);let g=new e.Blob([await m.arrayBuffer()],{type:h});if(g.size>4e7)return s;if(!(n.width!==void 0&&n.width<=f)||g.size>o){let V=await l(g,f,o).catch(()=>{});if(V)g=V;else if(g.size>o)return s}return g.size>o?{state:"left",said:`${E(n,r)} is left out: made as small as the ${B(u)} pixels across the view ${t.view} draws a picture at, it is still more than the ${B(o)} bytes one picture is handed.`}:{state:"ready",...await H(g),bytes:g.size}},j=(n,r)=>{a.set(n.href,{state:"pending",bytes:c(n)}),O(n,r).then(s=>U(n.href,s),()=>U(n.href,{state:"left",said:`${E(n,r)} could not be loaded for the view ${t.view}.`}))},U=(n,r)=>{if(y||a.get(n)?.state!=="pending")return T(r);a.set(n,r),r.state==="ready"&&p.set(r.url,r.drawn),r.state==="left"&&G(r.said),F()};return{hand(n){if(y)return R(n,i=>w(i));let r=0,s=new Set,b=R(n,(i,m)=>{if(!A(i))return w(i);s.add(i.href);let h=a.get(i.href);if(h?.state==="left")return w(i,{left:h.said});if(!h&&i.bytes>4e7)return h={state:"left",said:M(i,m)},a.set(i.href,h),G(h.said),w(i,{left:h.said});let g=h?h.bytes:c(i);if(r+g>d){let $=N(i,m,t.view,d);return G($),w(i,{left:$})}return r+=g,h||j(i,m),w(i,h?.state==="ready"?{src:h.url}:{})});for(let[i,m]of a)s.has(i)||(T(m),a.delete(i));return b},drawn:n=>p.get(n),waiting:()=>[...a.values()].some(n=>n.state==="pending"),dispose(){y=!0;for(let n of a.values())T(n);a.clear(),p.clear()}}}async function D(e,t,u,o){if(typeof e.createImageBitmap!="function")return;let d=await e.createImageBitmap(t);try{if(d.width<=u&&t.size<=o)return t;let f=Math.min(1,u/d.width),c=Math.max(1,Math.round(d.width*f)),l=Math.max(1,Math.round(d.height*f)),a=e.document.createElement("canvas");a.width=c,a.height=l;let p=a.getContext("2d");if(!p)return;p.drawImage(d,0,0,c,l);let P=F=>new Promise(G=>a.toBlob(G,F,.85)),y=/^image\/(jpeg|webp|png)$/i.test(t.type)?t.type:"image/png",v=await P(y);return v&&v.size<=o?v:await P("image/jpeg")??v??void 0}finally{d.close()}}export{q as PICTURE_FETCH_BYTES,Y as PICTURE_STAND_IN,W as PICTURE_WIDTH,Q as createGuestPictures,w as guestFileOf,R as handFiles,A as isGuestPicture,C as pictureBudget,K as standInPictures};
@@ -1 +0,0 @@
1
- import{a,b}from"./chunk.6ESAZJBN.js";import"./chunk.OZYZBRWO.js";import"./chunk.G6DISMVT.js";import"./chunk.W54NXXC5.js";import"./chunk.B3T4N2XM.js";import"./chunk.SDO3U72B.js";import"./chunk.6W2DUW5S.js";import"./chunk.SLBWPVIY.js";import"./chunk.AJZBJBMO.js";export{a as ActivityFilter,b as InteractionRow};
@@ -1 +0,0 @@
1
- var r=Symbol.for("@graview/core:seat"),o=e=>e[r];export{o as a};
@@ -1,2 +0,0 @@
1
- import{Da as Q,F,G as B,I as L,Jb as I,La as X,O,Qb as en,R as j,S as J,T as U,U as K,Wa as v,Za as nn,_ as P,aa as Z,la as z}from"./chunk.6W2DUW5S.js";var un=1e4,g=class{constructor(s){this.nodes=s}},rn=Symbol.for("@graview/core:far-record"),fn=e=>typeof e=="object"&&e!==null&&e[rn]===!0;function cn(e){let s={...e.fields,id:`@${e.address}/${e.kind}:${e.id}`,kind:`@${e.address}/${e.kind}`,label:e.label};return Object.defineProperty(s,rn,{value:!0}),s}function Nn(e){let s=`the linked record in ${e.ref.address}`;return e.reason==="denied"?`${s} is not one this viewer may open`:`${s} has not been read`}var pn="",f=class extends Error{constructor(c,l){super(c);this.sentence=c;this.at=l}},W=class extends f{},V=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof g)&&typeof e.id=="string",tn=e=>{let s=new Set;return new g(e.filter(c=>!s.has(c.id)&&s.add(c.id)))},w=e=>e===null?"nothing":e instanceof g?"a set of records":Array.isArray(e)?"a list":V(e)?"a record":typeof e=="string"?"a word":typeof e;function on(e,s){let c=s.budget??un,l=(n,a)=>{if(c-=n,c<0)throw new W("this rule looks at too much of the graph to judge in one go",a)},u=s.today??L(),b=s.now??new Date().toISOString(),k=new Map,N=new Set,A=s.bindings,H=(n,a,t,o)=>{let d=`${n?.id}\0${a}`;if(k.has(d))return k.get(d);if(N.has(d))throw new f(`"${a}"${n?` of ${z(n.kind)}`:""} depends on itself`,o);N.add(d);let r=A;A=void 0;try{let i=$(t,n);return k.set(d,i),i}finally{A=r,N.delete(d)}},E=(n,a,t)=>{l(1,t);let o=s.kinds.get(n.kind),d=o?.computed?.get(a);if(d)return H(n,a,d,t);let r=o?.linked?.get(a);if(r){let y=Q(Object.hasOwn(n,a)?n[a]:void 0,r);l(y.length,t);let m=s.linked??X(s.graph),h=y.flatMap(x=>{let C=m?m(x):{unread:!0};return"record"in C?[cn(C.record)]:(s.onUnread?.({relation:a,ref:x,reason:"denied"in C?"denied":"unread"}),[])});return r.cardinality==="one"?h[0]??null:new g(h)}let i=Object.hasOwn(n,a);if(o?.fields.has(a)||i){let y=i?v(n,a,u):void 0;return y===void 0?null:y}let p=o?.edges.get(a);if(p){let y=s.graph.out(n.id,a);return l(y.length,t),p==="one"?y[0]??null:new g(y)}if(a==="id")return n.id;if(fn(n))return null;throw new f(`${z(n.kind)} has no field or relation called "${a}"`,t)},S=(n,a,t)=>{if(n instanceof g)return n;if(n===null)return new g([]);if(V(n))return new g([n]);throw new f(`${t}(\u2026) needs a set of records, and was given ${w(n)}`,a)},G=(n,a,t)=>{if(n===null)return null;if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean")return String(n);throw new f(`${t}(\u2026) needs a word, and was given ${w(n)}`,a)},_=(n,a,t)=>{let o=G(n,a,t);if(o===null)return null;let d=Date.parse(o.length===10?`${o}T00:00:00Z`:o);if(Number.isNaN(d))throw new f(`${t}(\u2026) needs a date, and "${o}" is not one`,a);return d},M=(n,a)=>V(n)&&V(a)?n.id===a.id:V(n)&&typeof a=="string"?n.id===a:typeof n=="string"&&V(a)?n===a.id:Array.isArray(n)&&Array.isArray(a)?n.length===a.length&&n.every((t,o)=>M(t,a[o])):n===a,R=(n,a,t)=>{if(n===null)return!1;if(typeof n=="boolean")return n;throw new f(`${t} must be true or false, and was ${w(n)}`,a)},T=(n,a)=>$(a,n);function $(n,a){switch(l(1,n.at),n.t){case"lit":return n.value;case"list":return n.items.map(t=>$(t,a));case"ident":{let t=A&&Object.hasOwn(A,n.name)?A[n.name]:void 0;if(t!==void 0)return t;if(a)return E(a,n.name,n.at);throw new f(`"${n.name}" means nothing in a rule over the whole graph`,n.at)}case"member":{let t=$(n.object,a);if(t===null)return null;if(V(t))return E(t,n.name,n.at);throw new f(`".${n.name}" needs a record before it, and was given ${w(t)}`,n.at)}case"unary":{let t=$(n.operand,a);if(n.op==="!")return!R(t,n.at,"what follows not");if(t===null)return null;if(typeof t!="number")throw new f(`"-" needs a number, and was given ${w(t)}`,n.at);return-t}case"where":{let t=S($(n.set,a),n.at,"where");return l(t.nodes.length,n.at),new g(t.nodes.filter(o=>R(T(o,n.filter),n.at,"a where condition")))}case"binary":return dn(n,a);case"call":return ln(n,a)}}function dn(n,a){if(n.op==="&&")return R($(n.left,a),n.at,"each side of and")&&R($(n.right,a),n.at,"each side of and");if(n.op==="||")return R($(n.left,a),n.at,"each side of or")||R($(n.right,a),n.at,"each side of or");let t=$(n.left,a),o=$(n.right,a);if(n.op==="&"||n.op==="|"||n.op==="-"&&(t instanceof g||o instanceof g)){let d=S(t,n.at,n.op).nodes,r=S(o,n.at,n.op).nodes;l(d.length+r.length,n.at);let i=new Set(r.map(p=>p.id));return tn(n.op==="|"?[...d,...r]:d.filter(p=>i.has(p.id)===(n.op==="&")))}switch(n.op){case"==":return M(t,o);case"!=":return!M(t,o);case"in":{if(o===null)return!1;if(o instanceof g)return o.nodes.some(d=>M(t,d));if(Array.isArray(o))return o.some(d=>M(t,d));if(typeof o=="string"&&typeof t=="string")return o.includes(t);throw new f(`"in" needs a list or a set on its right, and was given ${w(o)}`,n.at)}case"<":case"<=":case">":case">=":{if(t===null||o===null)return!1;if(!(typeof t=="number"&&typeof o=="number"||typeof t=="string"&&typeof o=="string"))throw new f(`cannot compare ${w(t)} with ${w(o)}`,n.at);return n.op==="<"?t<o:n.op==="<="?t<=o:n.op===">"?t>o:t>=o}default:{if(t===null||o===null)return null;if(n.op==="+"&&(typeof t=="string"||typeof o=="string")){let d=`${G(t,n.at,"+")}${G(o,n.at,"+")}`;if(d.length>1e4)throw new f("that makes a word too long",n.at);return d}if(typeof t!="number"||typeof o!="number")throw new f(`"${n.op}" needs numbers, and was given ${w(t)} and ${w(o)}`,n.at);return(n.op==="/"||n.op==="%")&&o===0?null:n.op==="+"?t+o:n.op==="-"?t-o:n.op==="*"?t*o:n.op==="/"?t/o:t%o}}}function ln(n,a){let t=(r,i=r)=>{if(n.args.length<r||n.args.length>i)throw new f(`${n.fn}(\u2026) takes ${r===i?r:`${r} to ${i}`} argument${i===1?"":"s"}`,n.at)},o=r=>$(n.args[r],a),d=r=>{let i=o(r);if(typeof i!="string")throw new f(`${n.fn}(\u2026) needs a quoted name, like ${n.fn}('name')`,n.at);return i};switch(n.fn){case"out":case"in":{t(1,2);let r=(y,m)=>n.fn==="out"?s.graph.out(y,m):s.graph.in(y,m);if(n.args.length===2){let y=S(o(0),n.at,n.fn).nodes,m=d(1);return tn(y.flatMap(h=>{let x=r(h.id,m);return l(x.length+1,n.at),x}))}let i=d(0);if(!a)throw new f(`${n.fn}('${i}') needs a record to start from`,n.at);let p=r(a.id,i);return l(p.length,n.at),new g(p)}case"all":{t(1,2);let r=s.graph.nodesOfKind(d(0),{archived:n.args.length===2?o(1):!1});return l(r.length,n.at),new g(r)}case"archived":return t(0,1),nn(n.args.length===1?o(0):a);case"count":return t(1),S(o(0),n.at,"count").nodes.length;case"exists":return t(1),S(o(0),n.at,"exists").nodes.length>0;case"every":case"some":{t(2);let r=S(o(0),n.at,n.fn);l(r.nodes.length,n.at);let i=p=>R(T(p,n.args[1]),n.at,`the condition in ${n.fn}(\u2026)`);return n.fn==="every"?r.nodes.every(i):r.nodes.some(i)}case"sum":case"min":case"max":{t(2);let r=S(o(0),n.at,n.fn);l(r.nodes.length,n.at);let i=n.args[1],p=i.t==="lit"&&typeof i.value=="string"?i.value:void 0,y=i.t==="ident"?`'${i.name}'`:p!==void 0?`'${p}'`:"\u2026",m=r.nodes.map(h=>i.t==="ident"?E(h,i.name,n.at):p!==void 0?E(h,p,n.at):T(h,i)).filter(h=>{if(h===null)return!1;if(typeof h!="number")throw new f(`${n.fn}(\u2026, ${y}) needs a number for each member, and found ${w(h)}`,n.at);return!0});return n.fn==="sum"?m.reduce((h,x)=>h+x,0):m.length===0?null:n.fn==="min"?Math.min(...m):Math.max(...m)}case"fact":{t(1);let r=d(0),i=s.kinds.get(pn)?.computed?.get(r);if(!i)throw new f(`no fact is called "${r}"`,n.at);return H(null,r,i,n.at)}case"first":return t(1),S(o(0),n.at,"first").nodes[0]??null;case"sort":{t(2,3);let r=S(o(0),n.at,"sort"),i=n.args.length===3?o(2):"asc";if(i!=="asc"&&i!=="desc")throw new f("sort(\u2026) goes 'asc' or 'desc'",n.at);let p=r.nodes.length;l(p+p*Math.ceil(Math.log2(p+1)),n.at);let y=r.nodes.map((h,x)=>({node:h,i:x,key:T(h,n.args[1])})),m=i==="desc"?-1:1;return y.sort((h,x)=>Y(h.key,x.key,m,n.at)||h.i-x.i),new g(y.map(h=>h.node))}case"either":{if(n.args.length<1)throw new f("either(\u2026) takes at least one argument",n.at);for(let r=0;r<n.args.length;r++){let i=o(r);if(i!==null&&!(i instanceof g&&i.nodes.length===0))return i}return null}case"present":{t(1);let r=o(0);return r===null||r===""?!1:Array.isArray(r)?r.length>0:r instanceof g?r.nodes.length>0:!0}case"len":{t(1);let r=o(0);if(r===null)return 0;if(typeof r=="string"||Array.isArray(r))return r.length;if(r instanceof g)return r.nodes.length;throw new f(`len(\u2026) needs a word or a list, and was given ${w(r)}`,n.at)}case"contains":case"startsWith":{t(2);let r=o(0),i=o(1);if(r===null||i===null)return!1;if(n.fn==="contains"&&Array.isArray(r))return r.some(m=>M(m,i));let p=G(r,n.at,n.fn),y=G(i,n.at,n.fn);return n.fn==="contains"?p.toLowerCase().includes(y.toLowerCase()):p.startsWith(y)}case"lower":{t(1);let r=G(o(0),n.at,"lower");return r===null?null:r.toLowerCase()}case"today":return t(0),u;case"now":return t(0),b;case"date":{t(1);let r=_(o(0),n.at,"date");return r===null?null:new Date(r).toISOString().slice(0,10)}case"days":case"hours":{t(2);let r=_(o(0),n.at,n.fn),i=_(o(1),n.at,n.fn);if(r===null||i===null)return null;let p=(i-r)/(n.fn==="days"?864e5:36e5);return n.fn==="days"?Math.round(p):p}case"if":return t(3),R(o(0),n.at,"the condition in if(\u2026)")?o(1):o(2);default:throw new f(`"${n.fn}" is not a function the rule language knows`,n.at)}}function Y(n,a,t,o){if(n===null||a===null)return n===a?0:n===null?1:-1;if(Array.isArray(n)&&Array.isArray(a)){for(let r=0;r<Math.max(n.length,a.length);r++){let i=Y(n[r]??null,a[r]??null,t,o);if(i!==0)return i}return 0}let d=r=>typeof r=="number"||typeof r=="string"||typeof r=="boolean"?typeof r:w(r);if(d(n)!==d(a)||typeof n=="object"||typeof a=="object")throw new f(`sort(\u2026) cannot put ${w(n)} and ${w(a)} in order`,o);return typeof n=="string"?t*(n<a?-1:n>a?1:0):t*(Number(n)-Number(a))}return $(e,s.subject)}var Rn=["out","in","all","count","exists","every","some","sum","min","max","present","len","contains","startsWith","lower","today","now","date","days","hours","if","first","sort","either","fact","archived"];var Gn=(e,s,c,l)=>({severity:"error",code:e,path:s,message:c,...l?{fix:l}:{}}),Mn=(e,s,c,l)=>({severity:"warning",code:e,path:s,message:c,...l?{fix:l}:{}}),On=e=>e.some(s=>s.severity==="error");function En(e){return e.map(s=>`${s.severity==="error"?"\u2717":s.severity==="warning"?"!":"\xB7"} ${s.path||"(document)"}: ${s.message}${s.fix?` \u2014 ${s.fix}`:""}`).join(`
2
- `)}var jn=["money","percent","date","time","datetime","relative","upper","lower","count","words","and","plural","excerpt"],gn={getNode:()=>{},allNodes:()=>[],allEdges:()=>[],nodesOfKind:()=>[],edgesOfKind:()=>[],out:()=>[],in:()=>[],neighbors:()=>[],has:()=>!1};function Un(e,s,c,l=[],u,b=D){return q(e,s,c,l,u,b)}var yn=(e,s)=>e.capital?P(s):s,hn=new Set(["words","plural","relative"]);function Kn(e,s){let c=e[0];return!c||c.text!==void 0||!c.format||!hn.has(c.format)?s:/^[a-z][a-z'’-]*(?=\s|$|[,.;:!?])/.test(s)?P(s):s}function mn(e){return e?s=>{let c=e.tryDefinition(s.kind)?.label;return c?c(s):D(s)}:D}var an=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],sn=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];function wn(e,s){return!Number.isInteger(e)||e<0||e>99?K(e,s):e<20?an[e]:e%10===0?sn[e/10]:`${sn[Math.floor(e/10)]}-${an[e%10]}`}function $n(e){return/[^aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:/(s|x|z|ch|sh)$/i.test(e)?`${e}es`:`${e}s`}var D=e=>String(e.name??e.title??e.label??e.id);function q(e,s,c,l=[],u,b=D){if(s==="plural"){let k=e instanceof g?e.nodes.length:Array.isArray(e)?e.length:typeof e=="number"?e:null;return k===null||l[0]===void 0?"\u2014":k===1?l[0]:l[1]??$n(l[0])}if(e===null)return"\u2014";if(e instanceof g)return s==="count"?String(e.nodes.length):s==="and"?Z(e.nodes.map(b)):e.nodes.map(b).join(", ");if(Array.isArray(e)){if(s==="count")return String(e.length);let k=e.map(N=>q(N,void 0,c,[],u,b));return s==="and"?Z(k):k.join(", ")}if(typeof e=="object")return b(e);switch(s){case"words":return typeof e=="number"?wn(e,u?.locale):String(e);case"money":return typeof e=="number"?I(e,u):String(e);case"percent":return typeof e=="number"?K(e,u?.locale,{style:"percent",maximumFractionDigits:0}):String(e);case"upper":return String(e).toUpperCase();case"lower":return String(e).toLowerCase();case"excerpt":return en(String(e),Number(l[0])||void 0);case"date":return O(U(String(e),u?.timeZone)??String(e).slice(0,10),u?.locale);case"time":return typeof e=="string"&&F.test(e)?O(e,u?.locale):J(String(e),u?.locale,u?.timeZone);case"datetime":return typeof e=="string"&&F.test(e)?O(e,u?.locale):j(String(e),u?.locale,u?.timeZone);case"relative":{let k=U(String(e),u?.timeZone),N=k===void 0?Date.parse(String(e)):Date.parse(`${k}T00:00:00Z`);if(Number.isNaN(N))return String(e);let A=Math.round((N-Date.parse(`${c}T00:00:00Z`))/864e5);return A===0?"today":A===1?"tomorrow":A===-1?"yesterday":A>0?`in ${A} days`:`${-A} days ago`}default:return typeof e=="string"&&F.test(e)?O(e,u?.locale):typeof e=="string"&&B.test(e)?j(e,u?.locale,u?.timeZone):String(e)}}function Pn(e,s){let c=s.today??L(),l=s.name??mn(s.graph?.schema);return e.map(u=>{if(u.text!==void 0)return u.text;try{let b=on(u.expr,{graph:s.graph??gn,subject:s.node,kinds:s.kinds,today:c,budget:s.budget??500,...s.bindings?{bindings:s.bindings}:{}});return yn(u,q(b,u.format,c,u.formatArgs,s.money,l))}catch(b){if(b instanceof f)return"\u2014";throw b}}).join("")}export{g as a,Nn as b,pn as c,f as d,W as e,on as f,Rn as g,Gn as h,Mn as i,On as j,En as k,jn as l,gn as m,Un as n,yn as o,Kn as p,mn as q,Pn as r};
@@ -1,2 +0,0 @@
1
- import{a as Z,b as qe}from"./chunk.KHRS2SKB.js";import"./chunk.S6TN3MLY.js";import"./chunk.ZQWKS6K5.js";import"./chunk.GZBODS7Z.js";import{j as De,k as Ne,l as Oe}from"./chunk.FBRARPGR.js";import"./chunk.EZXGVTT2.js";import"./chunk.UXNZPPWR.js";import"./chunk.GYO57LKD.js";import"./chunk.HJCQ6I3S.js";import"./chunk.LCG3VLCB.js";import"./chunk.P7FN3SFB.js";import"./chunk.CANTHIRO.js";import"./chunk.BG2SC77J.js";import{a as We,b as S}from"./chunk.NAEEPUWJ.js";import{a as X,b as $e}from"./chunk.AQJD23AN.js";import"./chunk.XBNASVTY.js";import"./chunk.52Y37IAD.js";import"./chunk.MSPRCR3Q.js";import"./chunk.CSA6SWTI.js";import"./chunk.4DCPB67O.js";import{b as Pe,c as Le}from"./chunk.Y4VOCJ7R.js";import"./chunk.3FUFVVR4.js";import"./chunk.XOZU4OFA.js";import"./chunk.IYVBJDR7.js";import"./chunk.ZJXUWOG3.js";import"./chunk.TI4OSTQV.js";import"./chunk.TXEWSZGO.js";import"./chunk.VTCPA4V4.js";import"./chunk.FGJM4LJO.js";import"./chunk.K7WME4P4.js";import"./chunk.MDIAWTNK.js";import"./chunk.PEA4D66Y.js";import"./chunk.TRPPN2GD.js";import{u as Re}from"./chunk.TTFYXKLI.js";import"./chunk.OJGHDWI6.js";import"./chunk.ICYJ7QJG.js";import"./chunk.MT45H2T5.js";import{l as ze}from"./chunk.S2ATSY6P.js";import{c as Ce}from"./chunk.72Q4R7N6.js";import{j as Ie}from"./chunk.G6DISMVT.js";import"./chunk.W54NXXC5.js";import{G as ot,Ma as J,Ra as He,T as Me,Va as Ee,ba as O,h as Ae,u as Te}from"./chunk.B3T4N2XM.js";import"./chunk.SDO3U72B.js";import{Cb as be,Oc as Se,la as Q,ma as N,oc as xe,qc as ke}from"./chunk.6W2DUW5S.js";import"./chunk.SLBWPVIY.js";import{b as Y}from"./chunk.AJZBJBMO.js";var a=Y(ot(),1);var t=Y(Me(),1);function bt(u,r,o){let c=r.on??r.about[r.about.length-1];De(u,r.about,{...o,pins:Z(),...c===void 0?{}:{focus:c}})}function xt({placement:u="float",chosen:r=!0}={}){let{menuAt:o}=O();return u==="menu"&&o===null?r?(0,t.jsx)(at,{}):null:(0,t.jsx)(lt,{placement:u})}function at(){let{store:u,setMenuAt:r,view:o}=O(),{selection:c}=J(),h=(0,a.useRef)(null),[E,y]=(0,a.useState)(null);(0,a.useLayoutEffect)(()=>{let b=h.current?.offsetParent??h.current?.parentElement;if(!b)return;let m=Math.round(b.getBoundingClientRect().width);m!==E&&y(m)});let v=c.length===1&&!o.overview?u.graph.getNode(c[0]):void 0;return!v||E===null||E>=Be?(0,t.jsx)("span",{ref:h,hidden:!0}):(0,t.jsx)("button",{type:"button",ref:h,"data-testid":"chosen-acts","aria-label":`What can be done with ${S(u,v.id)}`,"aria-haspopup":"menu",onClick:b=>{let m=b.currentTarget.getBoundingClientRect();r({x:Math.round(m.right),y:Math.round(m.bottom+4),on:v.id})},style:{position:"absolute",right:"calc(14px + var(--graview-dock, 0px))",top:98,zIndex:"var(--graview-layer-overview, 10)",minHeight:30,padding:"0 12px",borderRadius:8,fontSize:"0.8125rem",background:"var(--graview-float)",boxShadow:"var(--graview-lift-low)"},children:"Acts\u2026"})}var Be=564;function lt({placement:u}){let{store:r,menuAt:o,setMenuAt:c,view:h,signIn:E}=O(),y=(0,a.useRef)(null),v=(0,a.useRef)(null),b=(0,a.useRef)(null),m=(0,a.useRef)(null);o?.returnTo&&(m.current=o.returnTo);let Ke=e=>{let i=e.closest("[data-graview-asking]")?.getAttribute("data-graview-asking"),n=e.getAttribute("data-pin-for"),d=i??e.getAttribute("data-affordance")??(n===null?null:`pin:${n}`)??e.getAttribute("data-menu-item");v.current=d===null?null:{key:d,element:e}};(0,a.useEffect)(()=>{let e=y.current,i=v.current;if(i===null||document.activeElement!==document.body||i.element.isConnected)return;let n=i.key;if(!e){v.current=null;let k=m.current;m.current=null,(k?.isConnected?k:b.current)?.focus();return}((n.startsWith("pin:")?e.querySelector(`[data-pin-for="${CSS.escape(n.slice(4))}"]`):null)??e.querySelector(`[data-affordance="${CSS.escape(n)}"]:not([disabled])`)??e).focus()});let[_e,je]=(0,a.useState)(null);(0,a.useLayoutEffect)(()=>{let e=y.current?.offsetParent??y.current?.parentElement;if(e instanceof HTMLElement&&(b.current=e),!e)return;let i=e.getBoundingClientRect();je(n=>n&&n.left===i.left&&n.top===i.top&&n.width===i.width&&n.height===i.height?n:{left:i.left,top:i.top,width:i.width,height:i.height})});let{selection:Ue,set:Ve,clear:Ge}=J(),s=o?.about??Ue,[q,Ye]=(0,a.useState)(()=>Z()),F=o?.on??s[s.length-1],B=o?.about,Qe=(0,a.useMemo)(()=>({pins:q,...F===void 0?{}:{focus:F},...B?{about:B}:{}}),[q,F,B]),Je=(0,a.useMemo)(()=>new Set(r.allMutations().filter(e=>e.pinned).map(e=>e.name)),[r]),{affordances:g,withheld:ee,observations:te}=Ne(Qe),I=ke(ee,E),f=I?st:ee,Xe=o===null?null:{face:o.face??"scene",on:o.on,about:s,field:o.field,place:o.place,href:o.href,act:o.act,element:o.returnTo},ne=Re(Xe),ie=te.some(e=>e.id.startsWith("schema:waits:")),{apply:Ze,preview:et}=Oe(),[C,z]=(0,a.useState)(null),[tt,re]=(0,a.useState)(!1),[oe,ae]=(0,a.useState)(!1),[L,R]=(0,a.useState)(""),nt=$e({letters:!0}),[le,K]=(0,a.useState)(null),_=(0,a.useRef)([]),j=(e,i)=>{try{return et(e,i),Ze(e,i),K(null),c(null),_.current=[],!0}catch(n){return K(ze(r.schema,r.allMutations(),n)),_.current=n instanceof be?n.issues.map(d=>String(d.path[0]??"")).filter(Boolean):[],!1}},$=[...new Set(s.flatMap(e=>{let i=r.graph.getNode(e);return i?[i.kind]:[]}))],x=$.length>0?$:[...new Set(s.flatMap(e=>Te(e)))],p=s.length===1?Ae(s[0]):null,U=p?{from:r.graph.getNode(p.from),to:r.graph.getNode(p.to)}:null,se=p?Le(r,p):void 0,de=se?.provisional?se:void 0,ue=p?(()=>{let e=r.schema.tryDefinition(r.graph.getNode(p.from)?.kind??"")?.edges?.[p.kind],i=r.graph.getNode(p.to);return e?.inverse&&i?`From ${S(r,i.id)}: ${e.inverse}`:null})():null;(0,a.useEffect)(()=>{z(null),re(!1),ae(!1),K(null),R("")},[s,o?.about]);let l=o!==null,it=u==="menu"&&!l,A=(0,a.useRef)(o);A.current=o;let pe=Ee("acts",{open:l&&u==="menu",onOpenChange:e=>{e||c(null)},at:()=>A.current?{x:A.current.x,y:A.current.y}:null,returnTo:()=>{let e=A.current?.returnTo;if(e?.isConnected)return e;let i=A.current?.on;return i?document.querySelector(`[data-graview-view="${CSS.escape(i)}"]`):null},align:"start"}),ce=(_e?.width??Number.POSITIVE_INFINITY)<Be;if((0,a.useLayoutEffect)(()=>{let e=y.current?.offsetParent;if(!e||!ce||l)return;let i=y.current?.getBoundingClientRect().height??0,n=`${Math.round(i)+20}px`;if(e.style.paddingBottom===n)return;let d=e.style.paddingBottom;return e.style.paddingBottom=n,()=>{e.style.paddingBottom=d}}),s.length===0&&!l)return null;let ge=o?.title!==void 0||s.length>0&&!(s.length===1&&s[0]===h.focusId),he=Math.max(1,Math.min(9,g.length)),T=[...g.filter(e=>e.provider==="invariant"&&!e.destructive),...g.filter(e=>e.pinned&&e.provider!=="invariant"&&!e.destructive),...g.filter(e=>!e.ties&&!e.destructive&&!e.pinned&&e.provider!=="invariant"),...g.filter(e=>e.ties&&!e.destructive&&!e.pinned&&e.provider!=="invariant"),...g.filter(e=>e.destructive)],me=T.length>he&&!l,fe=L.trim().toLowerCase(),w=me&&fe.length>0?T.filter(e=>`${e.label} ${e.why}`.toLowerCase().includes(fe)):null,V=w??(tt||l?T:T.slice(0,he)),ye=w?0:T.length-V.length,W=[];for(let e of V){let i=!l&&e.provider==="invariant",n=!l&&!i&&e.pinned!==void 0&&!e.destructive,d=!l&&!i&&!n&&e.ties===!0&&!e.destructive,k=i?e.why:n?"pinned":d?"its ties":null,D=i?"violation":n||d?"ties":null,H=W[W.length-1];H&&H.heading===k?H.items.push(e):W.push({heading:k,tone:D,items:[e]})}let G=g.find(e=>e.id===C),P=s.length===1?S(r,s[0]):null,ve=e=>{if(!P)return e;let i=e.startsWith(`"${P}"`)?e.slice(P.length+2):e.startsWith(P)?e.slice(P.length):null;if(i===null)return e;let n=i.trimStart();return n.length===0?e:n[0].toUpperCase()+n.slice(1)},rt=new Set(l?[]:V.filter(e=>e.provider==="invariant").map(e=>e.why)),M=te.filter(e=>!rt.has(e.text)).map(e=>({...e,text:ve(e.text)}));return it?null:(0,t.jsxs)("section",{...l?pe.pane:{},ref:e=>{y.current=e,l&&pe.pane.ref(e)},"aria-label":"Inspector","data-graview-offstage":"","data-testid":l?"context-menu":"inspector-strip",tabIndex:-1,onFocus:e=>Ke(e.target),onBlur:e=>{e.relatedTarget!==null&&(v.current=null)},onMouseDown:e=>e.stopPropagation(),style:{...l?He:{position:"absolute",zIndex:Se("rail")},boxSizing:"border-box",display:"flex",flexDirection:"column",gap:7,padding:"9px 12px",borderRadius:"var(--graview-radius, 12px)",border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)",...l?{width:300,maxHeight:"min(52cqh, 420px)",overflow:"auto"}:ce?{left:10,right:10,width:"auto",bottom:10,maxHeight:"min(42cqh, 300px)",overflow:"auto"}:{left:14,top:h.overview?"min(296px, 38cqh)":44,width:236,maxHeight:h.overview?"calc(100cqh - min(296px, 38cqh) - 20px)":"calc(68cqh - 94px)",overflow:"auto"}},children:[(0,t.jsx)("h2",{style:{...Ie,margin:0},children:"Inspector"}),(0,t.jsxs)("div",{style:{display:ge||!l?"flex":"none",alignItems:"baseline",flexWrap:"wrap",gap:"2px 8px",minWidth:0,paddingRight:l?0:24},children:[ge?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("strong",{style:{fontSize:"0.9375rem",whiteSpace:"nowrap"},children:o?.title??(s.length===1?S(r,s[0]):`${s.length} selected`)}),$.length>0||p?(0,t.jsx)("span",{style:{fontSize:"0.75rem",color:"var(--graview-ink-faint)",whiteSpace:"nowrap"},children:p?"relation":$.map(e=>N(r.schema.tryDefinition(e),e)).join(" \xB7 ")}):null,s.length===1&&!p&&o?.face!=="pages"?(0,t.jsx)("span",{style:{fontSize:"0.75rem",color:"var(--graview-ink-faint)",whiteSpace:"nowrap"},children:h.expanded.includes(s[0])?"\xB7 double-click closes":"\xB7 double-click opens"}):null]}):null,(0,t.jsx)("span",{style:{flex:"1 1 auto"}})]}),l?null:(0,t.jsx)("button",{type:"button",onClick:()=>{c(null),Ge()},"aria-label":"Clear selection",title:"Clear selection",style:{position:"absolute",top:6,right:6,flex:"0 0 auto",width:24,height:24,display:"grid",placeItems:"center",padding:0,fontSize:"0.875rem",lineHeight:1,borderRadius:7},children:"\xD7"}),p&&U?(0,t.jsxs)("div",{style:{display:"grid",gap:6},children:[ue?(0,t.jsx)("p",{"data-testid":"edge-said",style:{margin:0,fontSize:"0.8125rem",lineHeight:1.45,color:"var(--graview-ink-muted)"},children:ue}):null,de?(0,t.jsx)("p",{"data-testid":"edge-provisional",style:{margin:0,fontSize:"0.8125rem",lineHeight:1.45,color:"var(--graview-ink-muted)"},children:Pe(de)}):null,(0,t.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[["from",U.from],["to",U.to]].map(([e,i],n)=>(0,t.jsxs)(a.Fragment,{children:[n===1?(0,t.jsx)("span",{"aria-hidden":"true",style:{color:"var(--graview-ink-faint)"},children:"\u2192"}):null,i?(0,t.jsx)("button",{type:"button","data-testid":`edge-${e}`,onClick:()=>Ve([i.id]),title:`Select ${S(r,i.id)}`,style:{fontSize:"0.8125rem",padding:"3px 9px",borderRadius:6},children:S(r,i.id)}):(0,t.jsx)("span",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-faint)"},children:"gone"})]},e))})]}):null,!p&&s.length===1&&xe(r,s[0])?(0,t.jsx)("p",{"data-testid":"left-alone",style:{margin:0,fontSize:"0.8125rem",lineHeight:1.45,color:"var(--graview-ink-muted)"},children:"Left alone: nothing automated changes it."}):null,M.length>0?(0,t.jsx)("div",{"data-testid":"observations",title:M.map(e=>e.text).join(`
2
- `),style:{display:"grid",gap:3},children:M.slice(0,2).map(e=>(0,t.jsxs)("p",{style:{margin:0,fontSize:"0.8125rem",lineHeight:1.45,color:"var(--graview-ink-muted)"},children:[e.text,e===M[1]&&M.length>2?(0,t.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[" +",M.length-2]}):null]},e.id))}):null,l?ne.start.map(e=>(0,t.jsx)(Fe,{section:e,close:()=>c(null)},e.id)):null,le?(0,t.jsx)("p",{"data-testid":"refused",style:{margin:0,fontSize:"0.8125rem",lineHeight:1.45,color:"var(--graview-warn)"},children:le}):null,me?(0,t.jsx)("input",{"data-testid":"action-filter",value:L,onChange:e=>R(e.target.value),placeholder:`Filter ${T.length} actions\u2026`,"aria-label":"Filter actions",onKeyDown:e=>{if(e.key==="Escape"){e.stopPropagation(),L.length>0?R(""):e.currentTarget.blur();return}if(e.key==="Enter"&&w?.length===1){let i=w[0];if(i.destructive)return;i.open.length>0?z(i.id):j(i)&&R("")}},style:{font:"inherit",fontSize:"0.875rem",padding:"5px 9px",borderRadius:8,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)"}}):null,w!==null&&w.length===0?(0,t.jsxs)("p",{"data-testid":"no-matches",style:{margin:0,fontSize:"0.8125rem",lineHeight:1.45,color:"var(--graview-ink-muted)"},children:["Nothing offered here matches \u201C",L.trim(),"\u201D."]}):null,I&&g.length===0||g.length===0&&!ie&&s.length===0?null:g.length===0&&!ie?(0,t.jsx)("p",{"data-testid":"no-affordances",style:{margin:0,fontSize:"0.8125rem",lineHeight:1.45,color:"var(--graview-ink-muted)"},children:f.length>0?`Nothing you may do with ${p?"this relation":x.length===1?Q(N(r.schema.tryDefinition(x[0]),x[0])):"this mix of kinds"} \u2014 ${f.length} action${f.length===1?"":"s"} withheld.`:p?`Nothing can be done with this line yet \u2014 nothing this app declares makes or breaks \u201C${Ce(r.schema,r.graph.getNode(p.from)?.kind??"",p.kind,"out")}\u201D.`:`Nothing can be done with ${x.length===1?Q(N(r.schema.tryDefinition(x[0]),x[0])):"this mix of kinds"} yet \u2014 nothing this app declares acts on ${x.length===1?"it":"them"}.`}):(0,t.jsxs)("ol",{...nt,"data-testid":"affordances",style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",flexWrap:"nowrap",gap:2},children:[W.map((e,i)=>(0,t.jsxs)(a.Fragment,{children:[e.heading?(0,t.jsxs)("li",{"data-graview-heading":e.tone,style:{fontSize:"0.75rem",lineHeight:1.4,color:e.tone==="violation"?"var(--graview-warn)":"var(--graview-ink-faint)",...e.tone!=="violation"?{letterSpacing:"0.12em",textTransform:"uppercase",fontSize:"0.75rem"}:{},padding:"2px 2px 1px",marginTop:i>0?6:0},children:[e.tone==="violation"?"\u26A0 ":"",e.tone==="violation"?ve(e.heading):e.heading]}):i>0?(0,t.jsx)("li",{"aria-hidden":"true",style:{borderTop:"1px solid var(--graview-edge)",margin:"6px 0 3px"}}):null,e.items.map(n=>(0,t.jsxs)("li",{style:{display:"flex",gap:2,alignItems:"stretch"},onKeyDown:d=>{if(d.metaKey||d.ctrlKey||d.altKey)return;let k=d.currentTarget.querySelector("[data-affordance]"),D=d.currentTarget.querySelector("[data-pin-for]"),H=d.target===D,we=d.key==="ArrowRight"&&!H?D:H&&["ArrowLeft","ArrowUp","ArrowDown"].includes(d.key)?k:null;we&&(d.preventDefault(),d.stopPropagation(),we.focus())},children:[(0,t.jsxs)("button",{type:"button",[X]:"","data-affordance":n.id,"data-rank":n.rank,"data-graview-destructive":n.destructive||void 0,"aria-pressed":C===n.id,title:n.why,style:{padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left",borderWidth:1,borderStyle:"solid",borderColor:C===n.id?"var(--graview-accent)":l?"transparent":"var(--graview-edge)",background:l?"none":"var(--graview-panel)",boxShadow:"none",...n.destructive?{color:"var(--graview-warn)"}:{},...C===n.id?{color:"var(--graview-accent)"}:{}},onClick:()=>{if(n.open.length>0){z(C===n.id?null:n.id);return}j(n)},children:[n.label,n.open.length>0?(0,t.jsx)("span",{style:{color:"var(--graview-ink-faint)"},children:" \u2026"}):null,w?.length===1&&w[0]?.id===n.id&&!n.destructive?(0,t.jsx)("span",{"aria-hidden":"true",title:"Enter runs it",style:{float:"right",color:"var(--graview-ink-faint)",fontSize:"0.75rem"},children:"\u21B5"}):null]}),(0,t.jsx)("button",{type:"button","data-testid":"pin-toggle",tabIndex:-1,"data-pin-for":n.mutation,"aria-pressed":n.pinned!==void 0,"aria-label":n.pinned!==void 0?`Unpin ${n.label}`:`Pin ${n.label}`,title:n.pinned==="declared"?"Pinned by the app \u2014 unpin it for yourself":n.pinned==="user"?"Unpin":"Pin to the top",onClick:()=>Ye(qe(q,n.mutation,Je.has(n.mutation))),style:{flex:"0 0 auto",width:24,minHeight:24,display:"grid",placeItems:"center",padding:0,fontSize:"0.75rem",border:"1px solid transparent",background:"none",boxShadow:"none",borderRadius:7,color:n.pinned==="user"?"var(--graview-accent)":n.pinned==="declared"?"var(--graview-ink-muted)":"var(--graview-ink-faint)"},children:n.pinned!==void 0?"\u2605":"\u2606"})]},n.id))]},`${e.heading??"plain"}-${i}`)),ye>0?(0,t.jsx)("li",{children:(0,t.jsxs)("button",{type:"button",[X]:"",onClick:()=>re(!0),title:`Show all ${g.length} actions`,style:{padding:"4px 10px",fontSize:"0.875rem",borderRadius:8},children:["Show ",ye," more"]})}):null]}),I?(0,t.jsx)("button",{type:"button","data-testid":"sign-in",onClick:()=>{c(null),I.run()},style:{padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left"},children:I.label}):null,f.length>0?(0,t.jsxs)("ul",{"data-testid":"withheld",style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",flexWrap:"nowrap",gap:2},children:[f.slice(0,l||oe?f.length:3).map(e=>(0,t.jsxs)("li",{style:{display:"grid",gap:2},children:[(0,t.jsx)("button",{type:"button",disabled:!0,"data-affordance":e.id,"data-rank":e.rank,"data-withheld":e.refusal.wouldNeed.join(",")||"nobody",style:{padding:"4px 10px",fontSize:"0.875rem",borderRadius:8,borderStyle:"dashed",width:"100%",textAlign:"left",background:"none"},children:(0,t.jsx)("s",{children:e.label})}),(0,t.jsx)("span",{"data-testid":"withheld-why",style:{fontSize:"0.8125rem",lineHeight:1.4,color:"var(--graview-ink-muted)",padding:"0 10px"},children:e.refusal.message})]},e.id)),!l&&!oe&&f.length>3?(0,t.jsx)("li",{children:(0,t.jsxs)("button",{type:"button","data-testid":"withheld-more",onClick:()=>ae(!0),title:`Show all ${f.length} actions this seat may not take`,style:{padding:"4px 10px",fontSize:"0.875rem",borderRadius:8},children:["Show ",f.length-3," more withheld"]})}):null]}):null,l?ne.end.map(e=>(0,t.jsx)(Fe,{section:e,close:()=>c(null)},e.id)):null,G?(0,t.jsx)(We,{affordance:G,onApply:e=>{if(j(G,e))z(null);else return _.current},onCancel:()=>z(null)}):null]})}var st=[];function Fe({section:u,close:r}){return(0,t.jsxs)("div",{"data-menu-section":u.id,...u.heading?{role:"group","aria-label":u.heading}:{},style:{display:"grid",gap:2,borderTop:"1px solid var(--graview-edge)",paddingTop:5},children:[u.heading?(0,t.jsx)("p",{"aria-hidden":"true",style:{margin:0,padding:"2px 2px 1px",fontSize:"0.75rem",lineHeight:1.4,letterSpacing:"0.12em",textTransform:"uppercase",color:"var(--graview-ink-faint)"},children:u.heading}):null,u.items&&u.items.length>0?(0,t.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:2},children:u.items.map(o=>(0,t.jsx)("li",{children:(0,t.jsxs)("button",{type:"button","data-menu-item":o.id,onClick:()=>{r(),o.run()},style:{padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left",borderWidth:1,borderStyle:"solid",borderColor:"transparent",background:"none",boxShadow:"none"},children:[o.label,o.hint?(0,t.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[" \xB7 ",o.hint]}):null]})},o.id))}):null,u.render?.(r)]})}export{xt as InspectorPane,bt as prepareActs};
@@ -1 +0,0 @@
1
- import{b as on,c as an,d as re,e as sn,f as oe,h as Oe,i as dn,n as cn,r as ie}from"./chunk.TRPPN2GD.js";import{Ab as U,B as ue,C as te,Ca as Be,Db as Qe,Ea as _e,F as ke,Fc as tn,Gc as rn,H as Ce,Hb as Xe,I as Ze,Ia as we,Ja as ve,Mb as en,Pa as He,Sa as Ue,b as De,ba as Ke,bb as We,c as Te,d as $e,db as Je,e as K,fa as Ve,g as ce,h as M,i as Pe,ib as xe,j as Ge,jb as Ye,k as le,l as Me,la as Ie,m as Le,o as Fe,p as fe,q as he,uc as nn,v as Ne,wa as be,x as ne,z as pe,za as qe}from"./chunk.6W2DUW5S.js";function ln(e){if(typeof e=="string")return{form:"string",light:e};if(typeof e!="object"||e===null)return;let s=e,n=b=>typeof s[b]=="string"?s[b]:void 0,t=n("light")??n("src");if(t===void 0)return;let[o,m,u]=[n("dark"),n("alt"),n("darkFallback")];return{form:n("light")!==void 0?"light":"src",light:t,...o!==void 0?{dark:o}:{},...m!==void 0?{alt:m}:{},...u!==void 0?{darkFallback:u}:{}}}function Gn(e,s){let n=e.brand??{},t=n.accent?rn(n.accent):void 0;t&&!t.ok&&s.push(dn("brand","brand.accent",`that accent cannot make a readable brand, so the app keeps Graview's colors: ${t.why}`,"pick a color further from orange-red, or a darker one"));let o=ln(n.logo),m=n.name??e.name,u=n.typography?Object.fromEntries(Object.entries(n.typography).filter(([,b])=>typeof b=="string"&&!/url\(|@import|[;{}<>\\]/i.test(b)).map(([b,L])=>[b,tn(L)])):void 0;return{name:m,schemes:t?.ok?t.schemes:nn,...n.currency?{currency:n.currency}:{},...n.locale?{locale:n.locale}:{},...n.timeZone?{timeZone:n.timeZone}:{},...o?{logo:o.dark||o.darkFallback==="invert"?{light:o.light,...o.dark?{dark:o.dark}:{darkFallback:"invert"}}:o.light,logoAlt:o.alt??m}:{},...n.favicon?{favicon:n.favicon}:{},...e.description?{subtitle:e.description}:{},...n.subtitle===!1?{subtitleDrawn:!1}:{},...u?{typography:u}:{},...n.shape?{shape:n.shape}:{},...n.accents?{accents:n.accents}:{},...n.scheme?{scheme:n.scheme}:{}}}function fn(e){let{currency:s,locale:n,timeZone:t}=e.brand??{};return{...s?{currency:s}:{},...n?{locale:n}:{},...t?{timeZone:t}:{}}}var wn=Symbol.for("@graview/core:typed-field"),pn=(e,s)=>(/^(phone|place|duration)$/.test(s)&&(te(e)[wn]=s),e),un=/^(?=(?:\D*\d){3})\+?[\d ()./-]+(?: *(?:ext\.?|x|#) *\d+)?$/i;function mn(e){let s=M().check(K(300),pe(t=>Be(t,e)!==void 0,`a record of ${e.kinds.join(" or ")} in ${e.address}, as "<kind>:<id>"`)),n=e.cardinality==="one"?s:fe(s).check(K(200));return _e(e.description?n.check(ue(e.description)):n,e)}var xn=new WeakMap;function gn(e,s){xn.set(e,s)}var On=[{where:"settings[]",was:"honoured",now:"honored",since:"0.1.16"},{where:"pages",was:"overview",now:"scene",since:"0.1.17"}],V=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function yn(e,s=On){if(!V(e))return{document:e,respelled:[]};let n=[],t=e;for(let o of s)t=Re(t,o.where.split("."),o,"",n);return{document:t,respelled:n}}function Re(e,s,n,t,o){if(s.length===0){if(!V(e)||!Object.hasOwn(e,n.was))return e;o.push(`${t}${n.was}`);let{[n.was]:T,...N}=e;return Object.hasOwn(e,n.now)?N:{...N,[n.now]:T}}if(!V(e))return e;let[m,...u]=s,b=m.endsWith("[]"),L=b?m.slice(0,-2):m,F=e[L],B=F;if(!b)B=Re(F,u,n,`${t}${L}.`,o);else if(Array.isArray(F)){let T=F.map((N,W)=>Re(N,u,n,`${t}${L}.${W}.`,o));B=T.some((N,W)=>N!==F[W])?T:F}return B===F?e:{...e,[L]:B}}var hn="graview-compiled@1";function Rn(e,s){return e.find(([n,t])=>n!==q&&"ref"in t&&(t.ref==="*"||t.ref.includes(s)))?.[0]}var q="id",me=e=>typeof e=="string"&&/^\$[A-Za-z][A-Za-z0-9]*$/.test(e)?e.slice(1):void 0;function kn(e){let s=Object.entries(e.fields),n=t=>["name","title","label"].find(o=>t.some(([m])=>m===o))??t[0]?.[0];return n(s.filter(([,t])=>t.required&&(t.type==="string"||t.type==="text")))??n(s.filter(([,t])=>t.type==="string"))}function bn(e,s,n){let t;switch(e.type){case"string":case"place":t=M().check(K(500));break;case"phone":t=M().check(K(40),ce(un,"a phone number"));break;case"text":t=M().check(K(2e4)),e.format&&(te(t)[Symbol.for("@graview/core:markdown")]=1);break;case"number":case"integer":case"duration":{let m=e.min??(e.type==="duration"?0:void 0),u=[...e.type==="number"?[]:[Me()],...m===void 0?[]:[Te(m)],...e.max===void 0?[]:[De(e.max)],...e.step===void 0?[]:[$e(e.step)]];t=u.length>0?le().check(...u):le();break}case"boolean":t=Le();break;case"date":t=M().check(ce(ke,"a date like 2026-10-02"));break;case"datetime":t=M().check(pe(Ce,"a date and time like 2026-10-02T14:30:00Z"));break;case"enum":t=Ne(e.options);break;case"list":t=fe(e.of==="number"?le():e.of==="date"?M().check(ce(ke)):e.of==="image"||e.of==="video"||e.of==="file"?be(e.of):M().check(K(500))).check(K(200));break;case"image":case"video":case"file":t=be(e.type);break;case"app-link":t=qe();break;case"url":t=Ge();break;case"email":t=Pe();break}let o=e.type==="number"||e.type==="integer";return pn(t,o&&e.format==="duration"?"duration":e.type),e.collaborative!==void 0&&(e.type==="text"||e.type==="string")&&(te(t)[Symbol.for("@graview/core:collaborative")]=e.collaborative?1:0),e.description&&(t=t.check(ue(e.description))),o&&(e.format==="money"||e.format==="percent"||!e.format&&e.unit)&&Xe(t,{...n,...e.format?{format:e.format}:{},...e.unit?{unit:e.unit}:{}}),s?ne(t):t}var ae=e=>{throw new U(`there is no record "${e}"`,"invalid")},zn=(e,s)=>"field"in e?bn(e.field,e.optional,s):"ref"in e?en(e.ref):ne(Fe()),An=new WeakMap;var ze=(e,s)=>V(s)&&Object.keys(e??{}).length===Object.keys(s).length&&Object.keys(e??{}).every(n=>Object.hasOwn(s,n));function it(e,s={}){let n=V(e)?e.format:void 0;if(n!==hn)return{ok:!1,findings:[Oe("compiled-format","format",n===void 0?"this is not a compiled Graview app":`this compiled app is ${JSON.stringify(n)}, and this build reads ${hn}`,"compile the document instead")]};let t=e,o=yn(t.document).document,m=o===t.document?t:{...t,document:o},u=V(o)&&typeof o.name=="string"&&V(o.kinds)&&ze(o.kinds,m.kinds)&&ze(o.acts,m.acts)&&ze(o.rules,m.rules)&&Array.isArray(m.edges)&&Array.isArray(m.findings),b={ok:!1,findings:[Oe("compiled-shape","","this compiled app's parts do not match its document","compile the document instead")]};if(!u)return b;try{return Sn(m,s)}catch{return b}}function Sn(e,s={}){let{document:n}=e,t=n.brand?.timeZone,o=s.today??(()=>Ze(t)),m=new Map(e.edges.map(([h,r])=>[h,r])),u=new Map;for(let[h,r]of Object.entries(n.kinds)){let z=e.kinds[h]?.computed,R=ve(r.edges);u.set(h,{fields:new Set([...Object.keys(r.fields),...R.keys()]),edges:new Map(Object.entries(we(r.edges)).map(([j,$])=>[j,$.cardinality??"many"])),...z?{computed:new Map(z)}:{},...R.size>0?{linked:R}:{}})}e.facts&&u.set(an,{computed:new Map(e.facts)});let b=fn(n),L=new Map,F=Object.entries(n.kinds).map(([h,r])=>{let z={};for(let[i,g]of Object.entries(r.fields))z[i]=bn(g,!g.required,b),g.repeats&&(z[He(i)]=ne(Ue()));for(let[i,g]of ve(r.edges))z[i]=ne(mn(g));let{label:R,describe:j,durations:$}=e.kinds[h]??{},P=Object.entries(r.computed??{}).map(([i,g])=>[i,typeof g=="string"?{expr:g}:g]),J=Object.hasOwn(r.fields,"label")&&!r.fields.label.label&&!/\{\s*label\b/.test(r.label??`{${kn(r)??""}}`),_=Object.fromEntries([...J?[["label","Label"]]:[],...Object.entries(r.fields).filter(([,i])=>i.label).map(([i,g])=>[i,g.label]),...P.filter(([,i])=>i.label).map(([i,g])=>[i,g.label])]),A=Object.keys(_).length>0,l=Object.fromEntries(Object.entries(r.fields).filter(([,i])=>i.default!==void 0).map(([i,g])=>[i,g.default]));L.set(h,l);let D=Object.fromEntries(Object.entries(we(r.edges)).map(([i,{renamedFrom:g,...I}])=>[i,I])),S=i=>r[i]?{[i]:r[i]}:{};return Ke(h,{fields:he(z),edges:D,...S("plural"),...S("noun"),...S("description"),...R?{label:i=>ie(R,{node:i,kinds:u,today:o(),money:b})||i.id}:{},...j?{describe:i=>ie(j,{node:i,kinds:u,today:o(),money:b})}:{},...S("lifecycle"),...S("figure"),...S("fieldRoles"),...S("people"),archives:r.archives,...r.tidying?{tidying:r.tidying}:{},...P.length>0?{computed:Object.fromEntries(P.map(([i,g])=>[i,$?.includes(i)?{...g,as:"duration"}:r.computed[i]]))}:{},...A||r.glance||r.page?{display:{...A?{labels:_}:{},...r.glance?{glance:[...r.glance]}:{},...r.page?{page:r.page}:{}}}:{},...Object.keys(l).length>0?{defaults:l}:{}})}),B=We(F,n.computed);function T(h){return B.tryDefinition(h.kind)?.label?.(h)??h.id}let N=h=>({id:"",kind:h,...L.get(h)}),W=[];for(let[h,r]of Object.entries(n.acts??{})){let z=e.acts[h],{title:R,effects:j,guard:$,refusal:P,destructive:J,idempotent:_,creates:A,connects:l,severs:D,writes:S,writesOther:i,sets:g}=z,I=new Map(z.args),se={};for(let[d,x]of I)se[d]=zn(x,b);let w=[r.on??[]].flat(),C=new Map(z.exprs),G=j.find(d=>"create"in d),Y=(d,x,f,v=null)=>{if(V(d)&&"expr"in d)return oe(C.get(d.expr),{graph:f,subject:v,kinds:u,bindings:x,today:o()});let k=me(d);return k===void 0?typeof d=="string"&&d.startsWith("$$")?d.slice(1):d:k==="now"?new Date().toISOString():k==="today"?o():x[k]},Ee=(d,x)=>{if(!G)return"";let f=n.kinds[G.create].fields,v=N(G.create),k=[];for(let[O,ee]of Object.entries(G.set??{})){try{v[O]=Y(ee,d,x)??v[O]}catch{}let Q=me(ee);Q&&d[Q]!==void 0&&k.push(O)}let Z=T(v).trim(),H=k.filter(O=>v[O]!==!1&&f[O].type!=="text"&&!(/[^]{41}/.test(v[O])||/ .*[.!?]$/.test(v[O])&&!/[ .][A-Z]\w{0,3}\.$/.test(v[O]))&&T({...v,[O]:void 0}).trim()===Z).map(O=>v[O]===!0?f[O].label??Ve(O):cn(v[O],f[O].format,o(),[],b));return Z&&H.length>0?`${Z} (${H.join(", ")})`:Z};W.push(Qe(h,{input:he(se),title:R,...r.description?{description:r.description}:{},...r.fromTheOtherEnd?{fromTheOtherEnd:r.fromTheOtherEnd}:{},...I.has(q)?{subject:{kinds:w.length>0?w:"*",arg:q}}:{},...J?{destructive:!0}:{},..._?{idempotent:!0}:{},...A.length>0?{creates:A}:{},...l.length>0?{connects:l}:{},...D.length>0?{severs:D}:{},writes:S,...Object.keys(i).length>0?{writesOther:i}:{},...Object.keys(g).length>0?{sets:g}:{},describe:(d,x)=>{let f=typeof d[q]=="string"?x.getNode(d[q]):void 0,v=f?T(f):Ee(d,x);return v?`${R}: ${v}`:R},apply(d,x){let f=d.graph,v=typeof x[q]=="string"?x[q]:void 0,k=v?f.getNode(v):void 0;if(v&&!k&&ae(v),k&&w.length>0&&!w.includes(k.kind))throw new U(`"${R}" acts on ${w.join(" or ")}, not on ${Ie(k.kind)}`,"invalid");let Z={};for(let[a,c]of Object.entries(x))c!==void 0&&(Z[a]=c);if($&&k){let a;try{a=oe($,{graph:f,subject:k,kinds:u,bindings:Z,today:o()})}catch(c){throw c instanceof re?new U(`"${R}" could not be judged: ${c.sentence}`):c}if(a!==!0)throw new U(P?ie(P,{node:k,kinds:u,graph:f,bindings:Z,today:o(),money:b}):`"${R}" is not allowed for ${T(k)} right now`)}let H=new Map,O=a=>f.has(a)||[...H.values()].includes(a),ee=new Set,Q=a=>{let c=Je(a);ee.has(c)||(ee.add(c),d.removeEdge(a))},X=(a,c)=>{let p=me(a);if(p==="subject")return v;if(p==="me"){let y=d.me;if(y&&n.kinds[f.getNode(y)?.kind]?.people)return y;throw new U(`"${R}" is done as you, and you have no record here`)}if(H.has(p))return H.get(p);try{return Y(a,Z,f,c??k??null)}catch(y){throw y instanceof re?new U(`"${R}" could not work out a value: ${y.sentence}`):y}};for(let a of j)if("create"in a){let c=n.kinds[a.create],p=N(a.create);for(let[ye,de]of Object.entries(a.set??{})){let je=X(de,void 0);je!==void 0&&(p[ye]=je)}let y=kn(c),E=d.freshId(String((y&&p[y])??a.create),a.create);d.addNode({...p,id:E}),a.as&&H.set(a.as,E)}else if("connect"in a||"sever"in a){let c="connect"in a?a.connect:a.sever,p=String(X(a.from,void 0)??""),y=String(X(a.to,void 0)??"");if(O(p)||ae(p),O(y)||ae(y),"connect"in a){if(m.get(c)?.cardinality==="one")for(let E of f.out(p,c))E.id!==y&&Q({kind:c,from:p,to:E.id});f.out(p,c).some(E=>E.id===y)||d.addEdge({kind:c,from:p,to:y})}else Q({kind:c,from:p,to:y})}else if("set"in a){let c=String(X(a.target??"$subject",void 0)??""),p=f.getNode(c);!p&&!O(c)&&ae(c);let y={};for(let[E,ye]of Object.entries(a.set)){let de=X(ye,p);de!==void 0&&(y[E]=de)}Object.keys(y).length>0&&d.patchNode(c,y)}else if("remove"in a){let c=String(X(a.remove,void 0)??"");f.has(c)||ae(c),d.removeNode(c)}else if("replace"in a&&k){let c=x.to;for(let p of a.replace){let y=m.get(p)?.from.includes(k.kind)??!0;for(let E of y?f.out(k.id,p):f.in(k.id,p))p===a.keep&&E.id===c||Q(y?{kind:p,from:k.id,to:E.id}:{kind:p,from:E.id,to:k.id})}}}}))}let Ae=[];for(let[h,r]of Object.entries(n.rules??{})){let{title:z,require:R,when:j,says:$}=e.rules[h],P=r.repairs??[],J=(A,l,D=o(),S)=>{let i=[],g={graph:A,subject:l,kinds:u,today:D,...S?{linked:S}:{},onUnread:w=>i.push(w)},I;try{if(j&&oe(j,g)!==!0)return[];if(I=oe(R,g)===!0,!I&&i.length>0)throw new re(`it reads ${on(i[0])}`,0)}catch(w){throw w instanceof sn?new Ye(w.sentence):w instanceof re?new Error(w.sentence):w}if(I)return[];let se=P.flatMap(w=>{let C=n.acts?.[w.act],G={},Y=l&&C?.on&&C.fromTheOtherEnd&&![C.on].flat().includes(l.kind)?Rn(e.acts[w.act].args,l.kind):void 0;Y?G[Y]=l.id:l&&(C?.on||/^(edit|remove|archive|unarchive|merge|skip|detach|split)-/.test(w.act))&&(G[q]=l.id);for(let[x,f]of Object.entries(w.args??{}))G[x]=me(f)==="subject"?l?.id:f;let d=(C?e.acts[w.act].args:[]).filter(([x,f])=>f.required&&G[x]===void 0).map(([x])=>x);return[{mutation:w.act,label:w.label??(Y?C.fromTheOtherEnd:C?.title)??w.act.replace(/-/g," "),args:G,...d.length>0?{missing:d}:{}}]});return[{invariant:h,...l?{subjectId:l.id}:{},label:z,message:$?ie($,{node:l,kinds:u,graph:A,today:D,money:b}):l?`${T(l)}: ${z}`:z,nodeIds:l?[l.id]:[],repairs:se}]},_={label:z,shape:{over:r.over,require:R,when:j,says:$,declared:n.kinds,money:b,kinds:u,today:o},judgment:{require:r.require,...r.when?{when:r.when}:{},...r.says?{says:r.says}:{}},...r.description?{description:r.description}:{},...P.length>0?{repairs:P.map(A=>A.act)}:{}};Ae.push(r.over==="graph"?xe(h,{scope:"graph",..._,evaluate:({graph:A,today:l,context:D})=>J(A,null,l,D?.linked)}):xe(h,{scope:{kind:r.over},..._,evaluate:({graph:A,subject:l,today:D,context:S})=>J(A,l,D,S?.linked)}))}let Se=n.policy&&{...n.policy,...n.roles?{roles:n.roles}:{}},ge={name:n.name,schema:B,mutations:W,invariants:Ae,...Se?{policy:Se}:{},...e.brand?{brand:e.brand}:{},...n.modules?{modules:n.modules}:{},...n.lenses?{lenses:n.lenses}:{},...n.pages?{pages:n.pages}:{},...n.settings?{settings:n.settings}:{},...n.connections?{connections:n.connections}:{},...n.forms?{forms:n.forms}:{},...n.publishing?{publishing:n.publishing}:{},...e.viewSpecs?{viewSpecs:e.viewSpecs}:{},...e.home?{home:e.home}:{},version:n.version??1};return gn(ge,n),An.set(ge,e),{ok:!0,app:ge,document:n,findings:e.findings,sights:n.policy?.sees,kinds:u}}export{yn as a,Gn as b,hn as c,q as d,me as e,kn as f,it as g,Sn as h};
@@ -1 +0,0 @@
1
- import{a as N}from"./chunk.TI4OSTQV.js";import{h as E}from"./chunk.SLBWPVIY.js";var S=globalThis[Symbol.for("@graview/core:publishing")]??={},T=()=>S.kit,P="publish",x=e=>e?.mode==="on-publish",Q=Symbol.for("@graview/core:seat"),G=(e,n)=>{let s=Reflect.get(e,n,e);return typeof s=="function"?s.bind(e):s},X,Y=()=>X??={name:P,title:"Publish",description:"Publish what collaborators have changed, so readers see it.",input:S.input(),apply(){}};var I=new WeakMap;function z(e){let n=e.all(),s=n.at(-1)?.id,o=I.get(e);if(o&&o.length===n.length&&o.last===s)return o.seq;let a,r;for(let t=n.length-1;t>=0;t--){let i=n[t];if(!(i.publishedThrough===void 0||(r??=e.undoneIds()).has(i.id))){a=i.publishedThrough;break}}return I.set(e,{length:n.length,last:s,seq:a}),a}function ee(e,n){if(!x(e))return{mutation:P,message:"this app is live: every edit reaches its readers as it is made, so there is nothing to publish.",wouldNeed:[]};let s=e.publishers??e.working;if(T().reads({mode:"on-publish",working:s},n))return{mutation:P,message:`only ${s.join(", ")||"nobody"} may publish.`,wouldNeed:[...s]}}var ne=(e,n,s,o,a,r)=>{let{log:t}=e,i=t.length,d=s.args.through;if(d!==void 0&&(!Number.isInteger(d)||d<t.horizon||d>i))throw new RangeError(`Cannot publish through seq ${String(d)}: this store holds seqs ${t.horizon} to ${i}.`);let f=d??i+1,p=z(t)??t.horizon,c=t.batches().filter(b=>!b.undone&&b.ops.some(m=>m.seq>=p&&m.seq<f&&m.publishedThrough===void 0)).length,g={id:n.id,seq:i,batch:o,author:a,intent:f<p?"Take back what was published":`Publish ${c===1?"1 change":`${c} changes`}`,...r.intent!==void 0?{batchIntent:r.intent}:{},mutation:s,primitives:[],reads:[],writes:[],at:n.at,...r.via!==void 0?{via:r.via}:{},publishedThrough:f};return t.append(g),g},te=new Set(["graph","log","snapshot","batches","violations","findings","canUndo","servedSeq","checkpoint"]);function se(e,n){let{seatView:s,viewsOf:o,viewKey:a,diff:r}=T(),t=o(e),i=a(n,"published"),d=t.get(i);if(d)return d;let f=s(e,n),p,c=()=>{let h=Math.max(e.publishedSeq??e.log.horizon,e.log.horizon);if(h>=e.log.length)return f;let u=e.log.all()[h-1-e.log.horizon]?.id;return(p?.seq!==h||p.id!==u)&&(p={seq:h,id:u,view:s(O(e,h),n)}),p.view},g=h=>h.servedSeq,b=h=>{let u=g(c()),v=c().graph.snapshot();return e.subscribe(()=>{let y=c(),k=g(y);if(k===u)return;let q=y.graph.snapshot(),M=k>u?y.log.all().filter(w=>w.seq>=u):[],l=r(v,q);[u,v]=[k,q],h(l,M)})},m=new Proxy(f,{get(h,u){switch(u){case Q:return{store:e,principal:n};case"subscribe":return b;case"seenBy":return(v,y)=>e.seenBy(v,y);case"seenFor":return n;default:return te.has(u)?G(c(),u):G(h,u)}}});return t.set(i,m),m}S.served=se;S.act=(e,n)=>x(e.publishing)&&!e.past&&!n.has(P)?Y():void 0;S.verdict=(e,n)=>{let s=ee(e.publishing,n);return s?{ok:!1,refusal:s}:{ok:!0}};S.seq=e=>x(e.publishing)?z(e.log):void 0;S.op=ne;function K(e,n){let s;for(let o of[...e??[]].sort((a,r)=>a.seq-r.seq)){if(o.seq>n)break;o.declaration&&(s=o.declaration)}return s}var R=new WeakMap;function oe(e,n){let s=K(e?.declarations,n),o=e?.declarationAt,a=[...e?.declarations??[]].filter(i=>i.seq<=n).sort((i,d)=>i.seq-d.seq).at(-1);if(!o||!a||a.declaration)return{declaration:s};let r=R.get(o);r||R.set(o,r=new Map);let t=r.get(a.seq);if(!t){let i={settled:!0,declaration:void 0,waiting:Promise.resolve()};try{let d=o(a.seq);d instanceof Promise?(i.settled=!1,i.waiting=d.then(f=>void Object.assign(i,{settled:!0,declaration:f}),()=>void(i.settled=!0))):i.declaration=d}catch{}r.set(a.seq,t=i)}return t.settled?{declaration:t.declaration??s}:{waiting:t.waiting}}var V=e=>e,$=new WeakMap,B=new WeakMap;function j(e,n){let s=typeof n=="string"?Date.parse(n):n.getTime();if(Number.isNaN(s))throw new RangeError(`\u201C${String(n)}\u201D is not a time`);let a=e.log.all().findIndex(r=>Date.parse(r.at)>s);return a===-1?e.log.length:e.log.horizon+a}function O(e,n,s={}){let o=N(e);if(o){let l=typeof n=="number"?n:j(e,n);if(l>e.servedSeq)throw new RangeError(`No moment at seq ${l}: this seat is served through seq ${e.servedSeq}`);return O(o.store,l,s).seenBy(o.principal)}let a=e.log,r=a.horizon,t=typeof n=="number"?n:j(e,n);if(!Number.isInteger(t)||t<r||t>a.length)throw new RangeError(`No moment at seq ${t}: this store holds seqs ${r} to ${a.length}${r>0?"; what is before its horizon is in the archive":""}`);let i=a.all(),d=s.declaration,f=d?.schema??e.schema,p=a.epochs().filter(l=>l.seq<=t),c=p.at(-1),g=c?.seq??r,b=l=>l>r?i[l-1-r]?.id:void 0,m=($.get(e)??[]).filter(l=>l.seq<=a.length&&b(l.seq)===l.id);$.set(e,m);let h=[...m].reverse().find(l=>l.seq>=g&&l.seq<=t),u=h?.seq??g,v=h?.base??c?.base??ae(e),y=U(e,f,v),k=e.pastEvery,q=(l,w)=>{m.some(D=>D.seq===l)||(m.push({seq:l,id:w,base:y.snapshot()}),m.sort((D,J)=>D.seq-J.seq))};for(let l=u;l<t;l++){let w=i[l-r];try{_(y,w)}catch{}(l+1)%k===0&&l+1<t&&q(l+1,w.id)}t-u>=k&&q(t,b(t));let M=i[t-1-r]?.at??c?.at;return L(e,d,{graph:y,log:i.slice(0,t-r),epochs:p,...r>0&&!p.some(l=>l.horizon)?{horizon:r}:{},seq:t,at:M,from:u})}var A=(e,n)=>n===void 0?{}:{[e]:n};function L(e,n,s){let o=V(e),a=e.constructor;return new a({schema:n?.schema??e.schema,invariants:n?.invariants??o.invariants,invariantOptions:o.invariantOptions,...A("policy",n?n.policy:e.policy),...A("modules",n?.modules??o.declaredModules),...A("enabledModules",o.startingModules),...A("timeZone",e.timeZone),intelligence:e.intelligence,principal:o.by,log:[...s.log],epochs:[...s.epochs],...A("horizon",s.horizon),snapshot:s.graph.snapshot(),validate:!1,now:o.now,past:{seq:s.seq,...A("at",s.at),foldedFrom:s.from,folded:s.seq-s.from}})}function U(e,n,s){let o=e.graph.constructor;try{return o.from(n,s,{validate:V(e).validate})}catch{return o.from(n,s,{validate:!1})}}var W=256,C=new WeakMap;function F(e){let n=C.get(e);return n||C.set(e,n={ops:new Map,epochs:new Map,chunks:new Map,marks:new Map}),n}function H(e,n){let s=-1,o;for(let[i,d]of e.epochs)i<=n&&i>s&&([s,o]=[i,d.base]);for(let[i,d]of e.marks)i<=n&&i>s&&([s,o]=[i,d]);let a=-1;for(let i=n-1;i>=Math.max(s,0);i--)if(!e.ops.has(i)){a=i;break}if(a<0&&o)return{from:s,base:o};let r=a<0?0:a-a%W,t=e.chunks.get(r);return!t||t.settled&&!t.refused&&a>=t.to?{ask:r}:t.settled?t.refused?{refused:t.refused}:a<0?{from:0,base:{nodes:[],edges:[]}}:{refused:`The archive is missing a change this moment needs (seq ${a})`}:{waiting:t.waiting}}function re(e,n,s,o){let a=Math.min(s+W,o),r={to:a,settled:!1,waiting:Promise.resolve()};r.waiting=Promise.resolve().then(()=>n(s,a)).then(t=>{let i=Array.isArray(t)?{ops:t}:t;if(!Array.isArray(i?.ops))throw new Error("its answer held no ops");for(let d of i.ops)Number.isInteger(d?.seq)&&d.seq<o&&!e.ops.has(d.seq)&&e.ops.set(d.seq,d);for(let d of i.epochs??[])Number.isInteger(d?.seq)&&d.seq<o&&d.base&&e.epochs.set(d.seq,d)}).then(()=>void(r.settled=!0),t=>void Object.assign(r,{settled:!0,refused:`Could not read the older changes from the archive: ${t instanceof Error?t.message:String(t)}`})),e.chunks.set(s,r)}function pe(e,n,s){let o=s?.archived,a=e.log.horizon;if(!o||n>=a)return;let r=F(o),t=H(r,n);return"ask"in t&&(re(r,o,t.ask,a),t=H(r,n)),"base"in t||"ask"in t?void 0:{seq:n,...t}}function Z(e,n,s,o){let a=N(e);if(a)return Z(a.store,n,s,o).seenBy(a.principal);if(!Number.isInteger(n)||n<0)throw new RangeError(`No moment at seq ${n}`);let r=F(s),t=H(r,n);if(!("base"in t))throw new RangeError("refused"in t?t.refused:`The changes before seq ${n} are still being read from the archive`);let i=U(e,o?.schema??e.schema,t.base),d=[],f=e.pastEvery;for(let c=t.from;c<n;c++){let g=r.ops.get(c);d.push(g);try{_(i,g)}catch{}(c+1)%f===0&&c+1<n&&!r.marks.has(c+1)&&r.marks.set(c+1,i.snapshot())}n-t.from>=f&&r.marks.set(n,i.snapshot());let p=r.epochs.get(t.from);return L(e,o,{graph:i,log:d,epochs:p?[p]:[],...t.from>0?{horizon:t.from}:{},seq:n,at:d.at(-1)?.at??p?.at,from:t.from})}function ae(e){let n=e.log.all(),s=e.log.horizon,o=n[0]?.id,a=B.get(e);if(a&&a.firstId===o)return a.base;let r=e.log.epochs().find(d=>d.seq>s),t=e.graph.constructor.from(e.schema,r?.base??e.graph.snapshot(),{validate:!1});for(let d=(r?.seq??e.log.length)-1;d>=s;d--)try{t.applyPrimitives(E(n[d-s]),{restoring:!0})}catch{}let i=t.snapshot();return B.set(e,{firstId:o,base:i}),i}function he(e,n,s={}){let o=typeof n=="number"?n:j(e,n),a=oe(s,o),r="declaration"in a?a.declaration:K(s.declarations,o);return s.archived&&o<e.log.horizon?Z(e,o,s.archived,r):O(e,o,{declaration:r})}function _(e,n){if(n.undoes!==void 0){e.applyPrimitives(n.primitives,{restoring:!0});return}try{e.applyPrimitives(n.primitives)}catch{e.applyPrimitives(n.primitives,{restoring:!0})}}export{K as a,oe as b,j as c,O as d,pe as e,he as f};
@@ -1 +0,0 @@
1
- var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{q as He}from"./chunk.GYO57LKD.js";import{d as Je,e as Ee,f as ze,g as je}from"./chunk.BG2SC77J.js";import{a as Ie}from"./chunk.4DCPB67O.js";import{e as X}from"./chunk.IYVBJDR7.js";import{a as j}from"./chunk.TXEWSZGO.js";import{f as De,g as Y,i as Pe}from"./chunk.S2ATSY6P.js";import{a as Se}from"./chunk.72Q4R7N6.js";import{$a as ke,Ba as K,Bb as ve,Da as he,Eb as Ae,Fa as ye,Fb as Oe,Ga as Z,Ib as Re,K as pe,Lb as Te,Na as ge,Oa as be,Ob as C,Ra as we,Wb as _e,Ya as W,a as fe,cd as $e,ea as G,kc as xe,lc as Me,mc as Ne,ya as me}from"./chunk.6W2DUW5S.js";var E=(t,e,n)=>{(t[e]===void 0||n>t[e])&&(t[e]=n)},z=(t,e,n)=>{(t[e]===void 0||n<t[e])&&(t[e]=n)},Q=(t,e)=>{t.format=e,e.includes("int")&&(t.isInt=!0)},Le=(t,e)=>{t.mime=t.mime?t.mime.filter(n=>e.includes(n)):[...e]},qe=(t,e)=>{t.multipleOf??=[],t.multipleOf.includes(e)||t.multipleOf.push(e)},Fe=(t,e)=>(t.patterns??=new Set).add(e),sn={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function I(t){let e={},{def:n,bag:r}=t._zod,i=t._zod.traits.has("$ZodCheck")?[t,...n.checks??[]]:n.checks??[];for(let o of i){let a=o._zod.def;switch(a.check){case"greater_than":E(e,a.inclusive?"minimum":"exclusiveMinimum",a.value);break;case"less_than":z(e,a.inclusive?"maximum":"exclusiveMaximum",a.value);break;case"multiple_of":qe(e,a.value);break;case"number_format":{Q(e,a.format);let d=sn[a.format];d&&(E(e,"minimum",d[0]),z(e,"maximum",d[1]));break}case"bigint_format":Q(e,a.format);break;case"min_length":case"min_size":E(e,"minimum",a.minimum);break;case"max_length":case"max_size":z(e,"maximum",a.maximum);break;case"length_equals":E(e,"minimum",a.length),z(e,"maximum",a.length);break;case"size_equals":E(e,"minimum",a.size),z(e,"maximum",a.size);break;case"string_format":Q(e,a.format),a.pattern&&Fe(e,a.pattern),(a.format==="base64"||a.format==="base64url")&&(e.contentEncoding=a.format),(a.local||a.precision===-1)&&(e.laxFormat=!0);break;case"mime_type":Le(e,a.mime);break}}r.minimum!==void 0&&E(e,"minimum",r.minimum),r.exclusiveMinimum!==void 0&&E(e,"exclusiveMinimum",r.exclusiveMinimum),r.maximum!==void 0&&z(e,"maximum",r.maximum),r.exclusiveMaximum!==void 0&&z(e,"exclusiveMaximum",r.exclusiveMaximum),r.multipleOf!==void 0&&qe(e,r.multipleOf),r.format!==void 0&&(e.format??=r.format,r.format.includes("int")&&(e.isInt=!0)),r.mime&&Le(e,r.mime);for(let o of r.patterns??[])Fe(e,o);return e}var dn={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""};function L(t){let e=t._zod.def;return e.type==="pipe"&&e.in._zod.traits.has("$ZodTransform")?L(e.out):e.type==="catch"?L(e.innerType):t._zod.optin}var cn=new Set(["promise","optional","nonoptional","nullable","readonly","default","prefault","catch"]);function _(t,e=new Set){if(e.has(t))return!1;e.add(t);let n=t._zod.def,r=n.type;return r==="transform"?!0:r==="array"?_(n.element,e):r==="set"?_(n.valueType,e):r==="lazy"?_(n.getter(),e):cn.has(r)?_(n.innerType,e):r==="intersection"?_(n.left,e)||_(n.right,e):r==="record"||r==="map"?_(n.keyType,e)||_(n.valueType,e):r==="pipe"?t._zod.traits.has("$ZodCodec")||_(n.in,e)||_(n.out,e):r==="object"?Object.values(n.shape).some(i=>_(i,e)):r==="union"?n.options.some(i=>_(i,e)):r==="tuple"?n.items.some(i=>_(i,e))||(n.rest?_(n.rest,e):!1):!1}function ln(t){let e=Object.values(t).filter(n=>typeof n=="number");return Object.entries(t).filter(([n])=>e.indexOf(+n)===-1).map(([,n])=>n)}function Be(t){let e=t.anyOf;if(!Array.isArray(e)||e.length===0||t.type!==void 0)return;let n=[];for(let r of e){if(!r||typeof r!="object")return;Be(r);let i=Object.keys(r);if(i.length!==1||i[0]!=="type")return;for(let o of[r.type].flat()){if(typeof o!="string")return;n.includes(o)||n.push(o)}}delete t.anyOf,t.type=n.length===1?n[0]:n}var Ue=new Set(["type","properties","required","additionalProperties"]),We=t=>{let e=t.additionalProperties;return e&&typeof e=="object"&&Object.keys(e).length?e:null},Ce=(t,e)=>JSON.stringify(t)===JSON.stringify(e);function ee(t){for(let i of t){if(typeof i!="object"||i.type!=="object")return null;for(let o in i)if(!Ue.has(o))return null}let e={},n=new Set;for(let i of t){for(let o in i.properties){if(Object.prototype.hasOwnProperty.call(e,o))continue;let a=[];for(let d of t){let s=d.properties?.[o]??We(d);s&&!a.some(y=>Ce(y,s))&&a.push(s)}e[o]=a.length===1?a[0]:ee(a)??{allOf:a}}for(let o of i.required??[])n.add(o)}let r={type:"object",properties:e};if(n.size&&(r.required=[...n]),t.every(i=>i.additionalProperties===!1))r.additionalProperties=!1;else{let i=[];for(let o of t){let a=We(o);a&&!i.some(d=>Ce(d,a))&&i.push(a)}i.length===1?r.additionalProperties=i[0]:i.length>1&&(r.additionalProperties={allOf:i})}return r}function un(t){let e=t.allOf;if(!Array.isArray(e)||e.length<2)return;for(let i of Ue)if(i in t)return;let n=e.filter(i=>Array.isArray(i.oneOf)||Array.isArray(i.anyOf)),r;if(!n.length)r=ee(e);else{let i=n[0],o=Array.isArray(i.oneOf)?"oneOf":"anyOf";if(Object.keys(i).length!==1)return;let a=e.filter(s=>s!==i),d=i[o].map(s=>ee([...a,s]));if(d.some(s=>!s))return;r={[o]:d}}r&&(delete t.allOf,Object.assign(t,r))}function Ve(t){let e=t;for(let S of["anyOf","oneOf"]){let T=e[S];if(!Array.isArray(T))continue;let O=T.map(Ve);O.some((v,h)=>v!==T[h])&&(e={...e,[S]:O})}let n=[e.type].flat(),r=!n.includes("string")&&n.some(S=>S==="number"||S==="integer"),i=e.enum??(e.const!==void 0?[e.const]:void 0);if(!r&&!i?.some(S=>typeof S=="number"))return e;let{minimum:o,maximum:a,exclusiveMinimum:d,exclusiveMaximum:s,multipleOf:y,format:p,id:b,...f}=e;return f.enum?f.enum=f.enum.map(S=>typeof S=="number"?String(S):S):typeof f.const=="number"&&(f.const=String(f.const)),r&&(f.type="string",i||(f.pattern=n.includes("number")?"^-?\\d+(?:\\.\\d+)?$":"^-?\\d+$")),f}var B=class{constructor(e,n){this.override=e;this.refs=n}done=new Map;path=[];cyclic=new Map;write(e,n=!1){let r=this.refs.get(e);if(r!==void 0&&!n)return{$ref:r};if(this.path.includes(e))return this.cyclic.has(e)||this.cyclic.set(e,""),{};let i=this.done.get(e);if(i)return i;this.path.push(e);try{let o=this.written(e);return this.done.set(e,o),o}finally{this.path.pop()}}written(e){let n={},r,i=e._zod.toJSONSchema?.();i?Object.assign(n,i):r=this.process(e,n);let o=fe.get(e);if(o)for(let d of Object.keys(o))n[d]=o[d];_(e)&&(delete n.examples,delete n.default),"_prefault"in n&&(n.default??=n._prefault,delete n._prefault);let a=n;if(r){let d=this.write(r);a={...n};for(let s of Object.keys(d))s in n||(a[s]=d[s])}return this.override({zodSchema:e,jsonSchema:a}),Be(a),e._zod.def.type==="intersection"&&un(a),a}process(e,n){let r=e._zod.def;switch(r.type){case"string":{n.type="string";let{minimum:i,maximum:o,format:a,patterns:d,contentEncoding:s,laxFormat:y}=I(e);if(typeof i=="number"&&(n.minLength=i),typeof o=="number"&&(n.maxLength=o),a&&(n.format=dn[a]??a,(n.format===""||a==="time"||y)&&delete n.format),s&&(n.contentEncoding=s),d&&d.size>0){let p=[...d];p.length===1?n.pattern=p[0].source:n.allOf=p.map(b=>({pattern:b.source}))}return}case"number":{let{minimum:i,maximum:o,multipleOf:a,exclusiveMinimum:d,exclusiveMaximum:s,isInt:y}=I(e);if(n.type=y?"integer":"number",typeof d=="number"&&d>=(i??Number.NEGATIVE_INFINITY)?n.exclusiveMinimum=d:typeof i=="number"&&(n.minimum=i),typeof s=="number"&&s<=(o??Number.POSITIVE_INFINITY)?n.exclusiveMaximum=s:typeof o=="number"&&(n.maximum=o),a){let[p,...b]=new Set(a.filter(f=>Number.isFinite(f)&&f!==0).map(Math.abs));p!==void 0&&(n.multipleOf=p),b.length&&(n.allOf=[...n.allOf??[],...b.map(f=>({multipleOf:f}))])}return}case"boolean":case"success":n.type="boolean";return;case"null":n.type="null";return;case"never":n.not={};return;case"enum":{let i=ln(r.entries);i.length===0?n.not={}:(i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),n.enum=i);return}case"literal":{let i=r.values.filter(o=>o!==void 0).map(o=>typeof o=="bigint"?Number(o):o);if(r.values.length===0)n.not={};else if(i.length===1)n.type=i[0]===null?"null":typeof i[0],n.const=i[0];else if(i.length>1){for(let o of["number","string","boolean"])i.every(a=>typeof a===o)&&(n.type=o);i.every(o=>o===null)&&(n.type="null"),n.enum=i}return}case"template_literal":n.type="string",n.pattern=e._zod.pattern.source;return;case"file":{n.type="string",n.format="binary",n.contentEncoding="binary";let{minimum:i,maximum:o,mime:a}=I(e);i!==void 0&&(n.minLength=i),o!==void 0&&(n.maxLength=o),a&&(a.length===0?n.not={}:a.length===1?n.contentMediaType=a[0]:n.anyOf=a.map(d=>({contentMediaType:d})));return}case"array":{let{minimum:i,maximum:o}=I(e);typeof i=="number"&&(n.minItems=i),typeof o=="number"&&(n.maxItems=o),n.type="array",n.items=this.write(r.element);return}case"object":{let i=r.shape;n.type="object";let o={};n.properties=o;for(let d in i)Object.defineProperty(o,d,{value:this.write(i[d]),writable:!0,enumerable:!0,configurable:!0});let a=Object.keys(i).filter(d=>L(i[d])===void 0);a.length>0&&(n.required=a),r.catchall?._zod.def.type==="never"?n.additionalProperties=!1:r.catchall&&(n.additionalProperties=this.write(r.catchall));return}case"union":n[r.inclusive===!1?"oneOf":"anyOf"]=r.options.map(i=>this.write(i));return;case"intersection":{let i=d=>"allOf"in d&&Object.keys(d).length===1,o=this.write(r.left),a=this.write(r.right);n.allOf=[...i(o)?o.allOf:[o],...i(a)?a.allOf:[a]];return}case"tuple":{let i=r.items;n.type="array",n.prefixItems=i.map(s=>this.write(s)),r.rest?n.items=this.write(r.rest):n.items=!1;let o=i.length;for(;o>0&&L(i[o-1])!==void 0;)o-=1;o>0&&(n.minItems=o),r.rest||(n.maxItems=i.length);let{minimum:a,maximum:d}=I(e);typeof a=="number"&&(n.minItems=a),typeof d=="number"&&(n.maxItems=d);return}case"record":{let i=r.keyType;n.type="object";let o=I(i).patterns;if(r.mode==="loose"&&o&&o.size>0){let d=this.write(r.valueType),s={};for(let y of o)s[y.source]=d;n.patternProperties=s}else n.propertyNames=Ve(this.write(i)),n.additionalProperties=this.write(r.valueType);let a=i._zod.values;if(a&&!r.partial&&L(r.valueType)===void 0){let d=[...a].filter(s=>typeof s=="string"||typeof s=="number");d.length>0&&(n.required=d.map(String))}return}case"nullable":n.anyOf=[this.write(r.innerType),{type:"null"}];return;case"default":case"prefault":{let i=r.defaultValue,o,a=!1,d=JSON.stringify(i,(s,y)=>typeof y=="bigint"?(a=!0,null):y);return!a&&d!==void 0&&(o=JSON.parse(d)),a||(n[r.type==="default"?"default":"_prefault"]=o),r.innerType}case"catch":{try{n.default=r.catchValue(void 0)}catch{}return r.innerType}case"readonly":return n.readOnly=!0,r.innerType;case"pipe":return r.in._zod.traits.has("$ZodTransform")?r.out:r.in;case"lazy":return e._zod.innerType;case"optional":case"nonoptional":case"promise":return r.innerType;default:return}}};function Ge(t,e=()=>{}){let n=t,r=new B(e,new Map),i=r.write(n,!0);if(r.cyclic.size>0){let o=new Map,a=0,d=[];for(let y of r.cyclic.keys())if(y===n)o.set(y,"#");else{let p=`__schema${a++}`;o.set(y,`#/$defs/${p}`),d.push([y,p])}r=new B(e,o),i=r.write(n,!0);let s={};for(let[y,p]of d)s[p]=r.write(y,!0);d.length>0&&(i={...i,$defs:s})}return JSON.parse(JSON.stringify({$schema:"https://json-schema.org/draft/2020-12/schema",...i}))}function Ke(t){return Ge(t,mn)}var fn={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string"},pn={phone:"A phone number as it is written, like +1 555 123 4567 or 020 7946 0958 ext. 12.",place:"An address or a place's name, as a person would search a map for it.",duration:"A length of time in whole minutes: 90 is 1 h 30 min."};function mn(t){me(t.zodSchema)&&(t.jsonSchema["x-graview-app-link"]=!0);let e=ye(t.zodSchema);if(e&&(t.jsonSchema.type==="string"||t.jsonSchema.type==="array")){t.jsonSchema["x-graview-linked"]={address:e.address,kinds:[...e.kinds],cardinality:e.cardinality};let s=e.kinds.join(" or "),y=`${e.cardinality==="many"?"Records":"A record"}: a ${s} in the app ${e.address}, as "${e.kinds[0]}:<id>" \u2014 an id found there with find_linked. Linking never changes that app.`,p=t.jsonSchema.description;typeof p=="string"&&p.includes(y)||(t.jsonSchema.description=`${typeof p=="string"&&p?`${p.replace(/\.?$/,".")} `:""}${y}`)}if(we(t.zodSchema)&&(t.jsonSchema["x-graview-repeat"]=!0,!t.jsonSchema.type&&!t.jsonSchema.anyOf&&!t.jsonSchema.oneOf&&Object.assign(t.jsonSchema,hn())),Se(t.zodSchema)){t.jsonSchema.contentMediaType="text/markdown";let s=t.jsonSchema.description;typeof s=="string"&&s.endsWith("Written in Markdown.")||(t.jsonSchema.description=`${typeof s=="string"&&s?`${s.replace(/\.?$/,".")} `:""}Written in Markdown.`)}let n=Te(t.zodSchema);if(n){let s=t.jsonSchema;s["x-graview-type"]=n,n==="duration"&&(s["x-graview-unit"]="minutes"),s.description??=pn[n]}let r=Re(t.zodSchema,!1);if(r){let s=De(r);t.jsonSchema["x-graview-format"]=s.format??"unit",s.currency&&(t.jsonSchema["x-graview-currency"]=s.currency),s.unit&&s.format!=="money"&&(t.jsonSchema["x-graview-unit"]=s.unit);let y=t.jsonSchema.description;t.jsonSchema.description=typeof y=="string"&&y.length>0?`${y} ${Y(s)}`:Y(s)}let i=t.zodSchema._zod?.def;if(!i||i.type!=="string"||typeof i.format!="string"||i.format==="regex")return;let o=t.jsonSchema,a=(i.checks??[]).map(s=>s._zod?.def).filter(s=>s?.format==="regex"&&s.pattern instanceof RegExp).map(s=>s.pattern.source);delete o.pattern;let d=o.allOf;Array.isArray(d)&&d.every(s=>typeof s=="object"&&s!==null&&Object.keys(s).length===1&&"pattern"in s)&&delete o.allOf,o.format=fn[i.format]??i.format,a.length===1?o.pattern=a[0]:a.length>1&&(o.allOf=a.map(s=>({pattern:s})))}function ne(t,e){let n=C(t.input),r=Ke(t.input);if(e&&r.properties){let o=a=>e.includes(a)?e.indexOf(a):e.length;r.properties=Object.fromEntries(Object.entries(r.properties).sort(([a],[d])=>o(a)-o(d)))}let i=r.properties??{};if(Ae(t)){let o=t.creates.join(" | ");i.id={type:"string",minLength:1,description:`Optional: the id for the ${o} this makes. Refused if the graph already has it; left out, one is minted from the label.`},r.properties=i}Oe(t)&&(r.additionalProperties=!1);for(let o of n){let a=i[o.name];if(!a)continue;let d=o.kinds.includes("*")?"any node kind":o.kinds.join(" | ");a.description=[a.description,`Id of a node (${d}).`].filter(Boolean).join(" ")}return{name:t.name,...t.title===void 0?{}:{title:t.title},description:t.description??t.title??t.name,inputSchema:r,nodeRefs:n}}function hn(){let t={type:"string",pattern:"^\\d{4}-\\d{2}-\\d{2}$"},e=(n,r)=>({type:"integer",minimum:n,maximum:r});return{type:"object",description:'How the date beside it repeats; the date is the first occurrence. "on" is weekdays for "week", days of the month (-1 the last) for "month".',properties:{every:{type:"string",enum:[...be]},interval:e(1,99),on:{type:"array",minItems:1,maxItems:31,items:{anyOf:[{type:"string",enum:[...ge]},e(-1,31)]}},until:t,count:e(1,1e3),except:{type:"array",maxItems:500,items:t},continues:{type:"string",maxLength:200}},required:["every"],additionalProperties:!1}}function Ze(t){let e=new Set;for(let n=t;n;n=n.onBehalfOf)n.id!==void 0&&e.add(`${n.kind}:${n.id}`);return e}function U(t,e){let n=Ze(e),r=p=>{if(p.kind==="rule")return!1;let b=Ze(p);if(b.size===0)return!1;for(let f of b)if(n.has(f))return!1;return!0},i,o=()=>{if(i)return i;i=new Map;for(let p of t.log.live()){if(p.undoes!==void 0)continue;let b=r(p.author)?p.author:void 0;for(let f of p.primitives){f.op==="remove-node"&&i.delete(f.node.id);let S=f.op==="add-node"?f.node.id:f.op==="patch-node"||f.op==="splice-text"?f.id:void 0;if(S===void 0)continue;let T=f.op==="add-node"?Object.keys(f.node):f.op==="splice-text"?[f.field]:Object.keys(f.after),O=i.get(S);(f.op==="add-node"||!O)&&i.set(S,O=new Map);for(let v of T)v==="id"||v==="kind"||(b?O.set(v,b):O.delete(v))}}return i},a=t.schema,d=new Map,s=(p,b)=>{let f=`${p}\0${b}`,S=d.get(f);if(S===void 0){let T=a.tryDefinition(p)?.fields?.shape;S=T!==void 0&&b in T&&Pe(T[b]).type==="text",d.set(f,S)}return S},y=p=>t.graph.getNode(p)?.kind;return{prose:s,say:p=>W(p,{graph:t.graph,schema:a}),fieldBy(p,b){let f=y(p);if(!(f===void 0||!s(f,b)))return o().get(p)?.get(b)},recordBy(p){let b=y(p),f=o().get(p);if(b===void 0||!f)return;let S;for(let[T,O]of f)s(b,T)&&(S=O);return S}}}var te=(t,e,n)=>({untrusted:!0,authoredBy:n.say(e),text:t}),yn="the host's ranker";function Ye(t,e){return{...t,hits:t.hits.map(n=>{if(n.about!=="node")return n;n.why.by==="meaning"&&n.why.matched!==void 0&&(n={...n,why:{...n.why,matched:{untrusted:!0,authoredBy:yn,text:n.why.matched}}});let r=e.recordBy(n.id);if(!r)return n;let i=e.prose(n.kind,n.why.field)?e.fieldBy(n.id,n.why.field):r;return{...n,label:te(n.label,r,e),...n.apart!==void 0?{apart:te(n.apart,r,e)}:{},why:i?{...n.why,fragment:te(n.why.fragment,i,e)}:n.why}})}}var ie=(t,e,n)=>({title:t,readOnlyHint:e,destructiveHint:!1,idempotentHint:n,openWorldHint:!1}),gn={name:"subscribe",title:"Notify me when something happens",description:`Subscribe the person you act for to be told when something happens in this app \u2014 their host delivers it (an email, a push). on is one of: "act" (an act runs; give act, its declared name, and/or record), "created" (a record of kind is added), "changed" (a record of kind, or the one record, changes), "reaches" (a record of kind, or the one record, comes to satisfy condition, an expression in the app's rule language such as done == true or amount > 100). They are told only of changes someone else made, unless alsoMine is true, and only of records they may see. Returns the subscription and its sentence. Changes nothing in the app.`,inputSchema:{type:"object",properties:{on:{type:"string",enum:["act","created","changed","reaches"],description:"What to be told of."},act:{type:"string",description:"An act's declared name, for on: act."},kind:{type:"string",description:"A kind, for created, changed and reaches."},record:{type:"string",description:"One record, by id or name: for act, changed and reaches."},condition:{type:"string",description:"For reaches: what the record should come to satisfy, in the rule language (done == true)."},alsoMine:{type:"boolean",description:"Also when the person themselves made the change; false when unsaid."}},required:["on"],additionalProperties:!1},mutating:!1,annotations:ie("Notify me when something happens",!1,!1)},bn={name:"unsubscribe",title:"Stop notifying me",description:"Take away one of the person's subscriptions, by the id list_subscriptions or subscribe answered. Changes nothing in the app.",inputSchema:{type:"object",properties:{id:{type:"string",description:"The subscription's id."}},required:["id"],additionalProperties:!1},mutating:!1,annotations:ie("Stop notifying me",!1,!0)},wn={name:"list_subscriptions",title:"What I am notified of",description:`List what the person you act for is told of in this app: each subscription's id and its sentence ("When someone else adds a task").`,inputSchema:{type:"object",properties:{},additionalProperties:!1},mutating:!1,annotations:ie("What I am notified of",!0,!0)},re=[gn,bn,wn];var F=t=>{let e;return()=>e??=t().catch(n=>{throw e=void 0,n})},Sn=F(()=>(__graviewPreload(import.meta.url,["./chunk.CANTHIRO.js","./chunk.CSA6SWTI.js","./chunk.IYVBJDR7.js","./chunk.VTCPA4V4.js","./chunk.FGJM4LJO.js","./chunk.K7WME4P4.js","./chunk.MDIAWTNK.js","./chunk.PEA4D66Y.js","./chunk.TRPPN2GD.js","./chunk.S2ATSY6P.js","./chunk.72Q4R7N6.js","./chunk.6W2DUW5S.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.HE545Z6I.js"))),kn=()=>(__graviewPreload(import.meta.url,["./chunk.TXEWSZGO.js","./chunk.MDIAWTNK.js","./chunk.PEA4D66Y.js","./chunk.TRPPN2GD.js","./chunk.6W2DUW5S.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.65F3DF5Q.js")).catch(()=>{}),vn=async()=>{(await kn())?.judgeWithLines()},q=F(()=>(__graviewPreload(import.meta.url,["./chunk.WVUJXDXZ.js","./chunk.VTCPA4V4.js","./chunk.FGJM4LJO.js","./chunk.K7WME4P4.js","./chunk.MDIAWTNK.js","./chunk.PEA4D66Y.js","./chunk.TRPPN2GD.js","./chunk.72Q4R7N6.js","./chunk.6W2DUW5S.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.JCJ7NTW4.js"))),An=F(()=>(__graviewPreload(import.meta.url,["./chunk.7R6GXJS4.js","./chunk.G4JJXA63.js","./chunk.MSPRCR3Q.js","./chunk.CSA6SWTI.js","./chunk.3FUFVVR4.js","./chunk.XOZU4OFA.js","./chunk.IYVBJDR7.js","./chunk.Q5WEOX3Q.js","./chunk.P2W727C7.js","./chunk.XXCT6DLX.js","./chunk.TXEWSZGO.js","./chunk.WVUJXDXZ.js","./chunk.VTCPA4V4.js","./chunk.FGJM4LJO.js","./chunk.K7WME4P4.js","./chunk.MDIAWTNK.js","./chunk.PEA4D66Y.js","./chunk.TRPPN2GD.js","./chunk.MT45H2T5.js","./chunk.S2ATSY6P.js","./chunk.72Q4R7N6.js","./chunk.6W2DUW5S.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.4QVZXCV5.js"))),On=F(()=>(__graviewPreload(import.meta.url,["./chunk.GZBODS7Z.js","./chunk.CANTHIRO.js","./chunk.CSA6SWTI.js","./chunk.4DCPB67O.js","./chunk.Y4VOCJ7R.js","./chunk.IYVBJDR7.js","./chunk.VTCPA4V4.js","./chunk.FGJM4LJO.js","./chunk.K7WME4P4.js","./chunk.MDIAWTNK.js","./chunk.PEA4D66Y.js","./chunk.TRPPN2GD.js","./chunk.MT45H2T5.js","./chunk.S2ATSY6P.js","./chunk.72Q4R7N6.js","./chunk.6W2DUW5S.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.MXTDQXVW.js"))),Rn=F(()=>(__graviewPreload(import.meta.url,["./chunk.RIS3OKAI.js","./chunk.DUZS52WX.js","./chunk.MDIAWTNK.js","./chunk.PEA4D66Y.js","./chunk.TRPPN2GD.js","./chunk.6W2DUW5S.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.XDEKL6TJ.js"))),Tn=t=>t.definitions.some(e=>Z(e).size>0),Xe=t=>({value:K(t),label:t.label,...t.describe?{describe:t.describe}:{},...t.card?{card:t.card}:{},fields:t.fields,...t.app?{app:t.app}:{}});async function _n(t,e,n,r){let i=String(n.relation??""),[o,a]=i.includes(".")?i.split(".",2):[void 0,i],d=t.schema.definitions.flatMap(v=>[...Z(v)].map(([h,u])=>({kind:v.kind,name:h,relation:u}))),s=d.filter(v=>v.name===a&&(o===void 0||v.kind===o));if(s.length!==1){let v=d.map(h=>`${h.kind}.${h.name}`).join(", ")||"none";return{ok:!1,error:`${s.length===0?`No relation to another app is called "${i}"`:`"${i}" names a relation of several kinds`}. The relations to other apps are: ${v}.`}}let{kind:y,name:p,relation:b}=s[0];if(!r)return{ok:!1,error:`This seat cannot read ${b.address}: its host reads no other app's records. Nothing was changed.`};let f={kind:e.kind,...e.id===void 0?{}:{id:e.id},...e.roles?{roles:e.roles}:{}},S=typeof n.of=="string"?n.of:void 0;if(S!==void 0){let v=t.graph.getNode(S);if(!v||v.kind!==y)return{ok:!1,error:`No ${y} "${S}".`};let h=he(v[p],b),u=await Promise.all(h.map(w=>Promise.resolve().then(()=>r.resolve(w,f)).catch(()=>null)));return{ok:!0,data:{relation:`${y}.${p}`,app:b.address,records:u.map((w,k)=>w===null?{value:K(h[k]),missing:!0}:"denied"in w?{denied:!0,said:"linked record (no access)"}:Xe(w))},reads:[S]}}let T=typeof n.limit=="number"&&n.limit>0?Math.min(n.limit,20):20,O=await Promise.resolve().then(()=>r.find({address:b.address,kinds:b.kinds,query:String(n.query??""),limit:T},f)).catch(()=>[]);return Array.isArray(O)?{ok:!0,data:{relation:`${y}.${p}`,app:b.address,records:O.map(Xe),link:`edit-${y} with ${p} set to a record's value`}}:{ok:!0,data:{relation:`${y}.${p}`,app:b.address,denied:!0,said:"linked record (no access)"}}}var M=t=>({title:t,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}),Qe={description:'Which records: false (the default) the live ones, true only the archived ones, "all" both. An archived record is set aside, not gone: unarchive-<kind> brings it back.',anyOf:[{type:"boolean"},{type:"string",enum:["all"]}]},oe={type:"number",description:"Where the page starts; 0 when unsaid."},se=[{name:"search_graph",title:"Find by name",description:"Find things by name: records whose name or readable fields carry the words, and the kinds, places and rules the words name \u2014 each with why it matched. Reach for this before get_graph when you know what something is called. Words match the start of words, case and accents aside; key:value tokens narrow as a list's filter does (done:false, is:any for past records, kind:<kind>). Pass subject (a node id) to get the acts you may run on it as hits too. When few records match exactly, records with a near word follow \u2014 a typo, another form of the word, a meaning \u2014 each with near: true and why.matched, the record's own word that answered.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Words, with optional key:value conditions."},limit:{type:"number",description:"Most hits to return; at most 20."},subject:{type:"string",description:"A node id whose acts to include."},archived:Qe},required:["query"],additionalProperties:!1},mutating:!1,annotations:M("Find by name")},{name:"get_graph",title:"Read the graph",description:"Read the graph, 25 nodes a page: their fields, the edges out of them, and how many more. Start here when you need the shape of the domain rather than one thing in it.",inputSchema:{type:"object",properties:{offset:oe,archived:Qe},additionalProperties:!1},mutating:!1,annotations:M("Read the graph")},{name:"get_node",title:"Read one node",description:"Read one node: its fields, its links (id, kind and label, 20 each way a page), the violations that implicate it, and its computed values: read-only fields worked out from what you can see, which no act sets. Use this to check a thing before you change it.",inputSchema:{type:"object",properties:{id:{type:"string",description:"A node's id, or its name."},offset:oe},required:["id"],additionalProperties:!1},mutating:!1,annotations:M("Read one node")},{name:"get_violations",title:"List the problems",description:"List the invariant violations the graph currently has, 20 a page, with the repairs that would resolve each one. Read this before proposing work: a rule that is already broken is more urgent than anything you could add.",inputSchema:{type:"object",properties:{offset:oe,context:{type:"object",description:"Evaluation context, e.g. { weekStart }."}},additionalProperties:!1},mutating:!1,annotations:M("List the problems")},{name:"get_affordances",title:"Ask what can be done",description:"Ask what can legally be done with a selection, ranked. Prefer these over composing a mutation by hand: they are derived from the schema, the invariants and the shape of the graph, so they cannot name an action that does not exist.",inputSchema:{type:"object",properties:{selection:{type:"array",items:{type:"string"},description:"Node ids."},context:{type:"object"}},required:["selection"],additionalProperties:!1},mutating:!1,annotations:M("Ask what can be done")},{name:"describe_place",title:"Say what a place shows",description:`Say what one place of the app shows you, as a person in your seat would see it: its headings, its figures as drawn, its lists with each record's title and what its card or row says, the headings a list is grouped under, what an empty list says, the forms it offers (each field in the order asked, its label, whether it must be answered, what it takes and its choices), and any block that could not be worked out. Pass a place's slug ("home", a lens's address like "the-offers", a kind's like "offers"), a record's id, or a visitor form's "forms/<name>", and width 390 for a phone. Use it after a change to check what somebody now sees, instead of guessing.`,inputSchema:{type:"object",properties:{place:{type:"string",description:`"home", a place's slug, a record's id, or "forms/<name>" for a visitor form.`},width:{type:"number",description:"The screen's width in CSS pixels; 390 is a phone, 1440 when unsaid."}},required:["place"],additionalProperties:!1},mutating:!1,annotations:M("Say what a place shows")},{name:"preview_mutation",title:"Try an act without applying it",description:"Try a mutation without applying it: get back the diff it would produce and any invariant it would break. Do this when you are unsure, rather than applying and undoing.",inputSchema:{type:"object",properties:{mutation:{type:"string"},args:{type:"object"}},required:["mutation","args"],additionalProperties:!1},mutating:!1,annotations:M("Try an act without applying it")},{name:"undo_batch",title:"Undo a batch",description:"Undo one batch of operations. Fails, naming the blocking operation, when a later operation read what it wrote.",inputSchema:{type:"object",properties:{batch:{type:"string"},include:{type:"array",items:{type:"string"}}},required:["batch"],additionalProperties:!1},mutating:!0,annotations:{title:"Undo a batch",readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1}},{name:"list_suggestions",title:"List what is suggested",description:"List the suggestions waiting for a person: changes the app's own actor proposed and did not make, each with its id, what it would do, who suggested it, what it was based on and how sure (0 to 1). Nothing changes until one is accepted (accept_suggestion) or declined (decline_suggestion); a declined one is never suggested again.",inputSchema:{type:"object",properties:{},additionalProperties:!1},mutating:!1,annotations:M("List what is suggested")},{name:"accept_suggestion",title:"Accept a suggestion",description:"Make a waiting suggestion's change, as this seat, carrying what it was based on. Returns the batch (undo_batch takes it back).",inputSchema:{type:"object",properties:{suggestion:{type:"string",description:"The suggestion's id, from list_suggestions."}},required:["suggestion"],additionalProperties:!1},mutating:!0,annotations:{title:"Accept a suggestion",readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1}},{name:"decline_suggestion",title:"Decline a suggestion",description:"Decline a waiting suggestion: nothing changes, the decline is kept in the log, and the same change is never suggested or made by the app's own actor again.",inputSchema:{type:"object",properties:{suggestion:{type:"string",description:"The suggestion's id, from list_suggestions."}},required:["suggestion"],additionalProperties:!1},mutating:!0,annotations:{title:"Decline a suggestion",readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}}],nn={name:"act_on_several",title:"Do one act to several records",description:`Run one act on several records at once, as one change with one undo. act is the act (its tool name or its declared name), records the records it runs on (ids or names; each goes in the act's subject), args what every call shares ("Set stage to Declined" is args { stage: "declined" }). Each record is judged on its own: one this seat may not change is named with why, and the rest still apply. Returns the batch (undo_batch takes it all back), the records changed, those already so, and those refused.`,inputSchema:{type:"object",properties:{act:{type:"string",description:"The act to run on each record."},records:{type:"array",items:{type:"string"},minItems:1,maxItems:200,description:"Ids or names of the records."},args:{type:"object",description:"Arguments every call shares, besides the record."}},required:["act","records"],additionalProperties:!1},mutating:!0,annotations:{title:"Do one act to several records",readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1}},ue={name:"suggest_changes",title:"Suggest changes",description:"Keep calls ({ act, args }) as one suggestion a person accepts or declines, with its basis and confidence (0 to 1). Changes nothing; a declined change is refused.",inputSchema:{type:"object",properties:{calls:{type:"array",items:{type:"object"}},basis:{type:"string"},confidence:{type:"number"}},required:["calls","basis"]},mutating:!0,annotations:{title:"Suggest changes",readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},de={type:"object",description:"A lens, as draft_view returns one.",properties:{title:{type:"string"},lens:{type:"string"},on:{type:"string"},bindings:{type:"object"},options:{type:"object"}},required:["title","lens","on"]},ce={name:"draft_view",title:"Draw a view",description:'Draw a view of the data from words ("a board of tasks by status", "who covers what") as a lens the app could keep; or check a lens you wrote (lens); or change the one on screen (current, with ask: "only this month"). Returns the lens and its add-lens edit, or one sentence saying why not. Writes nothing.',inputSchema:{type:"object",properties:{ask:{type:"string",description:"What to see, in words."},lens:de,current:de},additionalProperties:!1},mutating:!1,annotations:M("Draw a view")},tn={name:"keep_lens",title:"Keep a view as a lens",description:"Keep a lens draft_view drew as one of the app's places: checked again, then written as the add-lens edit. Returns the remove-lens edit that takes it back.",inputSchema:{...de,additionalProperties:!1},mutating:!0,annotations:{title:"Keep a view as a lens",readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}},rn={name:"find_linked",title:"Find a record in another app",description:`A relation may go to a kind in another app (describe_app lists them under "Linked from other apps"). With relation and words, list the records there this seat may link \u2014 each with the value to link it by ("house:h1"), its name and its describe line. With of (a record id here), read the records that record links, as this seat may see them there. Linking one is the record's edit (edit-<kind>) with the relation set to the value. Another app this seat may not open answers denied, and nothing of it. Writes nothing; never changes the other app.`,inputSchema:{type:"object",properties:{relation:{type:"string",description:"The relation, by name (forHouse) or as <kind>.<relation> (scenario.forHouse)."},query:{type:"string",description:"Words to find by, in the other app's names; empty for the first few."},of:{type:"string",description:"A record here whose linked records to read, instead of finding."},limit:{type:"number",description:"Most records to return; at most 20."}},required:["relation"],additionalProperties:!1},mutating:!1,annotations:M("Find a record in another app")};function xn(t,e){return t===void 0?[]:t==="keep"&&!e?[ce,tn]:[ce]}var Mn="An argument that names a record takes its id or its name.",on=[...se.map(t=>t.name),nn.name,ue.name,ce.name,tn.name,rn.name,...re.map(t=>t.name)],an=64;function N(t){let{line:e,...n}=t;return n}function en(t){return{...t,...t.introduces?{introduces:t.introduces.map(N)}:{},...t.resolves?{resolves:t.resolves.map(N)}:{},...t.violationsAfter?{violationsAfter:t.violationsAfter.map(N)}:{}}}function Nn(t){let e=t.normalize("NFKD").replace(/\p{M}/gu,"").replace(/[^A-Za-z0-9_-]/g,"_");return e.length===0&&(e="act"),/^[A-Za-z_]/.test(e)||(e=`act_${e}`),e.slice(0,an)}function $n(t){let e=new Set(on),n=new Map;for(let r of t){let i=Nn(r),o=i;for(let a=2;e.has(o);a+=1)o=`${i.slice(0,an-`_${a}`.length)}_${a}`;e.add(o),n.set(r,o)}return n}function Dn(t,e){if(e.size===0)return t;let n=Object.fromEntries(Object.entries(t.properties??{}).filter(([i])=>!e.has(i))),r=(t.required??[]).filter(i=>!e.has(i));return{...t,properties:n,...t.required?{required:r}:{}}}function Pn(t,e,n,r){let i=ne(t,_e(r,t)),o=G(t),a=i.nodeRefs.length>0?`${i.description}${/[.!?]$/.test(i.description)?"":"."} ${Mn}`:i.description;return{name:e,title:o,description:a,inputSchema:Dn(i.inputSchema,n),mutating:!0,annotations:{title:o,readOnlyHint:!1,destructiveHint:t.destructive===!0||(t.severs?.length??0)>0,idempotentHint:t.idempotent===!0,openWorldHint:!1},act:t.name}}function le(t){if(t===null||typeof t!="object")return JSON.stringify(t)??"null";if(Array.isArray(t))return`[${t.map(le).join(",")}]`;let e=t;return`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${le(e[n])}`).join(",")}}`}function Jn(t){return`sha256:${$e(le(t))}`}function En(t,e,n,r,i,o=!1,a=!1,d=!1,s){let y=$n(t.map(f=>f.name)),p=[...xn(r,n),...o?[rn]:[],...a?re:[]];return{definitions:n?[...se.filter(f=>!f.mutating),...p]:[...se,nn,...d?[ue]:[],...p,...t.filter(f=>e.has(f.name)).map(f=>Pn(f,y.get(f.name),i(f),s))],names:y}}function At(t,e={}){let n=e.author??{kind:"agent"},r=t.allMutations(),i=new Set(t.permittedMutations(n).map(h=>h.name)),{definitions:o,names:a}=En(r,i,e.readOnly===!0,e.drafts?e.drafts.keep?"keep":"draw":void 0,h=>X(t.schema,t.policy,n,h),Tn(t.schema),e.subscriptions!==void 0,Ne(n),t.schema),d=Jn(o),s={app:e.app?.brand?.locale,appTimeZone:e.app?.brand?.timeZone},y=h=>pe(s,h),p=h=>{if(!on.includes(h)){for(let[u,w]of a)if(w===h)return u;return a.has(h)?h:xe(h,a.keys())}},b=h=>{let u=Me(h,a.keys());return u?` Did you mean "${u}"?`:""},f=h=>{let u=o.find(k=>k.name===h)??o.find(k=>k.act===h);if(u)return u;let w=p(h);return w===void 0?void 0:o.find(k=>k.act===w)},S=(h,u)=>{let w=r.find(c=>c.name===h);if(!w)return{args:u,resolved:[]};let k={...u},l=[];for(let c of C(w.input)){let m=k[c.name];if(typeof m!="string"||m.trim()==="")continue;let g=t.resolveRef(c,m,n);if(!g.ok){let A=g.reason==="none"?` Nothing was changed. Use search_graph to look it up, then pass its id as ${c.name}.`:" Nothing was changed.";return{ok:!1,error:`${g.message}${A}`,argument:c.name,candidates:g.candidates}}g.by!=="id"&&(k[c.name]=g.id,l.push({argument:c.name,given:m,id:g.id,label:g.label}))}return{args:k,resolved:l}},T=async(h,u)=>{try{await vn();let w=f(h);if(!w&&h===ue.name)return{ok:!1,error:"Only the app's own actor (automated: true) suggests changes.",reason:"forbidden"};if(!w){let l=p(h);if(l){let c=t.permits({name:l,args:u},n);if(!c.ok)return{ok:!1,error:c.refusal.message,reason:"forbidden"}}return{ok:!1,error:`Unknown tool "${h}".${b(h)} Available: ${o.map(c=>c.name).join(", ")}`}}if(w.mutating&&e.readOnly)return{ok:!1,error:`"${h}" changes the graph, and this seat is read-only.`,reason:"forbidden"};if(w.act!==void 0){let l=S(w.act,u);if("ok"in l)return l;let c=w.act,m=y(()=>j(t,n,t.apply({name:c,args:l.args},{...e.author?{author:e.author}:{},...V(e.via)})));return{ok:!0,data:{batch:m.batch,intent:m.intent,introduces:m.introduces.map(N),resolves:m.resolves.map(N),...l.resolved.length>0?{resolved:l.resolved}:{}},diff:m.diff}}let k=t.seenBy(n);switch(w.name){case"search_graph":{let l=typeof e.places=="function"?e.places():e.places,c=typeof u.subject=="string"?u.subject:void 0,m=He(k,String(u.query??""),{principal:n,rank:e.near,archived:ke(u.archived),limit:typeof u.limit=="number"&&u.limit>0?Math.min(u.limit,20):20,...l?{places:l}:{},...c?{subject:c,from:[c]}:{}}),g=m.later?await m.later:m;return{ok:!0,data:(await q()).searchRead(g,Ye(g,U(k,n))),reads:g.hits.flatMap(A=>A.about==="node"?[A.id]:[])}}case"get_graph":return{ok:!0,...(await q()).graphRead(k,U(k,n),u)};case"get_node":{let l=String(u.id??""),c=l,m;if(!k.graph.getNode(l)){let A=l.trim()===""?void 0:t.resolveRef({name:"id",kinds:["*"]},l,n);if(A?.ok)c=A.id,m={argument:"id",given:l,id:c,label:A.label};else return A?.reason==="ambiguous"?{ok:!1,error:A.message,argument:"id",candidates:A.candidates}:{ok:!1,error:`No node "${l}".`}}let g=(await q()).nodeRead(k,U(k,n),c,u);return{ok:!0,data:m?{...g.data,resolved:[m]}:g.data,reads:g.reads}}case"describe_place":{let l=e.app??{name:"",schema:t.schema},c=typeof u.width=="number"&&Number.isFinite(u.width)&&u.width>0?u.width:1440,{describePlace:m}=await Sn(),g=m(t,n,String(u.place??""),{app:l,width:c});if(!g.ok)return{ok:!1,error:`${g.error} The places are: ${g.places.join(", ")}.`};let A=new Set,$=H=>{for(let P of H)for(let x of P.groups??[])for(let D of x.items)A.add(D.id),$(D.parts)};return $(g.description.parts),{ok:!0,data:g.description,reads:[...A]}}case"find_linked":return _n(k,n,u,e.linked);case"draft_view":case"keep_lens":{let l=e.app??{name:"",schema:t.schema};return(await An()).runDraftTool(w.name,u,{app:l,principal:n,...e.drafts?{drafts:e.drafts}:{}})}case"get_violations":{let l=k.violations(u.context);return{ok:!0,...(await q()).violationsRead(l,u)}}case"get_affordances":{let l=u.selection??[];return{ok:!0,data:Ie(k,l,{...typeof e.derive=="function"?e.derive():e.derive,...e.author?{principal:e.author}:{},...u.context?{context:u.context}:{}}),reads:l.filter(m=>k.graph.has(m))}}case"preview_mutation":{let l=String(u.mutation),c=p(l)??l,m=S(c,u.args??{});if("ok"in m)return m;let g=t.missingFor({name:c,args:m.args},n);if(g)return{ok:!1,error:g.message,reason:"missing"};let A=j(t,n,t.preview({name:c,args:m.args},void 0,{author:n})),$=en(A);return{ok:!0,data:m.resolved.length>0?{...$,resolved:m.resolved}:$}}case"act_on_several":{let l=String(u.act??""),c=p(l)??l,m=r.find(R=>R.name===c);if(!m||!i.has(c)){let R=m?t.permits({name:c,args:{}},n):void 0;return R&&!R.ok?{ok:!1,error:R.refusal.message,reason:"forbidden"}:{ok:!1,error:`There is no act "${l}" this seat may run.${b(l)} Nothing was changed.`,reason:"invalid"}}let g=m.subject;if(!g)return{ok:!1,error:`"${G(m)}" does not act on a record, so it cannot be run on several. Nothing was changed.`,reason:"invalid"};let A=Array.isArray(u.records)?u.records.filter(R=>typeof R=="string"&&R.trim()!==""):[];if(A.length===0)return{ok:!1,error:"Name at least one record. Nothing was changed.",reason:"invalid"};let $=[],H=[];for(let R of A.slice(0,200)){let J=t.resolveRef({name:g.arg,kinds:g.kinds},R,n);if(!J.ok)return{ok:!1,error:`${J.message} Nothing was changed.`,argument:"records",candidates:J.candidates};$.push(J.id),J.by!=="id"&&H.push({argument:"records",given:R,id:J.id,label:J.label})}let P=S(c,{...u.args??{}});if("ok"in P)return P;let x=(await On()).actOnSeveral(t,{mutation:c,subject:g.arg,args:P.args},$,{author:n,...V(e.via)}),D=x.result?j(t,n,x.result):void 0;return{ok:!0,data:{...x.batch?{batch:x.batch,intent:x.intent}:{},applied:x.applied,unchanged:x.unchanged,refused:x.refused.map(R=>({record:R.id,label:R.label,error:R.message,reason:R.reason})),...x.allOrNothing?{keptNone:!0}:{},...D?{introduces:D.introduces.map(N),resolves:D.resolves.map(N)}:{},...H.length>0||P.resolved.length>0?{resolved:[...H,...P.resolved]}:{}},...D?{diff:D.diff}:{}}}case"subscribe":case"unsubscribe":case"list_subscriptions":{let l=await(await Rn()).runSubscriptionTool(w.name,u,{store:t,principal:e.subscriber??n,app:e.app?.name??"app",subscriptions:e.subscriptions});return l.ok?{ok:!0,data:l.data}:{ok:!1,error:l.error}}case"list_suggestions":{let l=Ee(t,n).map(c=>{let m=W(c.author,{graph:k.graph,schema:t.schema});return{id:c.id,intent:c.intent,by:m,at:c.at,about:c.about,...c.lineage?{basis:{untrusted:!0,authoredBy:m,text:c.lineage.basis},...c.lineage.confidence!==void 0?{confidence:c.lineage.confidence}:{}}:{}}});return{ok:!0,data:{suggestions:l},reads:[...new Set(l.flatMap(c=>c.about))]}}case"suggest_changes":{let l=u.calls.map(m=>({name:p(m.act)??m.act,args:m.args}));return{ok:!0,data:{suggestion:Je(t,l,{author:n,lineage:{basis:u.basis,confidence:u.confidence},...V(e.via)})?.id??null}}}case"accept_suggestion":case"decline_suggestion":{let l=String(u.suggestion??""),c={author:n,...V(e.via)},m=w.name==="accept_suggestion"?ze(t,l,c):je(t,l,c),g=j(t,n,m);return{ok:!0,data:{batch:g.batch,intent:g.intent,introduces:g.introduces.map(N),resolves:g.resolves.map(N)},diff:g.diff}}case"undo_batch":{let l=String(u.batch),c=u.include??[],m=k.canUndo([l,...c]);if(!m.ok)return{ok:!1,error:m.message};let g=j(t,n,t.undo([l,...c],{...e.author?{author:e.author}:{}}));return{ok:!0,data:en(g),diff:g.diff}}default:return{ok:!1,error:`Unknown tool "${h}".`}}}catch(w){let{reason:k,wouldNeed:l}=ve(w);return{ok:!1,error:w instanceof Error?w.message:String(w),reason:k,...l?{wouldNeed:l}:{}}}},O=new Set,v=h=>{for(let u of O)u(h)};return{definitions:o,hash:d,...e.author?{author:e.author}:{},onDiff(h){return t.subscribe(h)},onCall(h){return O.add(h),()=>O.delete(h)},async call(h,u){let w=f(h)?.mutating??!1,k={name:h,args:u,mutating:w,at:new Date().toISOString()};v({...k,phase:"running"});let l=m=>(v(m.ok?{...k,phase:"ok",...!w&&m.reads?{reads:m.reads}:{}}:{...k,phase:"failed",error:m.error}),m),c=await T(h,u);return l(c.ok&&!w?{...c,data:(await q()).withinReadChars(h,c.data)}:c)}}}function V(t){let e=typeof t=="function"?t():t;return e?{via:e}:{}}export{le as a,At as b};
@@ -1 +0,0 @@
1
- var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{a as Ue}from"./chunk.4DCPB67O.js";import{a as Be}from"./chunk.3FUFVVR4.js";import{a as We}from"./chunk.OZYZBRWO.js";import{a as X}from"./chunk.TI4OSTQV.js";import{a as fe}from"./chunk.FGJM4LJO.js";import{c as ce}from"./chunk.G6DISMVT.js";import{E as we,G as ln,J as He,P as Le,T as Fe,ba as Je}from"./chunk.B3T4N2XM.js";import{Ob as Ne,Oc as De,Yb as le,_b as je,da as ae,fa as U,ha as q,ka as Ee,ma as de,wb as Me}from"./chunk.6W2DUW5S.js";import{b as Se}from"./chunk.AJZBJBMO.js";var cn=e=>/^(?:aggregate|kind):([^,]+)$/.exec(e)?.[1];function Ge(e,n){let t=e.about??[];if(e.field!==void 0&&e.on!==void 0&&n(e.on))return{on:"field",id:e.on,field:e.field};let i=t.filter(n);if(i.length>1)return{on:"selection",ids:i};if(e.on!==void 0&&n(e.on))return{on:"record",id:e.on};if(i.length===1)return{on:"record",id:i[0]};let o=[e.on,...t].map(s=>s===void 0?void 0:cn(s)).find(s=>s!==void 0);return e.place!==void 0?{on:"lens",place:e.place,...o?{kind:o}:{}}:o!==void 0?{on:"list",kind:o}:{on:"place",place:"home"}}var V=e=>e.on==="record"||e.on==="field"?[e.id]:e.on==="selection"?e.ids:e.on==="act"&&e.id!==void 0?[e.id]:[],ue=(e,n)=>e.tryDefinition(n)?.fields?.shape??{},K=(e,n)=>e.tryDefinition(n)?.edges??{},pe=(e,n)=>new Set(e.tryDefinition(n)?.display?.hide??[]),H=(e,n)=>ae(e.tryDefinition(n.kind),n),xe=(e,n,t)=>Ee(e.tryDefinition(n),t)||U(t),Oe=e=>typeof e=="boolean"?e?"yes":"no":String(e);function ge(e,n){let t=e.kindsKeptFrom(n);return new Set(e.schema.kinds.filter(i=>!t.has(i)))}function Ce(e,n,t,i){if(!e.permits(n,t).ok)return!1;if(!i)return!0;try{return e.previewAll([n],{author:t}).ops.length>0}catch{return!1}}function ye(e,n,t){let i=e,{principal:o}=t,s=t.each??8,c=X(i)?.store??i,d=c.seenBy(o),l=c.schema,p=ge(c,o),a=r=>{let y=d.graph.getNode(r);return y&&p.has(y.kind)?y:void 0},f=c.allMutations(),h=new Map(f.map(r=>[r.name,r])),b=[],P=new Set,S=r=>{P.has(r.id)||(P.add(r.id),b.push(r))},m=r=>r.slice(0,s),C=V(n).filter(r=>a(r)!==void 0);if(V(n).length>0&&C.length===0)return{target:n,candidates:[]};let k=C.length===1?a(C[0]):void 0,g=k?.kind??(n.on==="list"?n.kind:n.on==="lens"?n.kind??t.places?.find(r=>r.as===n.place)?.kind:void 0)??(n.on==="selection"?a(C[0])?.kind:void 0);if(g!==void 0&&!p.has(g))return{target:n,candidates:[]};let A=(r,y)=>`act:${r}${Object.keys(y).length>0?`:${Object.values(y).map(T=>String(T)).join(",")}`:""}`,w=(r,y,T,v,$)=>{r.destructive||Object.values(y).some(u=>typeof u=="string"&&c.graph.has(u)&&a(u)===void 0)||Ce(c,{name:r.name,args:{...y}},o,v.length===0)&&S({type:"act",id:A(r.name,y),label:T,description:$??r.description??T,mutation:r.name,args:y,asks:v})};if(n.on!=="place"||t.acts)if(t.acts)for(let r of t.acts){let y=h.get(r.mutation);!y||r.destructive||n.on==="act"&&r.mutation!==n.act||w(y,r.args,r.label,(r.open??[]).filter(T=>!T.optional).map(T=>T.name),r.why)}else{let r=k?[k]:[];for(let y of f){if(n.on==="act"&&y.name!==n.act)continue;let T=y.input.shape??{},v=$=>Object.entries(T).filter(([u,O])=>u!==$&&O.safeParse?.(void 0).success===!1).map(([u])=>u);if(y.subject)for(let $ of r)le(l,y).includes($.kind)&&w(y,{[y.subject.arg]:$.id},`${y.title??U(y.name)}: ${H(l,$)}`,v(y.subject.arg));else g!==void 0&&(y.creates??[]).includes(g)&&w(y,{},y.title??U(y.name),v(void 0))}}let M=b.filter(r=>r.type==="act");b.splice(0,b.length,...m(M));let L=(r,y)=>{let T=je(l,f).get(r.kind),v=ue(l,r.kind),$=pe(l,r.kind),u=[];for(let[O,j]of Object.entries(v)){if(y!==void 0?O!==y:$.has(O)||r[O]!==void 0)continue;let D=fe(j),z=D?.type==="enum"?D.options??[]:D?.type==="boolean"?[!0,!1]:[];if(z.length===0)continue;let W=(T?.get(O)??[]).map(N=>h.get(N)).find(N=>N?.subject!==void 0&&Ce(c,{name:N.name,args:{[N.subject.arg]:r.id,[O]:z.find(Ae=>Ae!==r[O])??z[0]}},o,!0));if(W?.subject)for(let N of z)r[O]!==N&&u.push({type:"fill",id:`fill:${r.id}:${O}:${Oe(N)}`,label:`${xe(l,r.kind,O)}: ${Oe(N)}`,description:`Set ${xe(l,r.kind,O).toLowerCase()} of ${H(l,r)} to ${Oe(N)}`,record:r.id,field:O,value:N,call:{name:W.name,args:{[W.subject.arg]:r.id,[O]:N}}})}for(let[O,j]of Object.entries(K(l,r.kind))){if(y!==void 0&&O!==y)continue;let D=j.to==="*"?[...p]:j.to.filter(R=>p.has(R)),z=new Set(d.graph.out(r.id,O).map(R=>R.id)),W=f.find(R=>(R.connects??[]).includes(O)&&R.subject!==void 0&&le(l,R).includes(r.kind));if(!W?.subject)continue;let N=Ne(W.input).find(R=>R.name!==W.subject.arg);if(!N)continue;let Ae=D.flatMap(R=>N.kinds.length===0||N.kinds.includes(R)?d.graph.nodesOfKind(R):[]).filter(R=>R.id!==r.id&&!z.has(R.id)&&a(R.id)!==void 0);for(let R of m(Ae)){let Re={name:W.name,args:{[W.subject.arg]:r.id,[N.name]:R.id}};Ce(c,Re,o,!0)&&u.push({type:"fill",id:`fill:${r.id}:${O}:${R.id}`,label:`${U(O)}: ${H(l,R)}`,description:`Link ${H(l,r)} to ${H(l,R)}${j.description?` as ${j.description}`:""}`,record:r.id,field:O,value:R.id,call:Re})}}return u};if(n.on==="field"&&k)for(let r of L(k,n.field))S(r);else if(k&&n.on==="record")for(let r of m(L(k)))S(r);let J=r=>{let y=q(l,r).toLowerCase(),T=[{type:"panel",id:`panel:${r}:list`,label:`A list of ${y}`,description:`Every ${de(l.tryDefinition(r),r).toLowerCase()} this viewer may see, as a list`,panel:{lens:"blocks",kind:r}}],v=pe(l,r);for(let[$,u]of Object.entries(ue(l,r))){if(v.has($))continue;let O=fe(u),j=xe(l,r,$).toLowerCase();if(O?.type==="enum")T.push({type:"panel",id:`panel:${r}:group:${$}`,label:`${_(y)} by ${j}`,description:`A list of ${y} grouped by ${j}`,panel:{lens:"blocks",kind:r,group:$}}),T.push({type:"panel",id:`panel:${r}:columns:${$}`,label:`Columns of ${y} by ${j}`,description:`${_(y)} in a column for each ${j}`,panel:{lens:"columns",kind:r,column:$}});else if(O?.type==="number"||O?.type==="integer"||O?.type==="date"||O?.type==="datetime"){let D=O.type==="date"||O.type==="datetime";T.push({type:"panel",id:`panel:${r}:sort:${$}`,label:`${_(y)} by ${j}`,description:`A list of ${y}, the ${D?"latest":"highest"} ${j} first`,panel:{lens:"blocks",kind:r,sort:{by:$,direction:"desc"}}}),D&&T.push({type:"panel",id:`panel:${r}:calendar:${$}`,label:`A calendar of ${y}`,description:`${_(y)} on a calendar by ${j}`,panel:{lens:"calendar",kind:r,start:$}})}}return T},F=n.on==="place"?[...p]:g!==void 0?[g]:[];for(let r of F)for(let y of m(J(r)))S(y);for(let r of m((t.places??[]).filter(y=>y.kind===void 0?n.on==="place":p.has(y.kind)&&(n.on==="place"||y.kind===g))))n.on==="lens"&&r.as===n.place||S({type:"place",id:`place:${r.as}`,label:r.title,description:`Go to ${r.title}`,place:r.as});if(k){let r=[];for(let[y,T]of Object.entries(K(l,k.kind)))for(let v of d.graph.out(k.id,y))a(v.id)&&r.push({type:"record",id:`record:${v.id}`,label:H(l,v),description:`${_(T.description??U(y))}: ${H(l,v)}`,record:v.id,relation:y});for(let y of l.kinds)for(let[T,v]of Object.entries(K(l,y)))if(!(v.to!=="*"&&!v.to.includes(k.kind)))for(let $ of d.graph.in(k.id,T))$.kind===y&&a($.id)&&r.push({type:"record",id:`record:${$.id}`,label:H(l,$),description:`${_(v.inverse??U(T))}: ${H(l,$)}`,record:$.id,relation:T});for(let y of m(r))S(y)}else if(n.on==="list"||n.on==="lens")for(let r of m(g!==void 0?d.graph.nodesOfKind(g):[]))a(r.id)&&S({type:"record",id:`record:${r.id}`,label:H(l,r),description:`Open ${H(l,r)}`,record:r.id});else if(n.on==="selection")for(let r of C){let y=a(r);S({type:"record",id:`record:${r}`,label:H(l,y),description:`Open ${H(l,y)}`,record:r})}return{target:n,candidates:b}}var _=e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`,fn={columns:["board","kanban","column","lane","pipeline","stage","funnel"],board:["board","map","floor","layout","seat","slot"],calendar:["calendar","schedule","date","due","month","week","agenda","deadline","day"],timeline:["timeline","gantt","schedule","roadmap","span"],coverage:["coverage","matrix","grid","gap"],plan:["plan","floor","map","region","area"],blocks:["list","table","summary","overview","dashboard","card"]},un=new Set(["a","an","the","of","for","my","our","me","us","to","with","and","in","on","by","that","which","i","we","want","need","show","open","go","draw","make","new","view","views","panel","panels","page","lens","please","all","every","some","see","can","could","would","like","one","what","is","are","do","does","here","there","how","it","this","these","those"]),Z=e=>e.length>3&&e.endsWith("ies")?`${e.slice(0,-3)}y`:e.length>3&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e,$e=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").split(/[^a-z0-9]+/).filter(Boolean);function ze(e,n,t){let i=e,o=X(i)?.store??i,s=o.schema,c=ge(o,t.principal),d=o.seenBy(t.principal),l=V(n),p=new Set;for(let A of l){let w=d.graph.getNode(A)?.kind;w!==void 0&&c.has(w)&&p.add(w)}if(l.length>0&&p.size===0)return[];if(n.on==="list"&&p.add(n.kind),n.on==="lens"){let A=n.kind??t.places.find(w=>w.as===n.place)?.kind;A!==void 0&&p.add(A)}let a=new Map;for(let A of s.kinds){if(!c.has(A))continue;let w=s.tryDefinition(A);for(let M of[A,de(w,A),q(s,A)])for(let L of $e(M))a.set(Z(L),A)}let f=$e(t.said??"").filter(A=>!un.has(A)),h=new Set,b=[];for(let A of f){let w=a.get(Z(A));w!==void 0?h.add(w):b.push(Z(A))}let P=h.size>0?h:p;if((t.said??"").trim()!==""&&f.length===0)return[];if(P.size===0&&f.length===0)return[];let S=[];t.places.forEach((A,w)=>{if(A.hidden||n.on==="lens"&&A.as===n.place)return;let M=A.over??(A.kind!==void 0?[A.kind]:[]);if(M.length>0&&!M.some(F=>c.has(F)))return;let L=M.some(F=>P.has(F)),J=!L&&(A.reads??[]).some(F=>P.has(F));P.size>0&&!L&&!J||S.push({place:A,own:L,reads:J,at:w})});let m=A=>new Set($e(A.title).map(Z)),C=new Set(b.filter(A=>S.some(({place:w})=>m(w).has(A)))),k=[];for(let{place:A,own:w,reads:M,at:L}of S){let J=m(A),F=new Set((fn[A.lens??""]??[]).map(Z)),r=b.filter($=>J.has($)||F.has($)&&!C.has($)).length,y=b.length-r;if(b.length>0&&r===0)continue;let T=!M&&y===0?"full":"partial",v=(w?4:M?2:1)+r*2-y+(T==="full"?1:0);k.push({view:{place:A.as,title:A.title,...A.kind!==void 0?{kind:A.kind}:{},fit:T},score:v,at:L})}return k.filter((A,w)=>!k.slice(0,w).some(M=>M.view.place===A.view.place&&M.view.title===A.view.title)).sort((A,w)=>w.score-A.score||A.at-w.at).slice(0,t.most??3).map(A=>A.view)}var Pe=new WeakMap;function pn(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n.toString(36)}function gn(e,n){let t=e,i=X(t)?.store??t,o=i.schema,s=ge(i,n),d=i.allMutations().filter(S=>!S.destructive&&i.permits({name:S.name,args:{}},n).ok!==!1),l=`${[...s].join(",")}|${d.map(S=>S.name).join(",")}`,p=Pe.get(o)?.get(l);if(p)return p;let a=[...s].map(S=>{let m=pe(o,S),C={};for(let[g,A]of Object.entries(ue(o,S))){if(m.has(g))continue;let w=fe(A);w&&(C[g]=w.type==="enum"?`enum:${(w.options??[]).join("|")}`:w.type)}let k={};for(let[g,A]of Object.entries(K(o,S)))k[g]=A.to==="*"?[...s]:A.to.filter(w=>s.has(w));return{kind:S,noun:de(o.tryDefinition(S),S),plural:q(o,S),fields:C,relations:k}}),f=d.map(S=>({name:S.name,title:S.title??U(S.name),...S.subject?{on:le(o,S).filter(m=>s.has(m))}:{}})),h={kinds:a,acts:f},b={version:pn(JSON.stringify(h)),...h},P=Pe.get(o)??new Map;return P.set(l,b),Pe.set(o,P),b}var yn=e=>e.name??e.id??e.kind;function qe(e,n,t){let i=e,{principal:o}=t,s=X(i)?.store??i,c=s.seenBy(o),d=s.schema,l=ge(s,o),p=k=>{let g=c.graph.getNode(k);return g&&l.has(g.kind)?g:void 0},a=k=>({id:k.id,kind:k.kind,label:H(d,k)}),f=V(n),h=f.length===1?p(f[0]):void 0,b=h?Object.fromEntries(Object.keys(ue(d,h.kind)).filter(k=>!pe(d,h.kind).has(k)&&h[k]!==void 0&&k!=="label").map(k=>[k,h[k]])):{},P={on:n.on,...h?{record:{...a(h),fields:b}}:{},...n.on==="field"&&h?{field:n.field}:{},...n.on==="list"&&l.has(n.kind)?{kind:n.kind}:{},...n.on==="lens"?{place:n.place,...n.kind&&l.has(n.kind)?{kind:n.kind}:{}}:{},...n.on==="place"?{place:n.place}:{},...n.on==="act"?{act:n.act}:{}},S=[...new Set([...n.on==="selection"?n.ids:[],...t.selection??[]])].flatMap(k=>{let g=p(k);return g?[a(g)]:[]}),m=[];if(h){for(let k of Object.keys(K(d,h.kind)))for(let g of c.graph.out(h.id,k))p(g.id)&&m.push({...a(g),relation:k,direction:"out"});for(let k of d.kinds)for(let g of Object.keys(K(d,k)))for(let A of c.graph.in(h.id,g))A.kind===k&&p(A.id)&&m.push({...a(A),relation:g,direction:"in"})}let C=c.batches().filter(k=>!k.ops.every(Me)).slice(-(t.recent??6)).reverse().map(k=>({intent:k.intent,at:k.at,by:yn(k.author)}));return{...t.place!==void 0?{place:t.place}:{},target:P,selection:S,neighbors:m.slice(0,24),recent:C,schema:gn(s,o)}}function ee(e){if(!e.off)return e.fast??(e.decide?{model:e.name??"decide",decide:e.decide}:void 0)}function B(e){if(e.off)return;if(e.thinking)return e.thinking;let n=e.name??"model";if(e.complete){let t=e.complete;return{model:n,think:({system:i,prompt:o})=>t({prompt:o,system:i})}}if(e.turn){let t=e.turn;return{model:n,think:async({system:i,prompt:o})=>({text:await t({system:i,messages:[{role:"user",content:o}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Te=(e,n,t)=>e?n/1e6*(e.inputPerMillion??0)+t/1e6*(e.outputPerMillion??0):void 0,ve=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function hn(e,n,t=[]){let i=o=>{let s=e.graph.getNode(o);return s?ae(e.schema.tryDefinition(s.kind),s):"a record"};switch(n.on){case"record":return i(n.id);case"field":return`${i(n.id)} \xB7 ${n.field}`;case"selection":return`${n.ids.length} records`;case"list":return e.schema.tryDefinition(n.kind)?q(e.schema,n.kind):n.kind;case"lens":case"place":return t.find(o=>o.as===n.place)?.title??(n.place==="home"?"Home":n.place);case"act":return n.act}}var _e=e=>e.type!=="act"||e.asks.length===0,me=(e,n)=>({id:e.id,type:e.type,label:e.label,...n!==void 0?{confidence:n}:{}});function Q(e,n){let t=n.interaction??ve(),i=ye(n.store,n.target,{principal:n.principal,...n.acts?{acts:n.acts}:{},...n.places?{places:n.places}:{}}),o=qe(n.store,n.target,{principal:n.principal,...n.place?{place:n.place}:{},...n.selection?{selection:n.selection}:{}}),s=[];return{id:t,catalog:i,state:o,entry:{id:t,at:new Date().toISOString(),by:n.by??n.principal,target:n.target,targetLabel:hn(n.store,n.target,n.places)},usage:s,meter:c=>{s.push(c),e.meter?.({...c,interaction:t})}}}async function ne(e,n,t,i){let o=await e.decide(n,t),{inputTokens:s,outputTokens:c}=o.usage,d=Te(e.price,s,c);return i({tier:"fast",model:e.model,inputTokens:s,outputTokens:c,...d!==void 0?{costUsd:d}:{}}),o.answers}async function te(e,n,t,i,o){let s=await e.think({system:n,prompt:t,state:i.state,catalog:i.catalog}),c=s.usage?.inputTokens,d=s.usage?.outputTokens,l=s.usage?.costUsd??(c!==void 0?Te(e.price,c,d??0):void 0);return o({tier:"thinking",model:e.model,...c!==void 0?{inputTokens:c}:{},...d!==void 0?{outputTokens:d}:{},...l!==void 0?{costUsd:l}:{}}),Be(s.text)}function ie(e,n){let t=new Map(e.map((i,o)=>[`c${o+1}`,i]));return{question:{type:"choice",instructions:n,criteria:Object.fromEntries([...t].map(([i,o])=>[i,`${o.label} \u2014 ${o.description}`]))},of:i=>t.get(i)}}function oe(e,n,t){if(e?.type!=="choice")return[];let i=e,o=Object.entries(i.probabilities).sort((s,c)=>c[1]-s[1]);return o.some(([s])=>s===i.choice)||o.unshift([i.choice,i.confidence]),o.flatMap(([s,c])=>{let d=n(s);return d?[{candidate:d,confidence:c}]:[]}).slice(0,t)}var E=(e,n,t,i)=>({interaction:{...e.entry,ask:{kind:t,said:n??""},offered:[],outcome:"failed",failed:i,usage:[...e.usage]},offers:[]}),Y="AI isn't on here.";async function Ke(e,n,t=3){let i=Q(e,n),o=n.said??"Suggest",s=i.catalog.candidates.filter(_e).slice(0,24);if(s.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let c=ee(e),d=B(e),l=[];try{if(c){let{question:p,of:a}=ie(s,"Which of these would the person most likely want to do next, here?"),f=await ne(c,{...i.state,candidates:s.map(h=>({id:h.id,type:h.type,says:h.description}))},{next:p},i.meter);l=oe(f.next,a,t)}else if(d){let p=await te(d,'You suggest what a person most likely wants to do next in an app. Answer only JSON: {"pick": [candidate ids, best first]}. Pick only ids from the candidates.',JSON.stringify({state:i.state,candidates:s.map(f=>({id:f.id,says:f.description}))}),i,i.meter);l=(Array.isArray(p?.pick)?p.pick.filter(f=>typeof f=="string"):[]).flatMap(f=>s.filter(h=>h.id===f)).slice(0,t).map(f=>({candidate:f}))}else return E(i,o,"suggest",Y)}catch(p){return E(i,o,"suggest",p instanceof Error?p.message:String(p))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:l.map(({candidate:p,confidence:a})=>me(p,a)),outcome:"offered",usage:[...i.usage]},offers:l.map(({candidate:p})=>p)}}var mn=e=>`several:${e}`;async function Fn(e,n,t=2){let i=Q(e,{...n,acts:[]}),o=n.said??"Suggest for the chosen",s=n.target.on==="selection"?n.target.ids.length:1,d=[...n.shared.map(a=>({type:"act",id:mn(a.id),label:a.label,description:`${a.label}, for all ${s} chosen`,mutation:a.mutation,args:a.args,asks:[]})),...i.catalog.candidates.filter(a=>a.type==="panel"||a.type==="place")].slice(0,24),l=ee(e);if(!l)return E(i,o,"suggest",Y);if(d.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let p;try{let{question:a,of:f}=ie(d,`Which of these would the person most likely want to do next with the ${s} records they chose together?`),h=await ne(l,{...i.state,candidates:d.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:a},i.meter);p=oe(h.next,f,t).filter((b,P)=>P===0||b.confidence>=kn)}catch(a){return E(i,o,"suggest",a instanceof Error?a.message:String(a))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:p.map(({candidate:a,confidence:f})=>me(a,f)),outcome:"offered",usage:[...i.usage]},offers:p.map(({candidate:a})=>a)}}var kn=.25;async function Ve(e,n){let t=Q(e,n),i=n.said??"Fill in",o=t.catalog.candidates.filter(f=>f.type==="fill"),s=new Map;for(let f of o)s.set(f.field,[...s.get(f.field)??[],f]);if(s.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let c=ee(e),d=B(e),l=[];try{if(c){let f=[...s].map(([b,P],S)=>({key:`f${S+1}`,field:b,...ie(P,`Which value fits "${b}" best for this record?`)})),h=await ne(c,t.state,Object.fromEntries(f.map(b=>[b.key,b.question])),t.meter);for(let b of f){let P=!bn(n.store,n.target,b.field)&&An(n.store,n.target,b.field)!=="one";l.push(...oe(h[b.key],b.of,P?3:1).filter((S,m)=>m===0||S.confidence>=.4))}}else if(d){let f=await te(d,`You fill in a record's fields in an app. Answer only JSON: {"fills": [candidate ids]}, at most one per field, only ids from the candidates.`,JSON.stringify({state:t.state,candidates:o.map(P=>({id:P.id,says:P.description}))}),t,t.meter),h=Array.isArray(f?.fills)?f.fills.filter(P=>typeof P=="string"):[],b=new Set;for(let P of h){let S=o.find(m=>m.id===P);S?.type==="fill"&&!b.has(S.field)&&(b.add(S.field),l.push({candidate:S}))}}else return E(t,i,"fill",Y)}catch(f){return E(t,i,"fill",f instanceof Error?f.message:String(f))}let p=t.usage.at(-1)?.model,a=se(n.store,{interaction:t.id,target:n.target,basis:i,...p?{model:p}:{},proposals:l.flatMap(({candidate:f,confidence:h})=>f.type==="fill"?[{id:f.id,label:f.label,said:f.description,call:f.call,record:f.record,field:f.field,...h!==void 0?{confidence:h}:{}}]:[])},n.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:a.proposals.map(f=>({id:f.id,type:"fill",label:f.label,...f.confidence!==void 0?{confidence:f.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...a.proposals.length>0?{ghost:a}:{}}}function bn(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0,s=(o?e.schema.tryDefinition(o)?.fields?.shape:void 0)??{};return t in s}function An(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0;return o?e.schema.tryDefinition(o)?.edges?.[t]?.cardinality:void 0}async function Qe(e,n){let t=Q(e,n),i=n.said??"Add one",o=new Set(n.store.allMutations().filter(a=>(a.creates??[]).length>0).map(a=>a.name)),s=t.catalog.candidates.filter(a=>a.type==="act"&&a.asks.length>0&&o.has(a.mutation));if(s.length===0)return E(t,i,"record","Nothing here makes a record.");let c=B(e);if(!c)return E(t,i,"record",Y);let d;try{let a=await te(c,'You propose one new record for an app by filling in an act. Answer only JSON: {"act": a candidate id, "args": {argument: value}}. Use only the candidates, and fill every argument the act asks for with a value that fits the state.',JSON.stringify({ask:i,state:t.state,candidates:s.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),f=s.find(b=>b.id===a?.act),h=typeof a?.args=="object"&&a.args!==null?a.args:{};f&&(d={act:f,args:Object.fromEntries(Object.entries(h).filter(([b])=>f.asks.includes(b)))})}catch(a){return E(t,i,"record",a instanceof Error?a.message:String(a))}if(!d)return E(t,i,"record","The model named no act this app has here.");let l=t.usage.at(-1)?.model,p=se(n.store,{interaction:t.id,target:n.target,basis:i,...l?{model:l}:{},proposals:[{id:d.act.id,label:d.act.label,said:d.act.description,call:{name:d.act.mutation,args:{...d.act.args,...d.args}}}]},n.principal);return p.proposals.length===0?E(t,i,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:i},offered:p.proposals.map(a=>({id:a.id,type:"act",label:a.said})),outcome:"offered",usage:[...t.usage]},offers:[d.act],ghost:p}}async function Ye(e,n){let t=Q(e,n),i=n.said??"Make a panel",o=t.catalog.candidates.filter(a=>a.type==="panel");if(o.length===0)return E(t,i,"panel","Nothing here can be drawn as a panel.");let s=ee(e),c=B(e),d;try{if(c){let a=await te(c,'You choose a panel to draw in an app. Answer only JSON: {"panel": a candidate id, "title": a short title}. Choose only among the candidates.',JSON.stringify({ask:i,state:t.state,candidates:o.map(h=>({id:h.id,says:h.description}))}),t,t.meter),f=o.find(h=>h.id===a?.panel);f&&(d={panel:f,...typeof a?.title=="string"&&a.title.trim()?{title:a.title.trim().slice(0,60)}:{}})}else if(s){let{question:a,of:f}=ie(o,`Which panel answers this best: ${i}`),h=oe((await ne(s,t.state,{panel:a},t.meter)).panel,f,1)[0];h?.candidate.type==="panel"&&(d={panel:h.candidate,confidence:h.confidence})}else return E(t,i,"panel",Y)}catch(a){return E(t,i,"panel",a instanceof Error?a.message:String(a))}if(!d)return E(t,i,"panel","The model named no panel this app can draw.");let l=d.title??d.panel.label,p={title:l,recipe:{...d.panel.panel,title:l}};return{interaction:{...t.entry,ask:{kind:"panel",said:i},offered:[me(d.panel,d.confidence)],outcome:"drawn",panel:p,usage:[...t.usage]},offers:[d.panel],panel:p}}function Sn(e){return e.off?void 0:e.answer}var wn=`You answer a person's question about what they are looking at in an app, from the state given and nothing else. Answer only JSON: {"answer": one to three short sentences, "pick": [candidate ids that act on the answer, best first, at most three]}. Pick only ids from the candidates, and none when nothing fits. Never say an id to the person.`;async function Jn(e,n){let t=Q(e,n),i=n.said.trim(),o=t.catalog.candidates.filter(m=>_e(m)||m.type==="panel"||m.type==="place"||m.type==="record").slice(0,32),s=Sn(e),c=B(e),d=ee(e),l="",p=[],a=m=>m.flatMap(C=>o.filter(k=>k.id===C)).slice(0,3).map(C=>({candidate:C}));try{if(s){let m=await s.answer({said:i,target:n.target,targetLabel:t.entry.targetLabel,state:t.state,catalog:{target:t.catalog.target,candidates:o},...n.follows?{follows:n.follows}:{}}),C=m.usage?.inputTokens,k=m.usage?.outputTokens,g=m.usage?.costUsd??(C!==void 0?Te(s.price,C,k??0):void 0);t.meter({tier:"thinking",model:s.model,...C!==void 0?{inputTokens:C}:{},...k!==void 0?{outputTokens:k}:{},...g!==void 0?{costUsd:g}:{}}),l=typeof m.text=="string"?m.text.trim():"",p=a(m.pick??[])}else if(c){let m=await te(c,wn,JSON.stringify({ask:i,about:t.entry.targetLabel,...n.follows?{follows:n.follows}:{},state:t.state,candidates:o.map(C=>({id:C.id,says:C.description}))}),t,t.meter);l=typeof m?.answer=="string"?m.answer.trim():"",p=a(Array.isArray(m?.pick)?m.pick:[])}else if(d&&o.length>0){let{question:m,of:C}=ie(o,`Which of these best answers, or acts on: ${i}`),k=await ne(d,{...t.state,asked:i,candidates:o.map(g=>({id:g.id,type:g.type,says:g.description}))},{answer:m},t.meter);p=oe(k.answer,C,3),l=p.length>0?`These fit \u201C${i}\u201D.`:""}else return E(t,i,"ask",Y)}catch(m){return E(t,i,"ask",m instanceof Error?m.message:String(m))}if(!l&&p.length===0)return E(t,i,"ask","The AI had no answer to that here.");let f=t.usage.at(-1)?.model,h=p.flatMap(({candidate:m,confidence:C})=>{let k=he(m);return k?[{...k,...C!==void 0?{confidence:C}:{}}]:[]}),b=h.length>0?se(n.store,{interaction:t.id,target:n.target,basis:i,...f?{model:f}:{},proposals:h},n.principal):void 0,P=p.map(({candidate:m})=>m).filter(m=>he(m)===void 0),S=[...P.map(m=>me(m,p.find(C=>C.candidate===m)?.confidence)),...(b?.proposals??[]).map(m=>({id:m.id,type:m.field!==void 0?"fill":"act",label:m.label,...m.confidence!==void 0?{confidence:m.confidence}:{}}))];return{interaction:{...t.entry,ask:{kind:"ask",said:i},offered:S,outcome:"offered",...l?{answer:l}:{},usage:[...t.usage]},offers:P,...b&&b.proposals.length>0?{ghost:b}:{},...l?{answer:l}:{}}}function se(e,n,t){let i=n.proposals.flatMap(o=>{try{let s=e.previewAll([o.call],{author:t}),c=s.ops.map(d=>d.intent).join("; ");return s.ops.length>0?[{...o,said:c||o.said}]:[]}catch{return[]}});return{...n,proposals:i}}function he(e){if(e.type==="fill")return{id:e.id,label:e.label,said:e.description,call:e.call,record:e.record,field:e.field};if(e.type==="act"&&e.asks.length===0)return{id:e.id,label:e.label,said:e.description,call:{name:e.mutation,args:{...e.args}}}}function Xe(e,n,t){let i=n.proposals.filter(s=>t.ids===void 0||t.ids.includes(s.id));if(i.length===0)return{ok:!1,refused:"Nothing was chosen."};let o=i.flatMap(s=>s.confidence===void 0?[]:[s.confidence]);try{let c=e.applyAll(i.map(d=>d.call),{author:t.author,via:`ai:${n.interaction}`,intent:n.basis,lineage:{basis:`Asked \u201C${n.basis}\u201D`,...n.model?{model:n.model}:{},...o.length>0?{confidence:Math.min(...o)}:{},interaction:n.interaction}}).ops[0]?.batch;return c?{ok:!0,batch:c,accepted:i.map(d=>d.id)}:{ok:!1,refused:"That changes nothing now."}}catch(s){return{ok:!1,refused:s instanceof Error?s.message:String(s)}}}function Ze(e,n,t){let i=e.ask.kind==="suggest"?n.length>0:e.offered.length>0&&e.offered.every(o=>n.includes(o.id));return{...e,outcome:i?"accepted":"partly",accepted:n,batches:[...e.batches??[],t]}}var en=e=>({...e,outcome:"dismissed"});var I=Se(ln(),1);var x=Se(Fe(),1);function tn(e,n,t){let i=n.on==="selection"?n.ids:n.on==="record"||n.on==="field"?[n.id]:[],o=i.length>0?Ue(e.store,i,{principal:e.principal,...i.length===1?{focus:i[0]}:{}}).affordances.map(s=>({mutation:s.mutation,label:s.label,args:s.args,open:s.open,why:s.why,...s.destructive?{destructive:!0}:{}})):void 0;return{store:e.store,target:n,principal:e.principal,interaction:ve(),places:e.places,selection:e.selection,...o?{acts:o}:{},...e.place?{place:e.place}:{},...t?{said:t}:{}}}async function on(e,n,t){let i=await (__graviewPreload(import.meta.url,["./chunk.7R6GXJS4.js","./chunk.G4JJXA63.js","./chunk.MSPRCR3Q.js","./chunk.CSA6SWTI.js","./chunk.3FUFVVR4.js","./chunk.XOZU4OFA.js","./chunk.IYVBJDR7.js","./chunk.Q5WEOX3Q.js","./chunk.P2W727C7.js","./chunk.XXCT6DLX.js","./chunk.TXEWSZGO.js","./chunk.WVUJXDXZ.js","./chunk.VTCPA4V4.js","./chunk.FGJM4LJO.js","./chunk.K7WME4P4.js","./chunk.MDIAWTNK.js","./chunk.PEA4D66Y.js","./chunk.TRPPN2GD.js","./chunk.MT45H2T5.js","./chunk.S2ATSY6P.js","./chunk.72Q4R7N6.js","./chunk.6W2DUW5S.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.4QVZXCV5.js")),o=i.recipeDraft(n.recipe,{app:e.app,sight:i.draftSight(e.app,e.principal)});if(i.isDraftFailure(o))return o.failed;t?.(),e.seatTalk.setDraft(o,null),e.goTo.draft?.(),sn()}function sn(e=180){if(typeof document>"u")return;let n=document.querySelector('[data-testid="draft-keep"]'),t=document.activeElement,i=!t||t===document.body||t.closest?.("[inert]")!==null;if(n){i&&n.focus();return}e>0&&requestAnimationFrame(()=>sn(e-1))}async function re(e,n,t,i,o){let s=tn(e,t,i),c=n==="suggest"?await Ke(e.ai,s):n==="fill"?await Ve(e.ai,s):n==="record"?await Qe(e.ai,s):await Ye(e.ai,s);if(c.interaction.outcome==="failed")return n!=="suggest"&&e.desk.record(c.interaction),c;let d=l=>{let p={...c.interaction,outcome:"failed",failed:l};return e.desk.record(p),{...c,interaction:p}};if(n==="fill"||n==="record"){if(!c.ghost||c.ghost.proposals.length===0)return d("Nothing here could be filled in.");o?.(),e.desk.setGhost({ghost:c.ghost}),e.desk.record(c.interaction)}if(n==="panel"&&c.panel){let l=await on(e,c.panel,o);if(l)return d(l);e.desk.record(c.interaction)}return c}var Ie=new WeakMap,xn=64,nn=new WeakMap;function On(e){let n=nn.get(e);if(!n){let t=n={n:0};nn.set(e,t),e.subscribe(()=>void(t.n+=1))}return n.n}var rn=(e,n)=>{let t=V(n);return t.length>0?t.map(i=>e.graph.getNode(i)):[On(e)]},an=(e,n,t)=>JSON.stringify({target:n,seat:e.principal,by:t}),dn=(e,n,t)=>{let i=rn(e.store,n);return t.schema===e.store.schema&&t.ai===e.ai&&i.length===t.depends.length&&i.every((o,s)=>o===t.depends[s])};function Cn(e,n,t="menu"){let i=Ie.get(e.store)?.get(an(e,n,t));return i?.result!==void 0&&dn(e,n,i)?i.result:void 0}function $n(e,n,t){let i=Ie.get(e.store);i||Ie.set(e.store,i=new Map);let o=an(e,n,t?.by??"menu"),s=i.get(o);if(s&&dn(e,n,s))return s.result?Promise.resolve(s.result):s.asked;let c=t?t.ask():re(e,"suggest",n),d={schema:e.store.schema,ai:e.ai,depends:rn(e.store,n),asked:c};i.delete(o),i.set(o,d),i.size>xn&&i.delete(i.keys().next().value);let l=i;return c.then(p=>{p.interaction.outcome!=="failed"?d.result=p:l.get(o)===d&&l.delete(o)}),c}async function Pn(e,n,t,i){let o=n.interaction,s=he(t);if(s){let c=o.usage?.at(-1)?.model,d=o.offered.find(p=>p.id===t.id)?.confidence,l=se(e.store,{interaction:o.id,target:o.target,basis:`${o.ask.said}: ${t.label}`,...c?{model:c}:{},proposals:[{...s,...d!==void 0?{confidence:d}:{}}]},e.principal);if(l.proposals.length===0){let p="That can't be done now.";return e.desk.record({...o,outcome:"failed",failed:p}),p}i?.(),e.desk.setGhost({ghost:l}),e.desk.record(o);return}if(t.type==="panel"){let c=t.label,d={title:c,recipe:{...t.panel,title:c}},l=await on(e,d,i);return e.desk.record(l?{...o,outcome:"failed",failed:l}:{...o,outcome:"drawn",accepted:[t.id],panel:d}),l}i?.(),t.type==="place"?e.goTo.place(t.place):t.type==="record"&&e.goTo.record(t.record),e.desk.record({...o,outcome:"accepted",accepted:[t.id]})}async function Yn(e,n){if(n.ask.kind==="ask")return ce(e.desk,{target:n.target,asked:n.ask.said}),null;let t=n.ask.kind==="panel"||n.ask.kind==="record"?n.ask.kind:"fill";return re(e,t,n.target,n.ask.said)}var G={padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left",borderWidth:1,borderStyle:"solid",borderColor:"transparent",background:"none",boxShadow:"none"},ke={margin:0,padding:"4px 10px",fontSize:"0.8125rem",color:"var(--graview-ink-muted)"};function Xn({target:e,close:n}){let t=We(),i=(0,I.useMemo)(()=>Ge(e,u=>t.store.graph.has(u)),[e,t.store]),o=(0,I.useMemo)(()=>{let u=tn(t,i);return ye(t.store,i,{principal:t.principal,places:t.places,...u.acts?{acts:u.acts}:{}})},[t,i]),s=o.candidates.some(u=>u.type==="fill"),c=o.candidates.some(u=>u.type==="panel"),d=(0,I.useMemo)(()=>c?ze(t.store,i,{principal:t.principal,places:t.places,most:1}):[],[c,t,i]),l=(0,I.useMemo)(()=>new Set(t.store.allMutations().filter(u=>(u.creates??[]).length>0).map(u=>u.name)),[t.store]),p=B(t.ai)!==void 0&&o.candidates.some(u=>u.type==="act"&&u.asks.length>0&&l.has(u.mutation)),a=we(t.ai),f=Cn(t,i),h=JSON.stringify(i),[b,P]=(0,I.useState)(!1),[S,m]=(0,I.useState)(null),[C,k]=(0,I.useState)(a&&f===void 0);(0,I.useEffect)(()=>{if(f!==void 0||!(a||b))return;let u=!0;return k(!0),$n(t,i).then(O=>{u&&(m(O),k(!1))}),()=>{u=!1}},[h,b]);let g=f??S,A=(g?.offers??[]).filter(u=>!(u.type==="place"&&d.some(O=>O.place===u.place))).slice(0,Math.max(0,3-d.length)),w=g?.interaction.outcome==="failed"?g.interaction.failed??"The AI could not suggest anything here.":null,M=(0,I.useRef)(!1),L=(0,I.useRef)(null);(0,I.useLayoutEffect)(()=>{g===null||!M.current||(M.current=!1,L.current?.querySelector("button")?.focus())},[g]);let J=(0,I.useRef)(!0);(0,I.useEffect)(()=>()=>{J.current=!1},[]);let[F,r]=(0,I.useState)(!1),[y,T]=(0,I.useState)(null),v=u=>{if(F)return;r(!0),T(null);let O=!1;u(()=>{O=!0,n()}).then(D=>{J.current&&(r(!1),D?T(D):O||n())},D=>{J.current&&(r(!1),T(D instanceof Error?D.message:String(D)))})},$=u=>u.interaction.outcome==="failed"?u.interaction.failed??"The AI could not do that here.":void 0;return(0,x.jsxs)("div",{ref:L,"data-testid":"inline-ai",style:{display:"grid",gap:2},children:[C&&!b?(0,x.jsx)("p",{role:"status","data-testid":"inline-ai-thinking",style:ke,children:"Thinking\u2026"}):F?(0,x.jsx)("p",{role:"status","data-testid":"inline-ai-asking",style:ke,children:"Asking\u2026"}):y?(0,x.jsx)("p",{role:"alert","data-testid":"inline-ai-failed",style:{...ke,color:"var(--graview-warn)"},children:y}):w?(0,x.jsx)("p",{role:"status",style:ke,children:w}):null,(0,x.jsxs)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:2},children:[A.map(u=>(0,x.jsx)("li",{children:(0,x.jsxs)("button",{type:"button","data-menu-item":`ai-offer:${u.id}`,"data-ai-offer":u.id,"data-ai-offer-type":u.type,onClick:()=>v(O=>Pn(t,g,u,O)),style:G,children:[u.label,(0,x.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[" \xB7 ",u.type==="panel"?"a panel":u.type==="place"?"go there":u.type==="record"?"open it":"suggested"]})]})},u.id)),!a&&g===null?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-suggest","aria-disabled":b||void 0,onClick:u=>{b||(M.current=document.activeElement===u.currentTarget,P(!0))},style:G,children:b?"Thinking\u2026":"Suggest\u2026"})}):null,s?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-fill",onClick:()=>v(async u=>$(await re(t,"fill",i,"Fill in",u))),style:G,children:"Fill in with AI"})}):null,p?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-record",onClick:()=>v(async u=>$(await re(t,"record",i,"Add one",u))),style:G,children:"Add one with AI"})}):null,d.map(u=>(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":`ai-open:${u.place}`,"data-ai-existing":u.fit,onClick:()=>{n(),t.goTo.place(u.place),u.fit==="partial"&&ce(t.desk,{target:{on:"lens",place:u.place,...u.kind?{kind:u.kind}:{}}})},style:G,children:u.fit==="full"?`Open ${u.title}`:`Open and adjust ${u.title}`})},u.place)),c?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-panel",onClick:()=>v(async u=>$(await re(t,"panel",i,"Draw a panel",u))),style:G,children:d.length>0?"Draw a new view":"Draw a panel"})}):null,(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-ask",onClick:()=>{let u=document.activeElement;n(),ce(t.desk,{target:i,returnTo:u instanceof HTMLElement&&u!==document.body?u:null})},style:G,children:"Ask about this\u2026"})})]})]})}var be={display:"inline-flex",alignItems:"center",minHeight:28,padding:"2px 10px",fontSize:"0.8125rem",borderRadius:8};function Zn({placement:e="picture"}){let{store:n,principal:t,aiDesk:i}=Je(),o=Le(n,t),{ghost:s,entries:c}=He(i),[d,l]=(0,I.useState)(new Set);(0,I.useEffect)(()=>l(new Set),[s?.ghost.interaction]);let p=(0,I.useRef)(null),a=(0,I.useRef)(null),f=s?.batch;if((0,I.useEffect)(()=>{f!==void 0&&a.current?.focus()},[f]),!s)return null;let{ghost:h}=s,b=c.find(g=>g.id===h.interaction),P=()=>{let g=h.target.on==="record"||h.target.on==="field"?h.target.id:void 0,A=p.current?.closest("[data-graview-face], main")?.parentElement??document,w=(g?A.querySelector(`[data-graview-view="${CSS.escape(g)}"][tabindex]`):null)??document.querySelector("[data-graview-page-title]")??p.current?.closest("main")??document.querySelector("main");w&&!w.hasAttribute("tabindex")&&w.setAttribute("tabindex","-1"),w?.focus({preventScroll:!0}),i.setGhost(null)},S=h.proposals.filter(g=>!d.has(g.id)).map(g=>g.id),m=()=>{let g=Xe(o,h,{author:t,ids:S});if(!g.ok){i.setGhost({...s,refused:g.refused});return}b&&i.record(Ze(b,g.accepted,g.batch)),i.setGhost({ghost:h,batch:g.batch,took:g.accepted.length,...s.onCard?{onCard:!0}:{}})},C=()=>{b&&s.batch===void 0&&i.record(en(b)),P()},k=()=>{if(s.batch!==void 0)try{o.undo(s.batch,{author:t}),P()}catch(g){i.setGhost({...s,refused:g instanceof Error?g.message:String(g)})}};return(0,x.jsxs)("section",{ref:p,"data-testid":"ai-ghost","data-interaction":h.interaction,"aria-label":"Proposed by AI",style:{...e==="card"?{position:"static"}:{position:e==="page"?"fixed":"absolute",insetInline:"max(12px, calc(50% - 220px))",bottom:"calc(var(--graview-foot-room, 0px) + 72px)",zIndex:De("toast"),boxShadow:"var(--graview-lift-high)"},display:"grid",gap:8,padding:12,borderRadius:12,border:"1px dashed var(--graview-accent)",background:"var(--graview-float)",fontSize:"0.875rem"},children:[(0,x.jsx)("p",{style:{margin:0,color:"var(--graview-ink-muted)"},children:s.batch!==void 0?`Done: ${s.took===1?"one change":`${s.took} changes`}, as one.`:`Proposed by AI \xB7 ${h.basis}`}),s.batch===void 0?(0,x.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:4},children:h.proposals.map(g=>(0,x.jsx)("li",{"data-ghost-proposal":g.id,children:(0,x.jsxs)("label",{style:{display:"flex",alignItems:"baseline",gap:8,cursor:"pointer"},children:[(0,x.jsx)("input",{type:"checkbox",checked:!d.has(g.id),onChange:A=>{let w=new Set(d);A.target.checked?w.delete(g.id):w.add(g.id),l(w)}}),(0,x.jsx)("span",{style:{fontStyle:"italic",color:"var(--graview-ink)"},children:g.said}),g.confidence!==void 0?(0,x.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[Math.round(g.confidence*100),"% sure"]}):null]})},g.id))}):null,s.refused?(0,x.jsx)("p",{role:"alert",style:{margin:0,color:"var(--graview-warn)"},children:s.refused}):null,(0,x.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:s.batch===void 0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("button",{type:"button","data-testid":"ghost-accept",disabled:S.length===0,onClick:m,style:be,children:S.length===h.proposals.length?"Accept":`Accept ${S.length} of ${h.proposals.length}`}),(0,x.jsx)("button",{type:"button","data-testid":"ghost-dismiss",onClick:C,style:be,children:"Dismiss"})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("button",{type:"button",ref:a,"data-testid":"ghost-undo",onClick:k,style:be,children:"Undo"}),(0,x.jsx)("button",{type:"button","data-testid":"ghost-close",onClick:P,style:be,children:"Close"})]})})]})}export{Ge as a,V as b,ye as c,ze as d,ee as e,ve as f,hn as g,mn as h,Fn as i,Jn as j,tn as k,on as l,re as m,Cn as n,$n as o,Pn as p,Yn as q,Xn as r,Zn as s};