graview 0.1.52 → 0.1.53

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 (210) hide show
  1. package/dist/preview/chunk.2IKVO743.js +1 -0
  2. package/dist/preview/{chunk.C4EPMV7O.js → chunk.2LQ37DC2.js} +1 -1
  3. package/dist/preview/{chunk.IVI3HRSF.js → chunk.3377DLPA.js} +1 -1
  4. package/dist/preview/chunk.34Q7OKK3.js +1 -0
  5. package/dist/preview/{chunk.3FKP32RG.js → chunk.36XV4ZMC.js} +2 -2
  6. package/dist/preview/{chunk.LESRQN3Y.js → chunk.3FRVG6JW.js} +1 -1
  7. package/dist/preview/{chunk.XLM4ONUB.js → chunk.3FUFVVR4.js} +1 -1
  8. package/dist/preview/chunk.3Y7BDRP3.js +1 -0
  9. package/dist/preview/{chunk.7FZY5E2U.js → chunk.4DCPB67O.js} +1 -1
  10. package/dist/preview/chunk.4DFO43VM.js +1 -0
  11. package/dist/preview/chunk.4QVZXCV5.js +1 -0
  12. package/dist/preview/chunk.4SVAHPJA.js +1 -0
  13. package/dist/preview/chunk.52Y37IAD.js +1 -0
  14. package/dist/preview/chunk.56UFDIX5.js +1 -0
  15. package/dist/preview/chunk.5E4UGVAD.js +1 -0
  16. package/dist/preview/chunk.5H3VCAPN.js +1 -0
  17. package/dist/preview/chunk.5K5D4IMM.js +1 -0
  18. package/dist/preview/{chunk.C4UNAJWC.js → chunk.5XFRWXYQ.js} +1 -1
  19. package/dist/preview/{chunk.ULAMIQ52.js → chunk.65F3DF5Q.js} +1 -1
  20. package/dist/preview/{chunk.QWQBPJ4U.js → chunk.6CVW53WA.js} +1 -1
  21. package/dist/preview/chunk.6ESAZJBN.js +1 -0
  22. package/dist/preview/chunk.6S3B4XC4.js +1 -0
  23. package/dist/preview/{chunk.VOHRQXCF.js → chunk.6W2DUW5S.js} +2 -2
  24. package/dist/preview/{chunk.7EA7THSM.js → chunk.72Q4R7N6.js} +1 -1
  25. package/dist/preview/chunk.7BXOQEUP.js +1 -0
  26. package/dist/preview/{chunk.7UJZP3YK.js → chunk.7NFCI4LH.js} +2 -2
  27. package/dist/preview/{chunk.4LI73QOY.js → chunk.7R6GXJS4.js} +1 -1
  28. package/dist/preview/chunk.A2RQFAZ6.js +1 -0
  29. package/dist/preview/{chunk.J2R55TM7.js → chunk.AQJD23AN.js} +1 -1
  30. package/dist/preview/{chunk.7XJ3XQZD.js → chunk.ASCTAUFD.js} +1 -1
  31. package/dist/preview/chunk.B3T4N2XM.js +25 -0
  32. package/dist/preview/chunk.B3WVCSW5.js +1 -0
  33. package/dist/preview/{chunk.NAPTE3S6.js → chunk.BB5XKTVC.js} +1 -1
  34. package/dist/preview/{chunk.Y37DXEHG.js → chunk.BG2SC77J.js} +1 -1
  35. package/dist/preview/{chunk.7UXDIEPK.js → chunk.BPPDBPTL.js} +1 -1
  36. package/dist/preview/chunk.BQHRZJ5Z.js +1 -0
  37. package/dist/preview/{chunk.BJL6EL6B.js → chunk.CANTHIRO.js} +1 -1
  38. package/dist/preview/chunk.CIUQWCU4.js +1 -0
  39. package/dist/preview/{chunk.SZCZD2GM.js → chunk.CSA6SWTI.js} +1 -1
  40. package/dist/preview/{chunk.52J42KR5.js → chunk.CWPRQSED.js} +1 -1
  41. package/dist/preview/{chunk.5DDHFNZM.js → chunk.CYP5KXIQ.js} +1 -1
  42. package/dist/preview/chunk.D3A24PQ6.js +1 -0
  43. package/dist/preview/{chunk.CBGKWYGI.js → chunk.DQPEVPKQ.js} +1 -1
  44. package/dist/preview/{chunk.R7ZZJOJW.js → chunk.DUZS52WX.js} +1 -1
  45. package/dist/preview/chunk.E52UTLQ2.js +1 -0
  46. package/dist/preview/{chunk.QPP3OJVR.js → chunk.E647LWH5.js} +1 -1
  47. package/dist/preview/chunk.EG2N5F6L.js +1 -0
  48. package/dist/preview/{chunk.T2Q3AAQI.js → chunk.EZXGVTT2.js} +1 -1
  49. package/dist/preview/chunk.F5RN6YXG.js +4 -0
  50. package/dist/preview/chunk.FBRARPGR.js +4 -0
  51. package/dist/preview/{chunk.J263VQF5.js → chunk.FCAKLO5U.js} +1 -1
  52. package/dist/preview/{chunk.3TME4BG3.js → chunk.FGJM4LJO.js} +1 -1
  53. package/dist/preview/{chunk.OS3WZV6C.js → chunk.FJN4OGAS.js} +1 -1
  54. package/dist/preview/chunk.FXNUR5JI.js +88 -0
  55. package/dist/preview/chunk.G226CUJQ.js +1 -0
  56. package/dist/preview/chunk.G6DISMVT.js +67 -0
  57. package/dist/preview/{chunk.LTJYKQJG.js → chunk.GANAZIRD.js} +1 -1
  58. package/dist/preview/{chunk.KFTZLNHY.js → chunk.GBIVIHGD.js} +19 -14
  59. package/dist/preview/chunk.GGHZEAAT.js +1 -0
  60. package/dist/preview/chunk.GPYZR6HE.js +1 -0
  61. package/dist/preview/{chunk.7KZ44FEU.js → chunk.GYO57LKD.js} +1 -1
  62. package/dist/preview/{chunk.NHIPVAGR.js → chunk.GZBODS7Z.js} +1 -1
  63. package/dist/preview/chunk.GZWC72HS.js +1 -0
  64. package/dist/preview/{chunk.FJEXINFF.js → chunk.H2B3SEI7.js} +1 -1
  65. package/dist/preview/{chunk.R6FHEEJ7.js → chunk.H6EMDQP5.js} +1 -1
  66. package/dist/preview/chunk.HAIHXBVX.js +1 -0
  67. package/dist/preview/{chunk.BHPZK4WJ.js → chunk.HBVURYWY.js} +2 -2
  68. package/dist/preview/{chunk.VKOCD5CL.js → chunk.HDXDYS4C.js} +1 -1
  69. package/dist/preview/chunk.HE545Z6I.js +1 -0
  70. package/dist/preview/chunk.HIDLE6BN.js +18 -0
  71. package/dist/preview/chunk.HIFLBWQJ.js +9 -0
  72. package/dist/preview/chunk.I62MCBQM.js +1 -0
  73. package/dist/preview/chunk.I6SUHXJF.js +1 -0
  74. package/dist/preview/chunk.I6W3IQ4W.js +1 -0
  75. package/dist/preview/chunk.ICYJ7QJG.js +2 -0
  76. package/dist/preview/{chunk.C7EEYSAM.js → chunk.IYVBJDR7.js} +1 -1
  77. package/dist/preview/{chunk.RWCWRJJC.js → chunk.J6OT74RM.js} +1 -1
  78. package/dist/preview/{chunk.GZHEGKPF.js → chunk.JCJ7NTW4.js} +1 -1
  79. package/dist/preview/{chunk.P5PXWOHI.js → chunk.JKCLYLT4.js} +1 -1
  80. package/dist/preview/chunk.JQTO52Q7.js +1 -0
  81. package/dist/preview/chunk.JRU5BT7K.js +5 -0
  82. package/dist/preview/{chunk.I43ONAEL.js → chunk.K7WME4P4.js} +1 -1
  83. package/dist/preview/{chunk.FLNYLE6S.js → chunk.KAKJYAHM.js} +1 -1
  84. package/dist/preview/chunk.KCM2VOC7.js +1 -0
  85. package/dist/preview/{chunk.LSL25VXW.js → chunk.KWMBRB6O.js} +1 -1
  86. package/dist/preview/{chunk.KVEDMKUN.js → chunk.KY7QD22S.js} +1 -1
  87. package/dist/preview/{chunk.RBWYXVUW.js → chunk.LAOZEYYQ.js} +1 -1
  88. package/dist/preview/{chunk.JQBP6QWQ.js → chunk.LCG3VLCB.js} +1 -1
  89. package/dist/preview/{chunk.7FMS57QO.js → chunk.LDLWYAHK.js} +1 -1
  90. package/dist/preview/chunk.LEKML4S4.js +1 -0
  91. package/dist/preview/{chunk.73EKJ4JN.js → chunk.MDIAWTNK.js} +1 -1
  92. package/dist/preview/chunk.MKWVNW4Q.js +35 -0
  93. package/dist/preview/{chunk.VGTEEANA.js → chunk.MSPRCR3Q.js} +1 -1
  94. package/dist/preview/{chunk.CV4QA4ZF.js → chunk.MT45H2T5.js} +1 -1
  95. package/dist/preview/chunk.MXTDQXVW.js +1 -0
  96. package/dist/preview/{chunk.M33LUF3Q.js → chunk.N6A3DIOY.js} +1 -1
  97. package/dist/preview/{chunk.DXZ5VYCQ.js → chunk.NAEEPUWJ.js} +1 -1
  98. package/dist/preview/{chunk.HSGUXMAO.js → chunk.NCTTPW7A.js} +1 -1
  99. package/dist/preview/chunk.OCWZJNZF.js +1 -0
  100. package/dist/preview/chunk.OP3ZUI4W.js +1 -0
  101. package/dist/preview/{chunk.J6IB2HUZ.js → chunk.OPKXCL5R.js} +1 -1
  102. package/dist/preview/chunk.OXLYDXQV.js +1 -0
  103. package/dist/preview/{chunk.DGWNVDZB.js → chunk.OZYZBRWO.js} +1 -1
  104. package/dist/preview/{chunk.CHMUL36A.js → chunk.P2W727C7.js} +1 -1
  105. package/dist/preview/{chunk.I2W7HSBU.js → chunk.P7FN3SFB.js} +1 -1
  106. package/dist/preview/{chunk.INL4OZI7.js → chunk.PEA4D66Y.js} +1 -1
  107. package/dist/preview/chunk.Q5JVKSEN.js +1 -0
  108. package/dist/preview/chunk.QATG5HNV.js +1 -0
  109. package/dist/preview/{chunk.KPUX27ZT.js → chunk.R3DWF35R.js} +1 -1
  110. package/dist/preview/{chunk.XZLKTOJE.js → chunk.RIS3OKAI.js} +1 -1
  111. package/dist/preview/{chunk.R77TACXU.js → chunk.RUTZEEBR.js} +1 -1
  112. package/dist/preview/{chunk.OYRZ2DEI.js → chunk.S2ATSY6P.js} +1 -1
  113. package/dist/preview/{chunk.NB6WN4DO.js → chunk.S6TN3MLY.js} +1 -1
  114. package/dist/preview/{chunk.FJC6PMOG.js → chunk.T56SOSIR.js} +4 -4
  115. package/dist/preview/chunk.THL67D77.js +1 -0
  116. package/dist/preview/{chunk.GL3YVGAP.js → chunk.TLQTDKOL.js} +2 -2
  117. package/dist/preview/{chunk.5WU2UTP7.js → chunk.TRPPN2GD.js} +1 -1
  118. package/dist/preview/{chunk.YKACMLLU.js → chunk.TTFYXKLI.js} +1 -1
  119. package/dist/preview/{chunk.FEBCIEI3.js → chunk.TXEWSZGO.js} +1 -1
  120. package/dist/preview/chunk.U4T4Y2MT.js +1 -0
  121. package/dist/preview/chunk.ULTYDYTS.js +19 -0
  122. package/dist/preview/chunk.UQ4CASST.js +1 -0
  123. package/dist/preview/chunk.UQENE3VE.js +1 -0
  124. package/dist/preview/chunk.USAGE5C6.js +28 -0
  125. package/dist/preview/{chunk.ZK42LPF5.js → chunk.UVMLX4US.js} +1 -1
  126. package/dist/preview/{chunk.G7XKQNOL.js → chunk.UXNZPPWR.js} +1 -1
  127. package/dist/preview/chunk.UYCPQ6IW.js +1 -0
  128. package/dist/preview/chunk.V6X3U3JF.js +1 -0
  129. package/dist/preview/{chunk.2K3YQJW3.js → chunk.VOHDRH3P.js} +1 -1
  130. package/dist/preview/{chunk.R7CRV2FE.js → chunk.VRJ4TULC.js} +1 -1
  131. package/dist/preview/{chunk.QRCTTDDQ.js → chunk.VTCPA4V4.js} +1 -1
  132. package/dist/preview/chunk.VTRI2MT2.js +2 -0
  133. package/dist/preview/chunk.W54NXXC5.js +293 -0
  134. package/dist/preview/{chunk.NVNQSZ43.js → chunk.WDEMPWS4.js} +1 -1
  135. package/dist/preview/chunk.XBNASVTY.js +1 -0
  136. package/dist/preview/{chunk.EIWTZC4A.js → chunk.XDEKL6TJ.js} +1 -1
  137. package/dist/preview/chunk.XE72DFBV.js +13 -0
  138. package/dist/preview/{chunk.N7D5LKBI.js → chunk.XFIZLWYA.js} +1 -1
  139. package/dist/preview/{chunk.U6PCKJ26.js → chunk.XXCT6DLX.js} +1 -1
  140. package/dist/preview/{chunk.7354O67H.js → chunk.Y4VOCJ7R.js} +1 -1
  141. package/dist/preview/chunk.YA7ZMGOL.js +1 -0
  142. package/dist/preview/{chunk.D62V3TBW.js → chunk.YI7WHBAD.js} +2 -2
  143. package/dist/preview/{chunk.6CY3EA6U.js → chunk.Z4YSCHZT.js} +1 -1
  144. package/dist/preview/{chunk.MBNZ2HK7.js → chunk.ZQWKS6K5.js} +1 -1
  145. package/dist/preview/{chunk.7IOC6U3C.js → chunk.ZYYM52N5.js} +1 -1
  146. package/dist/preview/index.html +50 -50
  147. package/dist/preview/page.js +2 -2
  148. package/package.json +6 -6
  149. package/dist/preview/chunk.2EB7COX5.js +0 -1
  150. package/dist/preview/chunk.2X3UZJWI.js +0 -1
  151. package/dist/preview/chunk.337JMOTL.js +0 -1
  152. package/dist/preview/chunk.3ZQAPPJ5.js +0 -18
  153. package/dist/preview/chunk.4VI3EYDL.js +0 -1
  154. package/dist/preview/chunk.4ZLCMATU.js +0 -2
  155. package/dist/preview/chunk.5LWPNOJA.js +0 -1
  156. package/dist/preview/chunk.63SRVTG2.js +0 -19
  157. package/dist/preview/chunk.6BA6RUK7.js +0 -1
  158. package/dist/preview/chunk.6JERQFZI.js +0 -1
  159. package/dist/preview/chunk.6NIE3ILA.js +0 -1
  160. package/dist/preview/chunk.6QNBUBGD.js +0 -1
  161. package/dist/preview/chunk.7OAXW7QF.js +0 -1
  162. package/dist/preview/chunk.7SNIX56B.js +0 -1
  163. package/dist/preview/chunk.AI2HBKVP.js +0 -359
  164. package/dist/preview/chunk.BDQ4FUKO.js +0 -1
  165. package/dist/preview/chunk.BRDAO2OF.js +0 -4
  166. package/dist/preview/chunk.CC7E6NUQ.js +0 -1
  167. package/dist/preview/chunk.D2T563AA.js +0 -1
  168. package/dist/preview/chunk.DC7M56NM.js +0 -9
  169. package/dist/preview/chunk.DIS7JS7X.js +0 -1
  170. package/dist/preview/chunk.DVLWSCIC.js +0 -35
  171. package/dist/preview/chunk.EHOEMVQP.js +0 -1
  172. package/dist/preview/chunk.EME5HQ3H.js +0 -1
  173. package/dist/preview/chunk.G446PWV6.js +0 -1
  174. package/dist/preview/chunk.HST7BYFW.js +0 -1
  175. package/dist/preview/chunk.JOWJNIWH.js +0 -4
  176. package/dist/preview/chunk.JV7FLVUV.js +0 -1
  177. package/dist/preview/chunk.KQSD5MLY.js +0 -1
  178. package/dist/preview/chunk.KSJ3J5UN.js +0 -1
  179. package/dist/preview/chunk.LXJW2Z2M.js +0 -1
  180. package/dist/preview/chunk.MCFLCC42.js +0 -12
  181. package/dist/preview/chunk.MYKRJ4SV.js +0 -1
  182. package/dist/preview/chunk.NICCIJV4.js +0 -1
  183. package/dist/preview/chunk.NQPNK6I5.js +0 -1
  184. package/dist/preview/chunk.NWK4E7TJ.js +0 -1
  185. package/dist/preview/chunk.NZB5S5UO.js +0 -1
  186. package/dist/preview/chunk.PRCWGE7A.js +0 -1
  187. package/dist/preview/chunk.PXHBPLTQ.js +0 -1
  188. package/dist/preview/chunk.PXVJBL2C.js +0 -1
  189. package/dist/preview/chunk.Q3XKNZQW.js +0 -1
  190. package/dist/preview/chunk.Q5IAXTF5.js +0 -25
  191. package/dist/preview/chunk.QXCYAFRT.js +0 -1
  192. package/dist/preview/chunk.RMRO5JZX.js +0 -1
  193. package/dist/preview/chunk.S4ZWBCYC.js +0 -1
  194. package/dist/preview/chunk.SELLAVIQ.js +0 -1
  195. package/dist/preview/chunk.SM6HTPYF.js +0 -1
  196. package/dist/preview/chunk.T6KKNWZT.js +0 -1
  197. package/dist/preview/chunk.UEPVA6IS.js +0 -1
  198. package/dist/preview/chunk.UMS7XRPO.js +0 -1
  199. package/dist/preview/chunk.VGIWQNJB.js +0 -1
  200. package/dist/preview/chunk.W5UJLKIT.js +0 -1
  201. package/dist/preview/chunk.WUEU3QBL.js +0 -1
  202. package/dist/preview/chunk.WWUMSCYC.js +0 -1
  203. package/dist/preview/chunk.XPR3QFF4.js +0 -1
  204. package/dist/preview/chunk.YKXUDACI.js +0 -28
  205. package/dist/preview/chunk.YUEOUV7G.js +0 -5
  206. package/dist/preview/chunk.YYWLYVAW.js +0 -1
  207. package/dist/preview/chunk.Z2JMTRF4.js +0 -1
  208. package/dist/preview/chunk.Z2UFPOAN.js +0 -88
  209. package/dist/preview/chunk.ZEKKIMKI.js +0 -1
  210. package/dist/preview/chunk.ZZGXVYW2.js +0 -1
@@ -1,4 +1,4 @@
1
- import{a as Y,c as _,d as J,f as Q}from"./chunk.JV7FLVUV.js";import{a as Z,b as ee}from"./chunk.XOZU4OFA.js";import{b as U,c as X,d as ae}from"./chunk.C7EEYSAM.js";import{b as K,c as $,d as P,j as B,k as V}from"./chunk.CV4QA4ZF.js";import{b as z,k as j,l as G}from"./chunk.OYRZ2DEI.js";import{G as oe,T as H}from"./chunk.Q5IAXTF5.js";import{da as I,fa as F,ma as D}from"./chunk.VOHRQXCF.js";import{b as N}from"./chunk.AJZBJBMO.js";var c=N(oe(),1),a=N(H(),1),le=`
1
+ import{a as N,c as W,d as I,f as O}from"./chunk.52Y37IAD.js";import{a as Z,b as ee}from"./chunk.XOZU4OFA.js";import{b as U,c as X,d as ae}from"./chunk.IYVBJDR7.js";import{b as Y,c as _,d as L,j as J,k as Q}from"./chunk.MT45H2T5.js";import{b as $,k as B,l as V}from"./chunk.S2ATSY6P.js";import{G as oe,T as K}from"./chunk.B3T4N2XM.js";import{da as j,fa as F,ma as G}from"./chunk.6W2DUW5S.js";import{b as T}from"./chunk.AJZBJBMO.js";var c=T(oe(),1),a=T(K(),1),le=`
2
2
  form:where([data-graview-part="form"]) {
3
3
  /* A grid item of the section above it and a grid container for the
4
4
  fields below: both halves are allowed to be narrower than what is in
@@ -101,4 +101,4 @@ p:where([data-graview-part="refused"]) {
101
101
  color: var(--graview-warn);
102
102
  font-size: 0.875rem;
103
103
  }
104
- `;function de({title:r,name:e,optional:t,amount:o,value:h,onChange:v}){let s=K(o),[k,g]=(0,c.useState)(()=>typeof h=="number"?$(h,o):""),x=k.trim()!==""&&P(k,o)===void 0;return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"number","data-graview-amount":o.format??"unit",children:[(0,a.jsx)("span",{"data-graview-part":"label",children:r}),(0,a.jsxs)("span",{"data-graview-part":"amount",style:{display:"flex",alignItems:"center",gap:6},children:[s.prefix?(0,a.jsx)("span",{"data-graview-part":"amount-symbol","aria-hidden":"true",children:s.prefix}):null,(0,a.jsx)("input",{type:"text",inputMode:"decimal",name:e,required:!t,placeholder:s.placeholder,title:s.hint,"aria-invalid":x||void 0,value:k,onChange:p=>{g(p.target.value),v(P(p.target.value,o))},"data-graview-part":"control",style:{flex:1,minWidth:0}}),s.suffix?(0,a.jsx)("span",{"data-graview-part":"amount-symbol","aria-hidden":"true",children:s.suffix}):null]}),x?(0,a.jsxs)("span",{"data-graview-part":"hint",role:"status",children:["Not an amount ",s.hint,": write it like ",s.prefix??"",s.placeholder,s.suffix?` ${s.suffix}`:""]}):null]})}function te({children:r}){return(0,a.jsxs)("span",{"data-graview-part":"picker",children:[r,(0,a.jsx)("span",{"aria-hidden":"true","data-graview-part":"chevron",children:"\u25BE"})]})}var se=r=>({label:F(r),option:e=>e}),pe={phone:"+1 555 123 4567",place:"An address or a place's name",duration:"1h 30m, 90 or 1:30"};function T({store:r,spec:e,value:t,onChange:o,prefilled:h,open:v,words:s=se,values:k}){if(e.name in h&&e.control!=="group"&&e.control!=="variant")return null;let g=e.control==="node"&&!e.kinds.includes("*")?e.kinds.map(n=>F(D(r.schema.tryDefinition(n),n))).join(" or "):s(e.name).label,x=!(e.optional||e.control==="boolean"),p=x?(0,a.jsxs)(a.Fragment,{children:[g,(0,a.jsx)("span",{"aria-hidden":"true",children:" *"})]}):g;switch(e.control){case"text":case"date":return e.control==="text"&&e.long?(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"text",children:[(0,a.jsxs)("span",{"data-graview-part":"label",children:[p,e.markdown?(0,a.jsx)("span",{style:{fontWeight:"normal",color:"var(--graview-ink-faint)"},children:" \xB7 Markdown"}):null]}),(0,a.jsx)("textarea",{name:e.name,required:!e.optional,rows:6,value:typeof t=="string"?t:"",onChange:n=>o(n.target.value),"data-graview-part":"control",style:{fieldSizing:"content",minHeight:"7.5em",resize:"vertical",font:"inherit",lineHeight:1.5}})]}):e.control==="date"?(0,a.jsxs)("div",{"data-graview-part":"field","data-graview-field":"date",children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)(Q,{name:e.name,label:s(e.name).label,required:!e.optional,value:typeof t=="string"&&t!==""?t:void 0,time:e.time===!0,instant:e.instant===!0,onChange:o})]}):(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control==="text"&&e.holds?e.holds:e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)("input",{type:e.control==="text"&&e.holds==="phone"?"tel":"text",name:e.name,required:!e.optional,...e.control==="text"&&e.app?{placeholder:"@owner/app or https://\u2026"}:{},...e.control==="text"&&e.holds?{placeholder:pe[e.holds]}:{},...e.control==="text"&&e.holds==="phone"?{autoComplete:"tel"}:{},value:typeof t=="string"?t:typeof t=="number"?String(t):"",onChange:n=>o(n.target.value),"data-graview-part":"control"})]});case"number":return e.amount?(0,a.jsx)(de,{title:p,name:e.name,optional:e.optional,amount:e.amount,value:t,onChange:o}):(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)("input",{type:"number",name:e.name,required:!e.optional,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.step===void 0?{}:{step:e.step},value:typeof t=="number"?t:"",onChange:n=>o(n.target.value===""?void 0:Number(n.target.value)),"data-graview-part":"control"})]});case"boolean":return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"boolean",children:[(0,a.jsx)("input",{type:"checkbox",name:e.name,checked:t===!0,onChange:n=>o(n.target.checked),"data-graview-part":"control"}),(0,a.jsx)("span",{"data-graview-part":"label",children:p})]});case"choice":return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)(te,{children:(0,a.jsxs)("select",{name:e.name,required:!e.optional,value:typeof t=="string"?t:"",onChange:n=>o(n.target.value||void 0),"data-graview-part":"control",children:[(0,a.jsx)("option",{value:"",children:"\u2014"}),(e.options??[]).map(n=>(0,a.jsx)("option",{value:n,children:s(e.name).option(n)},n))]})})]});case"node":{let n=v.find(i=>i.name===e.name)?.candidates,m=new Set(Object.values(h).filter(i=>typeof i=="string")),f=(e.kinds.includes("*")?[...r.graph.allNodes()]:e.kinds.flatMap(i=>r.graph.nodesOfKind(i))).filter(i=>!m.has(i.id)),d=n?n.map(i=>r.graph.getNode(i)).filter(i=>i!==void 0):f,b=z(d,i=>r.schema.tryDefinition(i));return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)(te,{children:(0,a.jsxs)("select",{name:e.name,required:!e.optional,value:typeof t=="string"?t:"",onChange:i=>o(i.target.value||void 0),"data-graview-part":"control",children:[(0,a.jsx)("option",{value:"",children:"\u2014"}),d.map(i=>{let S=b.get(i.id);return(0,a.jsxs)("option",{value:i.id,children:[I(r.schema.tryDefinition(i.kind),i),S?` \xB7 ${S}`:""]},i.id)})]})})]})}case"group":{let n=t??{};return(0,a.jsxs)("fieldset",{"data-graview-part":"group","data-graview-field":e.control,children:[(0,a.jsx)("legend",{"data-graview-part":"label",children:p}),e.fields.map(m=>(0,a.jsx)(T,{store:r,spec:m,value:n[m.name],onChange:f=>o({...n,[m.name]:f}),prefilled:h,open:v,words:s},m.name))]})}case"variant":{let n=t??{},m=typeof n[e.tag]=="string"?n[e.tag]:"",f=e.options.find(d=>d.value===m);return(0,a.jsxs)("fieldset",{"data-graview-part":"group","data-graview-field":e.control,children:[(0,a.jsx)("legend",{"data-graview-part":"label",children:p}),(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"choice",children:[(0,a.jsx)("span",{"data-graview-part":"label",children:F(e.tag)}),(0,a.jsxs)("select",{value:m,onChange:d=>o({[e.tag]:d.target.value}),"data-graview-part":"control",children:[(0,a.jsx)("option",{value:"",children:"\u2014"}),e.options.map(d=>(0,a.jsx)("option",{value:d.value,children:F(d.value)},d.value))]})]}),f?.fields.map(d=>(0,a.jsx)(T,{store:r,spec:d,value:n[d.name],onChange:b=>o({...n,[d.name]:b}),prefilled:h,open:v,words:s},d.name))]})}case"file":case"list":{let n=e.control==="file"?e:e.item.control==="file"?e.item:void 0;if(n||e.control==="file")return(0,a.jsx)(Y,{as:"control",title:x?`${g} *`:g,value:t,onChange:o,several:n!==e,image:n?.image===!0,video:n?.video===!0,label:g});let m=Array.isArray(t)?t:[];return(0,a.jsxs)("fieldset",{"data-graview-part":"group","data-graview-field":"list",children:[(0,a.jsx)("legend",{"data-graview-part":"label",children:p}),m.map((f,d)=>(0,a.jsxs)("div",{"data-graview-part":"item",children:[(0,a.jsx)("div",{style:{flex:1},children:(0,a.jsx)(T,{store:r,spec:{...e.item,optional:!1},value:f,onChange:b=>o(m.map((i,S)=>S===d?b:i)),prefilled:h,open:v,words:s})}),(0,a.jsx)("button",{type:"button","data-graview-part":"remove",onClick:()=>o(m.filter((b,i)=>i!==d)),children:"remove"})]},d)),(0,a.jsx)("button",{type:"button","data-graview-part":"add",onClick:()=>o([...m,void 0]),children:"add another"})]})}case"linked":return(0,a.jsx)("div",{"data-graview-part":"field","data-graview-field":"linked",children:(0,a.jsx)(_,{relation:e.relation,value:t,onChange:o,label:g})});case"repeat":return(0,a.jsx)(J,{value:t,onChange:o,start:e.of?k?.[e.of]:void 0,label:`${e.of?s(e.of).label:g} repeats`,name:e.name});case"opaque":return(0,a.jsxs)("p",{"data-graview-part":"unasked",children:["\u201C",F(e.name),"\u201D needs a structured answer this form cannot ask for yet."]})}}function ue(r){let e=[...r.querySelectorAll("input:not([type=hidden]), select, textarea")].filter(t=>!t.disabled&&!t.closest("[hidden], [inert], [aria-hidden='true']"));return e.find(t=>t.required&&t.value==="")??e[0]??r.querySelector('button[type="submit"]')}function he({store:r,mutation:e,prefilled:t={},open:o=[],onDone:h,principal:v,initial:s,label:k,only:g,autoFocus:x=!1}){let p=()=>Z(e,r.graph,t),[n,m]=(0,c.useState)(p),[f,d]=(0,c.useState)(()=>({...n,...s})),[b,i]=(0,c.useState)(null),S=v??r.seenFor,O=e.subject&&t[e.subject.arg],ne=S?ae(r,S,e,typeof O=="string"?O:void 0):void 0,L=X(r.schema,e),C=(g===void 0?L:g.flatMap(l=>L.find(u=>u.name===l)??[])).filter(l=>!ne?.has(l.name)),re=l=>j(r.schema,e,l),E=V(C.filter(l=>l.control==="date").map(l=>l.name)),W=(0,c.useRef)(void 0),ie=(l,u)=>d(A=>{let M={...A,[l.name]:u};if(E&&l.name===E.start&&l.control==="date"){let w=y=>typeof y=="string"&&y!==""?y:void 0,R=w(A[E.start])??W.current;if(w(u)){W.current=w(u);let y=B(R,w(u),w(A[E.end]),{time:l.time===!0,instant:l.instant===!0});y!==void 0&&(M[E.end]=y)}}return M}),q=(0,c.useRef)(null);return(0,c.useEffect)(()=>{if(!x)return;let l=document.activeElement,u=0,A=0,M=()=>{let w=q.current;if(!w)return;let R=document.activeElement;if(R!==l&&R!==document.body&&R!==null&&!w.contains(R)||w.contains(R))return;let y=w.querySelector("[data-graview-when-arriving]")&&A<30?null:ue(w);if(y){y.focus();return}A+=1,A<=30&&(u=requestAnimationFrame(M))};return u=requestAnimationFrame(M),()=>cancelAnimationFrame(u)},[]),(0,a.jsxs)("form",{ref:q,"data-testid":`form-${e.name}`,onSubmit:l=>{l.preventDefault();try{r.apply({name:e.name,args:{...ee(U(C,f),n),...t}},v?{author:v}:{}),i(null);let u=p();m(u),d({...u}),h?.()}catch(u){i(G(r.schema,r.allMutations(),u))}},"data-graview-part":"form",children:[(0,a.jsx)("style",{children:le}),C.map(l=>(0,a.jsx)(T,{store:r,spec:l,value:f[l.name],values:f,onChange:u=>ie(l,u),prefilled:t,open:o,words:re},l.name)),b?(0,a.jsx)("p",{"data-testid":"refused","data-graview-part":"refused",role:"alert",children:b}):null,(0,a.jsx)("button",{type:"submit","data-graview-part":"submit",children:k??e.title??e.name})]})}export{he as a};
104
+ `;function de({title:r,name:e,optional:t,amount:o,value:h,onChange:v}){let s=Y(o),[k,g]=(0,c.useState)(()=>typeof h=="number"?_(h,o):""),x=k.trim()!==""&&L(k,o)===void 0;return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"number","data-graview-amount":o.format??"unit",children:[(0,a.jsx)("span",{"data-graview-part":"label",children:r}),(0,a.jsxs)("span",{"data-graview-part":"amount",style:{display:"flex",alignItems:"center",gap:6},children:[s.prefix?(0,a.jsx)("span",{"data-graview-part":"amount-symbol","aria-hidden":"true",children:s.prefix}):null,(0,a.jsx)("input",{type:"text",inputMode:"decimal",name:e,required:!t,placeholder:s.placeholder,title:s.hint,"aria-invalid":x||void 0,value:k,onChange:p=>{g(p.target.value),v(L(p.target.value,o))},"data-graview-part":"control",style:{flex:1,minWidth:0}}),s.suffix?(0,a.jsx)("span",{"data-graview-part":"amount-symbol","aria-hidden":"true",children:s.suffix}):null]}),x?(0,a.jsxs)("span",{"data-graview-part":"hint",role:"status",children:["Not an amount ",s.hint,": write it like ",s.prefix??"",s.placeholder,s.suffix?` ${s.suffix}`:""]}):null]})}function te({children:r}){return(0,a.jsxs)("span",{"data-graview-part":"picker",children:[r,(0,a.jsx)("span",{"aria-hidden":"true","data-graview-part":"chevron",children:"\u25BE"})]})}var se=r=>({label:F(r),option:e=>e}),pe={phone:"+1 555 123 4567",place:"An address or a place's name",duration:"1h 30m, 90 or 1:30"};function M({store:r,spec:e,value:t,onChange:o,prefilled:h,open:v,words:s=se,values:k}){if(e.name in h&&e.control!=="group"&&e.control!=="variant")return null;let g=e.control==="node"&&!e.kinds.includes("*")?e.kinds.map(n=>F(G(r.schema.tryDefinition(n),n))).join(" or "):s(e.name).label,x=!(e.optional||e.control==="boolean"),p=x?(0,a.jsxs)(a.Fragment,{children:[g,(0,a.jsx)("span",{"aria-hidden":"true",children:" *"})]}):g;switch(e.control){case"text":case"date":return e.control==="text"&&e.long?(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"text",children:[(0,a.jsxs)("span",{"data-graview-part":"label",children:[p,e.markdown?(0,a.jsx)("span",{style:{fontWeight:"normal",color:"var(--graview-ink-faint)"},children:" \xB7 Markdown"}):null]}),(0,a.jsx)("textarea",{name:e.name,required:!e.optional,rows:6,value:typeof t=="string"?t:"",onChange:n=>o(n.target.value),"data-graview-part":"control",style:{fieldSizing:"content",minHeight:"7.5em",resize:"vertical",font:"inherit",lineHeight:1.5}})]}):e.control==="date"?(0,a.jsxs)("div",{"data-graview-part":"field","data-graview-field":"date",children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)(O,{name:e.name,label:s(e.name).label,required:!e.optional,value:typeof t=="string"&&t!==""?t:void 0,time:e.time===!0,instant:e.instant===!0,onChange:o})]}):(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control==="text"&&e.holds?e.holds:e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)("input",{type:e.control==="text"&&e.holds==="phone"?"tel":"text",name:e.name,required:!e.optional,...e.control==="text"&&e.app?{placeholder:"@owner/app or https://\u2026"}:{},...e.control==="text"&&e.holds?{placeholder:pe[e.holds]}:{},...e.control==="text"&&e.holds==="phone"?{autoComplete:"tel"}:{},value:typeof t=="string"?t:typeof t=="number"?String(t):"",onChange:n=>o(n.target.value),"data-graview-part":"control"})]});case"number":return e.amount?(0,a.jsx)(de,{title:p,name:e.name,optional:e.optional,amount:e.amount,value:t,onChange:o}):(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)("input",{type:"number",name:e.name,required:!e.optional,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.step===void 0?{}:{step:e.step},value:typeof t=="number"?t:"",onChange:n=>o(n.target.value===""?void 0:Number(n.target.value)),"data-graview-part":"control"})]});case"boolean":return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"boolean",children:[(0,a.jsx)("input",{type:"checkbox",name:e.name,checked:t===!0,onChange:n=>o(n.target.checked),"data-graview-part":"control"}),(0,a.jsx)("span",{"data-graview-part":"label",children:p})]});case"choice":return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)(te,{children:(0,a.jsxs)("select",{name:e.name,required:!e.optional,value:typeof t=="string"?t:"",onChange:n=>o(n.target.value||void 0),"data-graview-part":"control",children:[(0,a.jsx)("option",{value:"",children:"\u2014"}),(e.options??[]).map(n=>(0,a.jsx)("option",{value:n,children:s(e.name).option(n)},n))]})})]});case"node":{let n=v.find(i=>i.name===e.name)?.candidates,m=new Set(Object.values(h).filter(i=>typeof i=="string")),f=(e.kinds.includes("*")?[...r.graph.allNodes()]:e.kinds.flatMap(i=>r.graph.nodesOfKind(i))).filter(i=>!m.has(i.id)),d=n?n.map(i=>r.graph.getNode(i)).filter(i=>i!==void 0):f,y=$(d,i=>r.schema.tryDefinition(i));return(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":e.control,children:[(0,a.jsx)("span",{"data-graview-part":"label",children:p}),(0,a.jsx)(te,{children:(0,a.jsxs)("select",{name:e.name,required:!e.optional,value:typeof t=="string"?t:"",onChange:i=>o(i.target.value||void 0),"data-graview-part":"control",children:[(0,a.jsx)("option",{value:"",children:"\u2014"}),d.map(i=>{let S=y.get(i.id);return(0,a.jsxs)("option",{value:i.id,children:[j(r.schema.tryDefinition(i.kind),i),S?` \xB7 ${S}`:""]},i.id)})]})})]})}case"group":{let n=t??{};return(0,a.jsxs)("fieldset",{"data-graview-part":"group","data-graview-field":e.control,children:[(0,a.jsx)("legend",{"data-graview-part":"label",children:p}),e.fields.map(m=>(0,a.jsx)(M,{store:r,spec:m,value:n[m.name],onChange:f=>o({...n,[m.name]:f}),prefilled:h,open:v,words:s},m.name))]})}case"variant":{let n=t??{},m=typeof n[e.tag]=="string"?n[e.tag]:"",f=e.options.find(d=>d.value===m);return(0,a.jsxs)("fieldset",{"data-graview-part":"group","data-graview-field":e.control,children:[(0,a.jsx)("legend",{"data-graview-part":"label",children:p}),(0,a.jsxs)("label",{"data-graview-part":"field","data-graview-field":"choice",children:[(0,a.jsx)("span",{"data-graview-part":"label",children:F(e.tag)}),(0,a.jsxs)("select",{value:m,onChange:d=>o({[e.tag]:d.target.value}),"data-graview-part":"control",children:[(0,a.jsx)("option",{value:"",children:"\u2014"}),e.options.map(d=>(0,a.jsx)("option",{value:d.value,children:F(d.value)},d.value))]})]}),f?.fields.map(d=>(0,a.jsx)(M,{store:r,spec:d,value:n[d.name],onChange:y=>o({...n,[d.name]:y}),prefilled:h,open:v,words:s},d.name))]})}case"file":case"list":{let n=e.control==="file"?e:e.item.control==="file"?e.item:void 0;if(n||e.control==="file")return(0,a.jsx)(N,{as:"control",title:x?`${g} *`:g,value:t,onChange:o,several:n!==e,image:n?.image===!0,video:n?.video===!0,label:g});let m=Array.isArray(t)?t:[];return(0,a.jsxs)("fieldset",{"data-graview-part":"group","data-graview-field":"list",children:[(0,a.jsx)("legend",{"data-graview-part":"label",children:p}),m.map((f,d)=>(0,a.jsxs)("div",{"data-graview-part":"item",children:[(0,a.jsx)("div",{style:{flex:1},children:(0,a.jsx)(M,{store:r,spec:{...e.item,optional:!1},value:f,onChange:y=>o(m.map((i,S)=>S===d?y:i)),prefilled:h,open:v,words:s})}),(0,a.jsx)("button",{type:"button","data-graview-part":"remove",onClick:()=>o(m.filter((y,i)=>i!==d)),children:"remove"})]},d)),(0,a.jsx)("button",{type:"button","data-graview-part":"add",onClick:()=>o([...m,void 0]),children:"add another"})]})}case"linked":return(0,a.jsx)("div",{"data-graview-part":"field","data-graview-field":"linked",children:(0,a.jsx)(W,{relation:e.relation,value:t,onChange:o,label:g})});case"repeat":return(0,a.jsx)(I,{value:t,onChange:o,start:e.of?k?.[e.of]:void 0,label:`${e.of?s(e.of).label:g} repeats`,name:e.name});case"opaque":return(0,a.jsxs)("p",{"data-graview-part":"unasked",children:["\u201C",F(e.name),"\u201D needs a structured answer this form cannot ask for yet."]})}}function ue(r){let e=[...r.querySelectorAll("input:not([type=hidden]), select, textarea")].filter(t=>!t.disabled&&!t.closest("[hidden], [inert], [aria-hidden='true']"));return e.find(t=>t.required&&t.value==="")??e[0]??r.querySelector('button[type="submit"]')}function Se({store:r,mutation:e,prefilled:t={},open:o=[],onDone:h,principal:v,initial:s,label:k,only:g,autoFocus:x=!1}){let p=()=>Z(e,r.graph,t),[n,m]=(0,c.useState)(p),[f,d]=(0,c.useState)(()=>({...n,...s})),[y,i]=(0,c.useState)(null),S=v??r.seenFor,q=e.subject&&t[e.subject.arg],ne=S?ae(r,S,e,typeof q=="string"?q:void 0):void 0,D=X(r.schema,e),C=(g===void 0?D:g.flatMap(l=>D.find(u=>u.name===l)??[])).filter(l=>!ne?.has(l.name)),re=l=>B(r.schema,e,l),E=Q(C.filter(l=>l.control==="date").map(l=>l.name)),H=(0,c.useRef)(void 0),ie=(l,u)=>d(A=>{let P={...A,[l.name]:u};if(E&&l.name===E.start&&l.control==="date"){let w=b=>typeof b=="string"&&b!==""?b:void 0,R=w(A[E.start])??H.current;if(w(u)){H.current=w(u);let b=J(R,w(u),w(A[E.end]),{time:l.time===!0,instant:l.instant===!0});b!==void 0&&(P[E.end]=b)}}return P}),z=(0,c.useRef)(null);return(0,c.useEffect)(()=>{if(!x)return;let l=document.activeElement,u=0,A=0,P=()=>{let w=z.current;if(!w)return;let R=document.activeElement;if(R!==l&&R!==document.body&&R!==null&&!w.contains(R)||w.contains(R))return;let b=w.querySelector("[data-graview-when-arriving]")&&A<30?null:ue(w);if(b){b.focus();return}A+=1,A<=30&&(u=requestAnimationFrame(P))};return u=requestAnimationFrame(P),()=>cancelAnimationFrame(u)},[]),(0,a.jsxs)("form",{ref:z,"data-testid":`form-${e.name}`,onSubmit:l=>{l.preventDefault();try{r.apply({name:e.name,args:{...ee(U(C,f),n),...t}},v?{author:v}:{}),i(null);let u=p();m(u),d({...u}),h?.()}catch(u){i(V(r.schema,r.allMutations(),u))}},"data-graview-part":"form",children:[(0,a.jsx)("style",{children:le}),C.map(l=>(0,a.jsx)(M,{store:r,spec:l,value:f[l.name],values:f,onChange:u=>ie(l,u),prefilled:t,open:o,words:re},l.name)),y?(0,a.jsx)("p",{"data-testid":"refused","data-graview-part":"refused",role:"alert",children:y}):null,(0,a.jsx)("button",{type:"submit","data-graview-part":"submit",children:k??e.title??e.name})]})}export{Se as a};
@@ -1 +1 @@
1
- import{b as P,c as m,d as k}from"./chunk.RWCWRJJC.js";import{b as v,c as w,d as S,e as x,f as M}from"./chunk.G446PWV6.js";import"./chunk.NVNQSZ43.js";import"./chunk.FJEXINFF.js";import"./chunk.VOHRQXCF.js";import"./chunk.SLBWPVIY.js";import"./chunk.AJZBJBMO.js";var O=new Set(["input","select","textarea"]),g=r=>r.namespaceURI==="http://www.w3.org/1999/xhtml"&&O.has(r.localName),N=r=>r.localName==="select"||r.type==="checkbox"||r.type==="radio",E=r=>r.type==="checkbox"||r.type==="radio"?!r.checked:r.localName!=="select"&&r.value==="";function h(r){return r.type==="checkbox"||r.type==="radio"?`checked:${r.checked}`:r.localName==="select"&&r.multiple?`selected:${[...r.selectedOptions].map(n=>n.value).join("\0")}`:`value:${r.value}`}function F(r=n=>n.isTrusted){let n=new WeakMap,d=new WeakSet,o=new WeakMap,i={heard(e,t){if(!(!g(t)||!r(e))&&(e.type==="input"||e.type==="change"&&N(t))&&((N(t)||E(t))&&d.delete(t),E(t)&&o.delete(t),n.set(t,h(t)),t.type==="radio"&&t.name)){let c=t.getRootNode();for(let u of c.querySelectorAll?.('input[type="radio"]')??[])u.name===t.name&&n.set(u,h(u))}},filled(e){n.delete(e),o.delete(e),g(e)&&!E(e)?d.add(e):d.delete(e)},press(e,t,c){if(!r(e))return;let u=t.closest("[data-act]");if(!u||!w(u))return;let l=e.type==="keydown"?e.key:void 0;if(!(e.type!=="click"&&!((l==="Enter"||l===" ")&&t===u&&!v(u))))return i.collect(u,c)},collect(e,t){if(!e.hasAttribute("data-act")||!t.contains(e))return;let c=e.closest("[data-record]"),u=e.closest("fieldset, [role='group']")??t,l=[];for(let a of u.querySelectorAll("input[name], select[name], textarea[name]")){let s=a,f=!d.has(s)&&n.get(s)===h(s);if(s.type==="radio"){if(!s.checked)continue;l.push({name:s.name,value:s.value,typed:f,empty:!1,chosen:!0});continue}if(s.localName==="select"){l.push({name:s.name,value:s.value,typed:f,empty:s.value===""&&!f,chosen:!0});continue}if(s.type==="checkbox"){l.push({name:s.name,value:s.checked,typed:f,empty:!s.checked&&!d.has(s)&&!f});continue}let R=(s.type==="number"||s.type==="range")&&s.value!==""&&Number.isFinite(s.valueAsNumber)?s.valueAsNumber:s.value,A=f?o.get(s):void 0;l.push({name:s.name,value:R,typed:f,empty:s.value===""&&!f,...A?{from:A}:{}})}return{as:e.getAttribute("data-act")??"",...c&&t.contains(c)?{record:c.getAttribute("data-record")}:{},fields:l}},prefilled(e,t){d.delete(e),o.set(e,t),n.set(e,h(e))}};return i}var b=new WeakMap,L=(r,n)=>{n.tab&&r.removeAttribute("tabindex"),n.role&&r.getAttribute("role")==="button"&&r.removeAttribute("role"),r.removeAttribute("data-graview-press"),b.delete(r)};function W(r){for(let n of r.querySelectorAll("[data-act], [data-graview-press], [role], [aria-pressed], [aria-expanded]")){let d=b.get(n),o=w(n)&&!v(n)&&!g(n),i=!o&&S(n,d?.role?null:n.getAttribute("role"));if(d&&(d.bound!==o||!(o||i))&&L(n,d),(o||i)&&!b.has(n)){let e=!x(n),t=o&&M(n);e&&n.setAttribute("tabindex","0"),t&&n.setAttribute("role","button"),n.setAttribute("data-graview-press",""),b.set(n,{tab:e,role:t,bound:o})}}}var y=new WeakSet;function V(r){for(let n of r.querySelectorAll("svg")){let d=n.hasAttribute("role")||n.hasAttribute("aria-label")||n.hasAttribute("aria-labelledby")||[...n.children].some(e=>e.localName==="title"),o=n.hasAttribute("tabindex")||n.hasAttribute("data-graview-link")||n.hasAttribute("data-graview-press")||n.querySelector("[tabindex], [data-graview-link], [data-graview-press], a")!==null,i=!d&&!o;i&&!y.has(n)&&!n.hasAttribute("aria-hidden")?(n.setAttribute("aria-hidden","true"),y.add(n)):!i&&y.has(n)&&(n.removeAttribute("aria-hidden"),y.delete(n))}}var j=1e3;function I(r){let n=r.getAttribute("data-debounce")?.trim(),d=n?Number(n):Number.NaN;return Number.isFinite(d)?Math.min(1e4,Math.max(250,Math.round(d))):j}function B(r){let n=r.trusted??(e=>e.isTrusted),d=r.timers??{set:(e,t)=>setTimeout(e,t),clear:e=>clearTimeout(e)},o=new Map,i=(e,t)=>{let c=o.get(e);c&&d.clear(c.handle),o.delete(e);let u=r.reader.collect(e,t);u&&r.save(u,e)};return{heard(e,t,c){if(!g(t)||!n(e)||!t.hasAttribute("data-act"))return;let u=t.getAttribute("data-save");if(e.type==="input"&&u==="input"){let l=o.get(t);l&&d.clear(l.handle),o.set(t,{root:c,handle:d.set(()=>i(t,c),I(t))})}else e.type==="change"&&(u==="change"||u==="input"&&o.has(t))&&i(t,c)},flush(){for(let[e,{root:t}]of[...o])i(e,t)},get waiting(){return o.size}}}var H=new Set(["text","search","email","url","tel","number"]);function D(r,n,d,o){for(let i of r.querySelectorAll("input[data-prefill], textarea[data-prefill]")){let e=i;if(d.has(e))continue;let t=e.getAttribute("data-prefill")??"";if(t===""||e.getAttribute("name")!==t||e.localName==="input"&&!H.has(e.type))continue;if(e.value!==""){d.add(e);continue}let u=[...(e.closest("fieldset, [role='group']")??r).querySelectorAll("[data-act]")],l=e.closest("[data-record]"),a=new Set(u.map(p=>p.closest("[data-record]")?.getAttribute("data-record")).filter(p=>typeof p=="string")),s=l&&r.contains(l)?l.getAttribute("data-record"):a.size===1?[...a][0]:void 0;if(!s)continue;let f=o({record:s,field:t,acts:u.map(p=>p.getAttribute("data-act")??"")});if(f!==void 0){if(e.value=f,d.add(e),e.value!==f){e.value="";continue}n.prefilled(e,{record:s,field:t,value:f})}}}function _(r,n,d,o){let i=k(n,o.as);if(!i)return m("undeclared",`This view may not ask for \u201C${o.as}\u201D: its manifest does not name it.`);let e=r.allMutations().find(a=>a.name===i.act);if(!e)return m("unknown-act","There is no act by that name here.");let t={};if(o.record!==void 0){let a=i.record??e.subject?.arg;if(!a)return m("unbound",`\u201C${o.as}\u201D is not done to a record.`);if(!d.has(o.record))return m("unbound","That press is bound to a record this view was not shown.");t[a]=o.record}for(let[a,s]of Object.entries(i.constants??{})){if(a in t)return m("malformed",`\u201C${a}\u201D is both the bound record and a constant.`);t[a]=s}let c=e.input?.shape??{},u=new Set(Object.keys(c)),l=new Set;for(let a of o.fields)if(!(!u.has(a.name)||a.name in t)){if(l.has(a.name))return m("malformed",`Two fields here are called \u201C${a.name}\u201D.`);if(l.add(a.name),a.typed&&a.chosen){let s=P(c[a.name])?.find(f=>String(f)===String(a.value));if(s!==void 0)t[a.name]=s;else if(typeof a.value=="string"&&d.has(a.value))t[a.name]=a.value;else return m("untyped",`\u201C${a.name}\u201D was a choice among the view's own words, not one this app declares, so it was not sent.`)}else{if(a.typed&&a.from&&!(o.record===a.from.record&&a.name===a.from.field&&T(r,i,a.from.record,a.from.field)))return m("untyped",`\u201C${a.name}\u201D was filled in from a record for an act that writes it back there, not for this one, so it was not sent.`);if(a.typed&&a.from&&String(a.value)===a.from.value)t[a.name]=r.graph.getNode(a.from.record)?.[a.name]??a.value;else if(a.typed)t[a.name]=a.value;else if(!a.empty)return m("untyped",`\u201C${a.name}\u201D was filled in by the view, not typed by you, so it was not sent.`)}}return{ok:!0,name:i.act,args:t}}function T(r,n,d,o){let i=r.allMutations().find(u=>u.name===n.act),e=i?.subject;if(!i||!e||(n.record??e.arg)!==e.arg||o===e.arg||Object.hasOwn(n.constants??{},o)||!Object.hasOwn(i.input.shape??{},o)||Object.keys(i.writesOther??{}).length>0)return!1;let t=r.graph.getNode(d)?.kind,c=t===void 0?void 0:r.schema.tryDefinition(t);return!c||e.kinds!=="*"&&!e.kinds.includes(t)||!Object.hasOwn(c.fields.shape??{},o)?!1:i.writes?.includes(o)??!1}function C(r,n,d,o,i){if(!o.has(i.record))return;let e=r.seenBy(n).graph.getNode(i.record);if(!e||!i.acts.some(u=>{let l=k(d,u);if(!l||!T(r,l,i.record,i.field))return!1;let a=r.allMutations().find(s=>s.name===l.act).subject;return r.permits({name:l.act,args:{[a.arg]:i.record}},n).ok}))return;let c=e[i.field];return typeof c=="string"?c:typeof c=="number"&&Number.isFinite(c)?String(c):void 0}export{j as SAVE_DEBOUNCE_MS,F as createPressReader,B as createSaver,D as fillPrefills,_ as judgePress,W as markPresses,C as prefillOf,V as quietPictures,I as saveDebounceOf,T as writesBack};
1
+ import{b as P,c as m,d as k}from"./chunk.J6OT74RM.js";import{b as v,c as w,d as S,e as x,f as M}from"./chunk.B3WVCSW5.js";import"./chunk.WDEMPWS4.js";import"./chunk.H2B3SEI7.js";import"./chunk.6W2DUW5S.js";import"./chunk.SLBWPVIY.js";import"./chunk.AJZBJBMO.js";var O=new Set(["input","select","textarea"]),g=r=>r.namespaceURI==="http://www.w3.org/1999/xhtml"&&O.has(r.localName),N=r=>r.localName==="select"||r.type==="checkbox"||r.type==="radio",E=r=>r.type==="checkbox"||r.type==="radio"?!r.checked:r.localName!=="select"&&r.value==="";function h(r){return r.type==="checkbox"||r.type==="radio"?`checked:${r.checked}`:r.localName==="select"&&r.multiple?`selected:${[...r.selectedOptions].map(n=>n.value).join("\0")}`:`value:${r.value}`}function F(r=n=>n.isTrusted){let n=new WeakMap,d=new WeakSet,o=new WeakMap,i={heard(e,t){if(!(!g(t)||!r(e))&&(e.type==="input"||e.type==="change"&&N(t))&&((N(t)||E(t))&&d.delete(t),E(t)&&o.delete(t),n.set(t,h(t)),t.type==="radio"&&t.name)){let c=t.getRootNode();for(let u of c.querySelectorAll?.('input[type="radio"]')??[])u.name===t.name&&n.set(u,h(u))}},filled(e){n.delete(e),o.delete(e),g(e)&&!E(e)?d.add(e):d.delete(e)},press(e,t,c){if(!r(e))return;let u=t.closest("[data-act]");if(!u||!w(u))return;let l=e.type==="keydown"?e.key:void 0;if(!(e.type!=="click"&&!((l==="Enter"||l===" ")&&t===u&&!v(u))))return i.collect(u,c)},collect(e,t){if(!e.hasAttribute("data-act")||!t.contains(e))return;let c=e.closest("[data-record]"),u=e.closest("fieldset, [role='group']")??t,l=[];for(let a of u.querySelectorAll("input[name], select[name], textarea[name]")){let s=a,f=!d.has(s)&&n.get(s)===h(s);if(s.type==="radio"){if(!s.checked)continue;l.push({name:s.name,value:s.value,typed:f,empty:!1,chosen:!0});continue}if(s.localName==="select"){l.push({name:s.name,value:s.value,typed:f,empty:s.value===""&&!f,chosen:!0});continue}if(s.type==="checkbox"){l.push({name:s.name,value:s.checked,typed:f,empty:!s.checked&&!d.has(s)&&!f});continue}let R=(s.type==="number"||s.type==="range")&&s.value!==""&&Number.isFinite(s.valueAsNumber)?s.valueAsNumber:s.value,A=f?o.get(s):void 0;l.push({name:s.name,value:R,typed:f,empty:s.value===""&&!f,...A?{from:A}:{}})}return{as:e.getAttribute("data-act")??"",...c&&t.contains(c)?{record:c.getAttribute("data-record")}:{},fields:l}},prefilled(e,t){d.delete(e),o.set(e,t),n.set(e,h(e))}};return i}var b=new WeakMap,L=(r,n)=>{n.tab&&r.removeAttribute("tabindex"),n.role&&r.getAttribute("role")==="button"&&r.removeAttribute("role"),r.removeAttribute("data-graview-press"),b.delete(r)};function W(r){for(let n of r.querySelectorAll("[data-act], [data-graview-press], [role], [aria-pressed], [aria-expanded]")){let d=b.get(n),o=w(n)&&!v(n)&&!g(n),i=!o&&S(n,d?.role?null:n.getAttribute("role"));if(d&&(d.bound!==o||!(o||i))&&L(n,d),(o||i)&&!b.has(n)){let e=!x(n),t=o&&M(n);e&&n.setAttribute("tabindex","0"),t&&n.setAttribute("role","button"),n.setAttribute("data-graview-press",""),b.set(n,{tab:e,role:t,bound:o})}}}var y=new WeakSet;function V(r){for(let n of r.querySelectorAll("svg")){let d=n.hasAttribute("role")||n.hasAttribute("aria-label")||n.hasAttribute("aria-labelledby")||[...n.children].some(e=>e.localName==="title"),o=n.hasAttribute("tabindex")||n.hasAttribute("data-graview-link")||n.hasAttribute("data-graview-press")||n.querySelector("[tabindex], [data-graview-link], [data-graview-press], a")!==null,i=!d&&!o;i&&!y.has(n)&&!n.hasAttribute("aria-hidden")?(n.setAttribute("aria-hidden","true"),y.add(n)):!i&&y.has(n)&&(n.removeAttribute("aria-hidden"),y.delete(n))}}var j=1e3;function I(r){let n=r.getAttribute("data-debounce")?.trim(),d=n?Number(n):Number.NaN;return Number.isFinite(d)?Math.min(1e4,Math.max(250,Math.round(d))):j}function B(r){let n=r.trusted??(e=>e.isTrusted),d=r.timers??{set:(e,t)=>setTimeout(e,t),clear:e=>clearTimeout(e)},o=new Map,i=(e,t)=>{let c=o.get(e);c&&d.clear(c.handle),o.delete(e);let u=r.reader.collect(e,t);u&&r.save(u,e)};return{heard(e,t,c){if(!g(t)||!n(e)||!t.hasAttribute("data-act"))return;let u=t.getAttribute("data-save");if(e.type==="input"&&u==="input"){let l=o.get(t);l&&d.clear(l.handle),o.set(t,{root:c,handle:d.set(()=>i(t,c),I(t))})}else e.type==="change"&&(u==="change"||u==="input"&&o.has(t))&&i(t,c)},flush(){for(let[e,{root:t}]of[...o])i(e,t)},get waiting(){return o.size}}}var H=new Set(["text","search","email","url","tel","number"]);function D(r,n,d,o){for(let i of r.querySelectorAll("input[data-prefill], textarea[data-prefill]")){let e=i;if(d.has(e))continue;let t=e.getAttribute("data-prefill")??"";if(t===""||e.getAttribute("name")!==t||e.localName==="input"&&!H.has(e.type))continue;if(e.value!==""){d.add(e);continue}let u=[...(e.closest("fieldset, [role='group']")??r).querySelectorAll("[data-act]")],l=e.closest("[data-record]"),a=new Set(u.map(p=>p.closest("[data-record]")?.getAttribute("data-record")).filter(p=>typeof p=="string")),s=l&&r.contains(l)?l.getAttribute("data-record"):a.size===1?[...a][0]:void 0;if(!s)continue;let f=o({record:s,field:t,acts:u.map(p=>p.getAttribute("data-act")??"")});if(f!==void 0){if(e.value=f,d.add(e),e.value!==f){e.value="";continue}n.prefilled(e,{record:s,field:t,value:f})}}}function _(r,n,d,o){let i=k(n,o.as);if(!i)return m("undeclared",`This view may not ask for \u201C${o.as}\u201D: its manifest does not name it.`);let e=r.allMutations().find(a=>a.name===i.act);if(!e)return m("unknown-act","There is no act by that name here.");let t={};if(o.record!==void 0){let a=i.record??e.subject?.arg;if(!a)return m("unbound",`\u201C${o.as}\u201D is not done to a record.`);if(!d.has(o.record))return m("unbound","That press is bound to a record this view was not shown.");t[a]=o.record}for(let[a,s]of Object.entries(i.constants??{})){if(a in t)return m("malformed",`\u201C${a}\u201D is both the bound record and a constant.`);t[a]=s}let c=e.input?.shape??{},u=new Set(Object.keys(c)),l=new Set;for(let a of o.fields)if(!(!u.has(a.name)||a.name in t)){if(l.has(a.name))return m("malformed",`Two fields here are called \u201C${a.name}\u201D.`);if(l.add(a.name),a.typed&&a.chosen){let s=P(c[a.name])?.find(f=>String(f)===String(a.value));if(s!==void 0)t[a.name]=s;else if(typeof a.value=="string"&&d.has(a.value))t[a.name]=a.value;else return m("untyped",`\u201C${a.name}\u201D was a choice among the view's own words, not one this app declares, so it was not sent.`)}else{if(a.typed&&a.from&&!(o.record===a.from.record&&a.name===a.from.field&&T(r,i,a.from.record,a.from.field)))return m("untyped",`\u201C${a.name}\u201D was filled in from a record for an act that writes it back there, not for this one, so it was not sent.`);if(a.typed&&a.from&&String(a.value)===a.from.value)t[a.name]=r.graph.getNode(a.from.record)?.[a.name]??a.value;else if(a.typed)t[a.name]=a.value;else if(!a.empty)return m("untyped",`\u201C${a.name}\u201D was filled in by the view, not typed by you, so it was not sent.`)}}return{ok:!0,name:i.act,args:t}}function T(r,n,d,o){let i=r.allMutations().find(u=>u.name===n.act),e=i?.subject;if(!i||!e||(n.record??e.arg)!==e.arg||o===e.arg||Object.hasOwn(n.constants??{},o)||!Object.hasOwn(i.input.shape??{},o)||Object.keys(i.writesOther??{}).length>0)return!1;let t=r.graph.getNode(d)?.kind,c=t===void 0?void 0:r.schema.tryDefinition(t);return!c||e.kinds!=="*"&&!e.kinds.includes(t)||!Object.hasOwn(c.fields.shape??{},o)?!1:i.writes?.includes(o)??!1}function C(r,n,d,o,i){if(!o.has(i.record))return;let e=r.seenBy(n).graph.getNode(i.record);if(!e||!i.acts.some(u=>{let l=k(d,u);if(!l||!T(r,l,i.record,i.field))return!1;let a=r.allMutations().find(s=>s.name===l.act).subject;return r.permits({name:l.act,args:{[a.arg]:i.record}},n).ok}))return;let c=e[i.field];return typeof c=="string"?c:typeof c=="number"&&Number.isFinite(c)?String(c):void 0}export{j as SAVE_DEBOUNCE_MS,F as createPressReader,B as createSaver,D as fillPrefills,_ as judgePress,W as markPresses,C as prefillOf,V as quietPictures,I as saveDebounceOf,T as writesBack};
@@ -1 +1 @@
1
- var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{q as He}from"./chunk.7KZ44FEU.js";import{d as Je,e as Ee,f as ze,g as je}from"./chunk.Y37DXEHG.js";import{a as Ie}from"./chunk.7FZY5E2U.js";import{e as X}from"./chunk.C7EEYSAM.js";import{a as j}from"./chunk.FEBCIEI3.js";import{f as De,g as Y,i as Pe}from"./chunk.OYRZ2DEI.js";import{a as Se}from"./chunk.7EA7THSM.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.VOHRQXCF.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.BJL6EL6B.js","./chunk.SZCZD2GM.js","./chunk.C7EEYSAM.js","./chunk.QRCTTDDQ.js","./chunk.3TME4BG3.js","./chunk.I43ONAEL.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.OYRZ2DEI.js","./chunk.7EA7THSM.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.5LWPNOJA.js"))),kn=()=>(__graviewPreload(import.meta.url,["./chunk.FEBCIEI3.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.ULAMIQ52.js")).catch(()=>{}),vn=async()=>{(await kn())?.judgeWithLines()},q=F(()=>(__graviewPreload(import.meta.url,["./chunk.WVUJXDXZ.js","./chunk.QRCTTDDQ.js","./chunk.3TME4BG3.js","./chunk.I43ONAEL.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.7EA7THSM.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.GZHEGKPF.js"))),An=F(()=>(__graviewPreload(import.meta.url,["./chunk.4LI73QOY.js","./chunk.G4JJXA63.js","./chunk.VGTEEANA.js","./chunk.SZCZD2GM.js","./chunk.XLM4ONUB.js","./chunk.XOZU4OFA.js","./chunk.C7EEYSAM.js","./chunk.Q5WEOX3Q.js","./chunk.CHMUL36A.js","./chunk.U6PCKJ26.js","./chunk.FEBCIEI3.js","./chunk.WVUJXDXZ.js","./chunk.QRCTTDDQ.js","./chunk.3TME4BG3.js","./chunk.I43ONAEL.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.CV4QA4ZF.js","./chunk.OYRZ2DEI.js","./chunk.7EA7THSM.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.NICCIJV4.js"))),On=F(()=>(__graviewPreload(import.meta.url,["./chunk.NHIPVAGR.js","./chunk.BJL6EL6B.js","./chunk.SZCZD2GM.js","./chunk.7FZY5E2U.js","./chunk.7354O67H.js","./chunk.C7EEYSAM.js","./chunk.QRCTTDDQ.js","./chunk.3TME4BG3.js","./chunk.I43ONAEL.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.CV4QA4ZF.js","./chunk.OYRZ2DEI.js","./chunk.7EA7THSM.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.Z2JMTRF4.js"))),Rn=F(()=>(__graviewPreload(import.meta.url,["./chunk.XZLKTOJE.js","./chunk.R7ZZJOJW.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.EIWTZC4A.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
+ 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 +1 @@
1
- var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{a as Ue}from"./chunk.7FZY5E2U.js";import{a as Be}from"./chunk.XLM4ONUB.js";import{a as We}from"./chunk.DGWNVDZB.js";import{a as X}from"./chunk.TI4OSTQV.js";import{a as fe}from"./chunk.3TME4BG3.js";import{e as ce}from"./chunk.AI2HBKVP.js";import{E as we,G as ln,J as He,P as Le,T as Fe,aa as Je}from"./chunk.Q5IAXTF5.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.VOHRQXCF.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.4LI73QOY.js","./chunk.G4JJXA63.js","./chunk.VGTEEANA.js","./chunk.SZCZD2GM.js","./chunk.XLM4ONUB.js","./chunk.XOZU4OFA.js","./chunk.C7EEYSAM.js","./chunk.Q5WEOX3Q.js","./chunk.CHMUL36A.js","./chunk.U6PCKJ26.js","./chunk.FEBCIEI3.js","./chunk.WVUJXDXZ.js","./chunk.QRCTTDDQ.js","./chunk.3TME4BG3.js","./chunk.I43ONAEL.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.CV4QA4ZF.js","./chunk.OYRZ2DEI.js","./chunk.7EA7THSM.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.NICCIJV4.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};
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};