fnloom 0.4.0 → 0.4.1

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 (132) hide show
  1. package/package.json +13 -13
  2. package/packages/build/package.json +2 -2
  3. package/packages/cli/package.json +1 -1
  4. package/packages/core/package.json +4 -4
  5. package/packages/core/src/gin-a.ts +13 -2
  6. package/packages/hub/package.json +13 -13
  7. package/packages/hub/src/api/store-ops.ts +9 -2
  8. package/packages/hub/src/catalog/catalog.ts +3 -2
  9. package/packages/sdk/package.json +8 -8
  10. package/packages/sdk/src/server/llm-wire.ts +50 -1
  11. package/packages/web/dist/assets/{ActorSettingsView-CDszUbHz.js → ActorSettingsView-CiWhrnP4.js} +2 -2
  12. package/packages/web/dist/assets/{AdminLayout-CFIz4GsQ.js → AdminLayout-CjVNzmYD.js} +2 -2
  13. package/packages/web/dist/assets/{AppPage-BvoVTk6h.js → AppPage-D_kkUatv.js} +2 -2
  14. package/packages/web/dist/assets/{AutoPairPicker-CLjD-muP.js → AutoPairPicker-BdCHi7dL.js} +2 -2
  15. package/packages/web/dist/assets/{BrowserFrame-BcN-A76X.js → BrowserFrame-CVQvfCB8.js} +2 -2
  16. package/packages/web/dist/assets/{ChatPage-DhTpAyM2.js → ChatPage-CPZJ8ya6.js} +2 -2
  17. package/packages/web/dist/assets/{CodeViewer-K9jrTmFO.js → CodeViewer-DzWZyAp4.js} +2 -2
  18. package/packages/web/dist/assets/{ConfigWithCustom-BvrvSVIp.js → ConfigWithCustom-C49loznj.js} +3 -3
  19. package/packages/web/dist/assets/{ConfirmDialog-BDvLleYf.js → ConfirmDialog-BtugUGEY.js} +2 -2
  20. package/packages/web/dist/assets/{ConnectPage-Dg6IPNNh.js → ConnectPage-D8k2nSdX.js} +2 -2
  21. package/packages/web/dist/assets/{ContextItemPage-qisBQetR.js → ContextItemPage-DC4FGi8V.js} +2 -2
  22. package/packages/web/dist/assets/{ContextPage-DXa6Yqk-.js → ContextPage-MlEkKMq0.js} +2 -2
  23. package/packages/web/dist/assets/{ContextRow-DDYnYRaL.js → ContextRow-BN26Di1B.js} +2 -2
  24. package/packages/web/dist/assets/{DataPage-DOE_pKAY.js → DataPage-CvOYkEkS.js} +2 -2
  25. package/packages/web/dist/assets/{DataTypePage-BnP_JELT.js → DataTypePage-CDEL6BHp.js} +2 -2
  26. package/packages/web/dist/assets/{DesignPage-B9MJbF10.js → DesignPage-D-MsKLuP.js} +2 -2
  27. package/packages/web/dist/assets/{ExplorePage-cRDQZRea.js → ExplorePage-CNQpEe_8.js} +2 -2
  28. package/packages/web/dist/assets/{FnPill-CbLZCXYM.js → FnPill-Dm5mmffj.js} +2 -2
  29. package/packages/web/dist/assets/{FnView-CG_wBKTP.js → FnView-oiIU5vka.js} +2 -2
  30. package/packages/web/dist/assets/{FnsView-BybyK12w.js → FnsView-DgIfza4W.js} +2 -2
  31. package/packages/web/dist/assets/{GinExprView-BYCKSD_n.js → GinExprView-C19g0UgI.js} +2 -2
  32. package/packages/web/dist/assets/{GinForm-CXjYVf2_.js → GinForm-p7UsKQ3s.js} +2 -2
  33. package/packages/web/dist/assets/{GinTypeView-Bmbmx9e_.js → GinTypeView-DvdHc0V4.js} +2 -2
  34. package/packages/web/dist/assets/{GinValueView-CWUzS7ti.js → GinValueView-D6c7E4C_.js} +2 -2
  35. package/packages/web/dist/assets/{GraphPage-D6OhckfJ.js → GraphPage-BTamx4d-.js} +2 -2
  36. package/packages/web/dist/assets/{GraphPanel-BTitgA-K.js → GraphPanel-DKpbijQD.js} +2 -2
  37. package/packages/web/dist/assets/{HubPicker-DVly8dLD.js → HubPicker-DfXIcUz1.js} +2 -2
  38. package/packages/web/dist/assets/{InboxApprovals-BF84edZU.js → InboxApprovals-B9qwPCHR.js} +2 -2
  39. package/packages/web/dist/assets/{InboxPage-DohZ9EDP.js → InboxPage-j2lF00uW.js} +2 -2
  40. package/packages/web/dist/assets/{InjectedList-e6qr1kdU.js → InjectedList-BTGvy8GB.js} +2 -2
  41. package/packages/web/dist/assets/{InstallDialog-JJCKYs2s.js → InstallDialog-BRJXLSMJ.js} +2 -2
  42. package/packages/web/dist/assets/{InstanceTypes-BqUzx87o.js → InstanceTypes-DYdolFFW.js} +2 -2
  43. package/packages/web/dist/assets/{InstanceView-C73pev7A.js → InstanceView-C5dJLBPe.js} +2 -2
  44. package/packages/web/dist/assets/{ItemHistory-dbGgOZsw.js → ItemHistory-vsyIMjIX.js} +2 -2
  45. package/packages/web/dist/assets/{LimitsView-Ddp5WakY.js → LimitsView-BtbQzkX1.js} +2 -2
  46. package/packages/web/dist/assets/{ListSearch-CYNNAuMB.js → ListSearch-BdVW9FHD.js} +2 -2
  47. package/packages/web/dist/assets/{LlmCallDetails-C9H5Hc2J.js → LlmCallDetails-Cd7qtybU.js} +2 -2
  48. package/packages/web/dist/assets/{LlmCallsView-CBqyZ8Cj.js → LlmCallsView-CrZB_I1H.js} +2 -2
  49. package/packages/web/dist/assets/{LoadState-B2YhZlyC.js → LoadState-8UknKQ6e.js} +2 -2
  50. package/packages/web/dist/assets/{McpDialog-DhlLklIq.js → McpDialog-r-qJDHOO.js} +2 -2
  51. package/packages/web/dist/assets/{McpView-D_ZmNO56.js → McpView-FeDQWGxu.js} +2 -2
  52. package/packages/web/dist/assets/{McpsView-9_gwBuzw.js → McpsView-Czd2yUdE.js} +2 -2
  53. package/packages/web/dist/assets/{MemoryDialog-pTHIxKEX.js → MemoryDialog-DDiT6wO1.js} +2 -2
  54. package/packages/web/dist/assets/{ModelCallsView-FHv2XWRX.js → ModelCallsView-DsdztwCR.js} +2 -2
  55. package/packages/web/dist/assets/{ModelPicker-EqOuvVnE.js → ModelPicker-Df_3l8nS.js} +2 -2
  56. package/packages/web/dist/assets/{ModelsView-D9UaL4PX.js → ModelsView-YXwRDgWv.js} +2 -2
  57. package/packages/web/dist/assets/{NotFoundPage-BsuJysan.js → NotFoundPage-DDEOlB6B.js} +2 -2
  58. package/packages/web/dist/assets/{PairPage-B_ZXsbL4.js → PairPage-D3uHAkh1.js} +2 -2
  59. package/packages/web/dist/assets/{PanelHost-Dx-vNNl5.js → PanelHost-BzWYqH39.js} +2 -2
  60. package/packages/web/dist/assets/{PeopleView-D6dmEgMs.js → PeopleView-Cg9RO5SF.js} +2 -2
  61. package/packages/web/dist/assets/{PoliciesView-Bn4rm-ao.js → PoliciesView-BoshL7RQ.js} +2 -2
  62. package/packages/web/dist/assets/{RefusalList-aosRD1ie.js → RefusalList-DnLIfmi-.js} +2 -2
  63. package/packages/web/dist/assets/{RendererHost-rjnpSgyQ.js → RendererHost-CmkaVEX0.js} +2 -2
  64. package/packages/web/dist/assets/{ResourceViewer-C4tRColf.js → ResourceViewer-CSAY6xIs.js} +2 -2
  65. package/packages/web/dist/assets/{ResourcesPage-7mCLBORZ.js → ResourcesPage-DAoa9mDs.js} +2 -2
  66. package/packages/web/dist/assets/{ResultGrid-GIMoQUAr.js → ResultGrid-DSyc0btv.js} +2 -2
  67. package/packages/web/dist/assets/{ReviewSummaryStrip-Bvjn3Iq8.js → ReviewSummaryStrip-Bzy-KGz_.js} +2 -2
  68. package/packages/web/dist/assets/{ReviewView-DIqsUedT.js → ReviewView-Cwq8Az_B.js} +2 -2
  69. package/packages/web/dist/assets/{RuleRow-zRg-e8Vj.js → RuleRow-DAvl2m9p.js} +2 -2
  70. package/packages/web/dist/assets/{RunCard-C7wOGaw8.js → RunCard-BMyRkKxJ.js} +2 -2
  71. package/packages/web/dist/assets/{RunDetails-W4GbE6AE.js → RunDetails-Bvyr1HYK.js} +2 -2
  72. package/packages/web/dist/assets/{RunDot-C46uzzNM.js → RunDot-Lfrt5XR3.js} +2 -2
  73. package/packages/web/dist/assets/{RunPage-DPLtZpeB.js → RunPage-C0-wY6Uz.js} +2 -2
  74. package/packages/web/dist/assets/{RunProgress-Cr_6TBaF.js → RunProgress-BbzwzrTK.js} +2 -2
  75. package/packages/web/dist/assets/{RunsView-tU350TPK.js → RunsView-so-UV2Cq.js} +2 -2
  76. package/packages/web/dist/assets/{SettingsPage-B8QmmMN3.js → SettingsPage-B4SQLk09.js} +2 -2
  77. package/packages/web/dist/assets/{SignInPage-DTwdqlnB.js → SignInPage-Ck-v3eH0.js} +2 -2
  78. package/packages/web/dist/assets/{StatusBadge-D7wKMAcD.js → StatusBadge-C4NawPsO.js} +2 -2
  79. package/packages/web/dist/assets/{StorePlacementStep-C04nRU-u.js → StorePlacementStep-DjLWeQF9.js} +2 -2
  80. package/packages/web/dist/assets/{SystemConfig-CE3keXWq.js → SystemConfig-B5C5B3b0.js} +2 -2
  81. package/packages/web/dist/assets/{SystemPageHost-CEhz4li8.js → SystemPageHost-DoyQlhKM.js} +2 -2
  82. package/packages/web/dist/assets/{SystemView-CBFzEGfm.js → SystemView-CTdpay8I.js} +2 -2
  83. package/packages/web/dist/assets/{SystemsView-0G8JntMV.js → SystemsView-Cnv2moRw.js} +2 -2
  84. package/packages/web/dist/assets/{TableView-BK0uwLHl.js → TableView-BK_95qHT.js} +3 -3
  85. package/packages/web/dist/assets/{TableViewer-nbMInGJJ.js → TableViewer-CRsIxdku.js} +2 -2
  86. package/packages/web/dist/assets/{ThemePicker-fZpVSYqG.js → ThemePicker-BlW7qvUd.js} +2 -2
  87. package/packages/web/dist/assets/{TurnTree-Co-iBqhT.js → TurnTree-D6OYRutQ.js} +2 -2
  88. package/packages/web/dist/assets/{UserMessage-CDjUxKY0.js → UserMessage-DJH2bXqv.js} +2 -2
  89. package/packages/web/dist/assets/{ValueVisual-EJnCKgSy.js → ValueVisual-BJUrdkHO.js} +2 -2
  90. package/packages/web/dist/assets/{fn-modal-DtE65mFt.js → fn-modal-DFtN7Kn-.js} +2 -2
  91. package/packages/web/dist/assets/{fn-notices-CCZ-DFbi.js → fn-notices-C8HXeo7m.js} +2 -2
  92. package/packages/web/dist/assets/{formats-CyHV2siv.js → formats-CHSYhY4X.js} +2 -2
  93. package/packages/web/dist/assets/{index-OZS2EluT.js → index-Uz-h2M5K.js} +3 -3
  94. package/packages/web/dist/assets/{labels-CT7_K0Pt.js → labels-DkV96Md_.js} +2 -2
  95. package/packages/web/dist/assets/{layout-B6fBDg80.js → layout-CTAHAwIH.js} +2 -2
  96. package/packages/web/dist/assets/{loaded-LaPjk6mK.js → loaded-BrwmsuZY.js} +2 -2
  97. package/packages/web/dist/assets/{metrics-9n8bKI7u.js → metrics-BBvD6KSk.js} +2 -2
  98. package/packages/web/dist/assets/{problems--AW4igVY.js → problems-CI9huk1n.js} +2 -2
  99. package/packages/web/dist/assets/{push-payload-B3EcrsVz.js → push-payload-C1ppI5V2.js} +61 -61
  100. package/packages/web/dist/assets/{record-edits-B-FWAbxR.js → record-edits-DFJBcNnL.js} +2 -2
  101. package/packages/web/dist/assets/{review-uLESCEz1.js → review-DlP8FQiO.js} +2 -2
  102. package/packages/web/dist/assets/{routes-B7Zmt8wh.js → routes-oIISbS5Z.js} +4 -4
  103. package/packages/web/dist/assets/{runs-CUb2PTFg.js → runs-BWVBevgu.js} +2 -2
  104. package/packages/web/dist/assets/{shared-Bxhw_9et.js → shared-Bc4GJbiE.js} +2 -2
  105. package/packages/web/dist/assets/{sources-YgkjgFLe.js → sources-gONU9kk2.js} +2 -2
  106. package/packages/web/dist/assets/{src-DY1fSFJS.js → src-ClMFVauH.js} +2 -2
  107. package/packages/web/dist/assets/{state-ChQDWWj-.js → state-BQlvjJzT.js} +2 -2
  108. package/packages/web/dist/assets/{systems-CjwjRySu.js → systems-Dt01wDhP.js} +2 -2
  109. package/packages/web/dist/assets/{table-host-B_D9dmCz.js → table-host-BvEY0Zxn.js} +2 -2
  110. package/packages/web/dist/assets/{tables-CaxIuHdw.js → tables-CkqGZ0Yq.js} +2 -2
  111. package/packages/web/dist/assets/{ui-DWjytmDS.js → ui-CjoSgSyZ.js} +2 -2
  112. package/packages/web/dist/assets/{url-DbGOI14W.js → url-Deh5u3O5.js} +2 -2
  113. package/packages/web/dist/index.html +40 -40
  114. package/packages/web/dist/sw.js +1 -1
  115. package/packages/web/package.json +2 -2
  116. package/premade/claude.zip +0 -0
  117. package/premade/database.zip +0 -0
  118. package/premade/web.zip +0 -0
  119. package/systems/api/package.json +3 -3
  120. package/systems/code/package.json +3 -3
  121. package/systems/embedder/package.json +1 -1
  122. package/systems/fs/client/machines/files/CommentComposer.vue +6 -3
  123. package/systems/fs/client/machines/files/FilePane.vue +2 -2
  124. package/systems/fs/package.json +3 -3
  125. package/systems/fs/server/metrics/os.ts +50 -29
  126. package/systems/google-calendar/package.json +1 -1
  127. package/systems/input/package.json +3 -3
  128. package/systems/mcp/package.json +3 -3
  129. package/systems/ollama/package.json +3 -3
  130. package/systems/schedule/package.json +3 -3
  131. package/systems/template/package.json +1 -1
  132. package/systems/widgets/package.json +3 -3
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/shared-Bxhw_9et.js","assets/rolldown-runtime-COiEfhsA.js","assets/runtime-core.esm-bundler-wlpNGAAZ.js","assets/src-DY1fSFJS.js","assets/push-payload-B3EcrsVz.js","assets/core-DdF778CY.js","assets/langs-CVIiVMBh.js","assets/preload-helper-7y9sWmk5.js","assets/mermaid.core-BNF3dRf5.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/chunk-DUW6YSOI-Dgx8z5s3.js","assets/chunk-M57EVK23-qYz6TUV4.js","assets/chunk-LEVMRMFU-paszafIt.js","assets/chunk-AXFCVDMN-CI0arS1F.js","assets/chunk-X4PVCEUW-YYhMSieL.js","assets/chunk-BG4553SI-DGn4S0JL.js","assets/d3-selection-COWvaQNI.js","assets/chunk-STOXU5M4-D5Gd-wq9.js","assets/chunk-R3KSYZAL-DW0WB_9q.js","assets/chunk-6MUBBAK2-BHXbrulB.js","assets/dist-DdXDFcej.js","assets/chunk-J5ZVWO5B-oDCd-gWO.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-DQASFODM-ClbbgMVy.js"])))=>i.map(i=>d[i]);
2
- import{C as e,E as t,O as n,c as r,h as i,i as a,l as o,q as s,x as c,y as l}from"./src-DY1fSFJS.js";import{Ar as u,At as d,Cr as f,Ct as p,Dr as m,Kt as h,Or as g,Tt as _,Ut as ee,Vt as te,ct as ne,f as re,i as v,jr as ie,kr as ae,l as oe,lr as se,lt as ce,mr as le,o as y,ot as ue,s as de,u as fe,wr as pe,wt as me,y as he}from"./routes-B7Zmt8wh.js";import{$ as ge,D as b,E as x,Ft as _e,Ht as S,Lt as ve,On as C,St as ye,T as be,Zn as w,_ as T,an as xe,b as E,bt as D,ct as Se,er as Ce,et as we,fn as O,g as k,gn as Te,gt as Ee,it as De,k as A,mt as j,o as M,pn as Oe,qt as N,tr as P,tt as ke,v as F,vn as I,w as Ae,wt as je,xn as L,xt as Me,y as R}from"./runtime-core.esm-bundler-wlpNGAAZ.js";import{n as Ne}from"./RunCard-C7wOGaw8.js";import{a as Pe,o as Fe}from"./TableView-BK0uwLHl.js";import{t as Ie}from"./ConfirmDialog-BDvLleYf.js";import{t as Le}from"./FactList-CeAbKajD.js";import{t as Re}from"./LoadState-B2YhZlyC.js";import{t as ze}from"./AppPage-BvoVTk6h.js";import{A as Be,C as Ve,D as He,S as Ue,_ as We,b as Ge,d as Ke,f as qe,g as Je,h as Ye,i as Xe,j as Ze,k as Qe,o as $e,p as et,r as tt,s as nt,t as rt,u as it,w as at,x as ot,y as st}from"./UserMessage-CDjUxKY0.js";import{d as z,i as ct,l as lt,r as ut,u as B}from"./labels-CT7_K0Pt.js";import{t as dt}from"./FnPill-CbLZCXYM.js";import{t as ft}from"./GinForm-CXjYVf2_.js";import{t as pt}from"./GinValueView-CWUzS7ti.js";import{l as mt,n as ht,r as gt,t as _t}from"./ResourceViewer-C4tRColf.js";import{A as vt,C as yt,D as bt,F as xt,G as St,H as V,I as Ct,L as wt,M as Tt,N as Et,O as Dt,P as Ot,R as kt,S as At,U as jt,V as Mt,W as Nt,X as Pt,Y as Ft,_ as It,a as Lt,b as Rt,f as zt,i as Bt,j as Vt,l as Ht,n as Ut,o as Wt,p as Gt,q as Kt,r as qt,t as Jt,v as Yt,z as H}from"./ui-DWjytmDS.js";import{n as U,t as W}from"./loaded-LaPjk6mK.js";import{r as Xt,t as Zt}from"./fn-notices-CCZ-DFbi.js";import{G as Qt,H as $t,V as en,z as tn}from"./state-ChQDWWj-.js";import{t as nn}from"./now-40JhSjx0.js";import{n as G,r as rn,t as an}from"./stores-BMEvTe-I.js";import{$a as on,Ao as sn,Br as cn,Ci as ln,Di as un,Dt as dn,Ei as fn,En as pn,Fo as mn,Fr as hn,Ho as gn,Ht as _n,Ia as vn,Ir as yn,Jr as bn,Kn as xn,Kr as Sn,Lo as Cn,Lr as wn,Ma as Tn,Mo as En,Q as Dn,Qa as On,Qn as kn,Ro as K,S as An,Sn as jn,Sr as Mn,Uo as Nn,Ut as Pn,Va as Fn,Vo as q,Vt as In,Wn as Ln,Wo as Rn,Wr as zn,Xa as Bn,Ya as Vn,Yr as Hn,Za as Un,Zr as Wn,at as Gn,dr as Kn,eo as qn,io as Jn,jo as Yn,ko as Xn,l as Zn,ot as Qn,qa as $n,qr as er,ra as tr,ro as nr,tn as rr,u as ir,ui as ar,wr as J}from"./push-payload-B3EcrsVz.js";import{A as or,C as sr,E as cr,a as lr,f as ur,h as dr,r as fr,s as pr,x as mr}from"./runs-CUb2PTFg.js";import{t as Y}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{n as hr,r as gr,t as _r}from"./fn-modal-DtE65mFt.js";import{b as vr,f as yr,g as br,r as xr,s as Sr,v as Cr}from"./systems-CjwjRySu.js";import{a as wr,i as Tr,n as Er,r as Dr,t as Or}from"./metrics-9n8bKI7u.js";import{n as kr,t as Ar}from"./ItemHistory-dbGgOZsw.js";import{i as jr,n as Mr,r as Nr,t as Pr}from"./InjectedList-e6qr1kdU.js";import{i as X,n as Z,r as Fr,t as Ir}from"./problems--AW4igVY.js";import{t as Lr}from"./sources-YgkjgFLe.js";import{t as Rr}from"./RendererHost-rjnpSgyQ.js";import{t as zr}from"./RunDot-C46uzzNM.js";import{c as Br,l as Vr,n as Hr,s as Ur,t as Wr}from"./layout-B6fBDg80.js";import{C as Gr,T as Kr,d as qr,j as Jr,u as Yr}from"./review-uLESCEz1.js";import{v as Xr}from"./tables-CaxIuHdw.js";import{o as Zr,s as Qr}from"./record-edits-B-FWAbxR.js";import{a as $r,i as ei,o as ti}from"./formats-CyHV2siv.js";import{t as ni}from"./preload-helper-7y9sWmk5.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ri=A({__name:`PageApproval`,props:{approval:{},inChat:{type:Boolean,default:!1},description:{default:``}},emits:[`decide`],setup(e,{emit:t}){let n=t;return(t,r)=>(j(),F(Xt,{ident:e.approval.id,"data-approval":e.approval.id,fn:e.approval.fn,description:e.description,args:void 0,preview:e.approval.preview,rememberable:e.inChat&&C(Qe)(e.approval),ask:e.approval.ask,onDecide:r[0]||=(e,t,r,i)=>n(`decide`,e,t,r,i)},null,8,[`ident`,`data-approval`,`fn`,`description`,`preview`,`rememberable`,`ask`]))}}),ii=A({__name:`PageComposer`,props:{modelValue:{},placeholder:{default:`Message`},sending:{type:Boolean,default:!1},running:{type:Boolean,default:!1},stopping:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},note:{default:``}},emits:[`update:modelValue`,`send`,`stop`],setup(e,{emit:t}){let n=e,r=t,i=Qt(),a=nn(),o={open:!1,kind:void 0,items:[],active:0,loading:!1},s={available:!1,state:`idle`,startedAt:0,problem:``},c={shown:!1,on:!1};function l(e){e===`cancel`&&r(`stop`)}return(t,u)=>(j(),F(We,{text:e.modelValue,placeholder:e.placeholder,tokens:[],"can-send":!n.disabled&&e.modelValue.trim()!==``,sending:e.sending,running:e.running,paused:!1,stopping:e.stopping,"immediate-stop":``,picker:o,files:[],"reply-all":c,answerers:``,"can-attach":!1,voice:s,now:C(a),touch:C(i),note:e.note,onInput:u[0]||=e=>r(`update:modelValue`,e),onSend:u[1]||=e=>r(`send`),onControl:u[2]||=e=>l(e)},null,8,[`text`,`placeholder`,`can-send`,`sending`,`running`,`stopping`,`now`,`touch`,`note`]))}}),ai=Bn.parse(`ses_page`),oi=Tn.parse(`act_page-agent`);function si(e,t){let n=`${e}/${t.name}`,r={...pr(Vn.parse(`run_${t.key}`),n,t.status),args:t.args};switch(t.status){case`running`:return r;case`done`:return{...r,outcome:{status:`done`,result:t.output??``}};case`failed`:return{...r,outcome:{status:`failed`,error:{class:`fatal`,code:`failed`,message:t.output===void 0||t.output.trim()===``?`It failed.`:t.output}}}}}function ci(e,t,n,r,i,a,o){return{id:Fn.parse(`msg_${e}`),session:ai,turn:on.parse(`trn_${e}`),author:t,role:n,parts:r===``?[]:[{type:`text`,text:r}],runs:[...a],status:o?`streaming`:`done`,replyAll:!1,answerers:[],createdAt:i??0}}function li(e,t){let n=[];return{segments:t.reduce((t,r)=>{if(r.kind!==`call`)return r.text.trim()===``?t:$e(t,{kind:r.kind,text:r.text});let i=si(e,r.call);return n.push(i),$e(t,{kind:`runs`,runs:[i.id]})},[]),runs:n}}function ui(e,t){let n=e.findLastIndex(e=>e.kind===`answer`);return e.map((e,r)=>{switch(e.kind){case`user`:return{kind:`user`,key:e.key,message:ci(e.key,t.me,`user`,e.text,e.at,[],!1)};case`note`:return{kind:`note`,key:e.key,message:ci(e.key,oi,`note`,e.text,void 0,[],!1)};case`answer`:{let{segments:i,runs:a}=li(t.system,e.pieces),o=e.pieces.flatMap(e=>e.kind===`text`?[e.text]:[]).join(``),s=t.streaming&&r===n;return{kind:`answer`,key:e.key,message:ci(e.key,oi,`assistant`,o,e.at,a.map(e=>e.id),s),segments:i,runs:a}}}})}var di={class:`conversation`,"data-testid":`conversation`},fi=Y(A({__name:`PageConversation`,props:{entries:{},agent:{},system:{},streaming:{type:Boolean,default:!1}},setup(e){let t=e,{session:n}=G(),r=nn(),i=k(()=>n.user.value?.id??oi),a=k(()=>ui(t.entries,{system:t.system,me:i.value,streaming:t.streaming})),o={context:[],fns:[]},s=I(new Set),c=e=>!s.value.has(e.id);function l(e){u([e],!s.value.has(e))}function u(e,t){let n=new Set(s.value);for(let r of e)t?n.add(r):n.delete(r);s.value=n}return(t,i)=>(j(),E(`div`,di,[(j(!0),E(M,null,D(a.value,t=>(j(),E(M,{key:t.key},[t.kind===`user`?(j(),F(rt,{key:0,message:t.message,mine:``,"author-name":C(n).user.value?.name??`You`,now:C(r),"command-name":e=>e,suggestions:o,actions:[]},null,8,[`message`,`author-name`,`now`,`command-name`])):t.kind===`note`?(j(),F(tt,{key:1,message:t.message},null,8,[`message`])):(j(),F(Xe,{key:2,messages:[t.message],"author-name":e.agent,now:C(r),streaming:t.message.status===`streaming`,failed:!1,"runs-of":()=>t.runs,"live-of":()=>t.segments,collapsed:c,"view-of":()=>void 0,"attachment-view":()=>void 0,actions:[],onRunOpen:i[0]||=e=>l(e),onRunToggle:i[1]||=(e,t)=>u([e],!t),onCollapseAll:e=>u(t.runs.map(e=>e.id),!e)},null,8,[`messages`,`author-name`,`now`,`streaming`,`runs-of`,`live-of`,`onCollapseAll`]))],64))),128))]))}}),[[`__scopeId`,`data-v-aa0c3db3`]]),pi={class:`fns`,"data-testid":`fns`},mi={key:1,class:`mark`,"aria-hidden":`true`},hi={class:`main`},gi={class:`top`},_i=[`onClick`],vi={class:`name`},yi=[`title`],bi={class:`description`},xi={class:`chips`},Si={class:`runs`},Ci={key:0,class:`dim detail`},wi={key:1,class:`dim`},Ti=Y(A({__name:`FnList`,props:{fns:{},now:{},runsOf:{type:Function},switchable:{type:Boolean}},emits:[`switch`,`switched`],setup(e,{emit:t}){let n=e,r=t,i=gr();i?.within({switched:(e,t)=>{r(`switched`,e,t)}});let a=k(()=>{let[e,...t]=n.fns;return e===void 0||t.length===0?{runtime:!1,tags:new Set}:{runtime:n.fns.every(e=>e.origin===`runtime`),tags:new Set(e.decl.tags.filter(e=>t.every(t=>t.decl.tags.includes(e))))}}),o=e=>xn(e.stats.outcomes);return(t,n)=>{let s=ye(`RouterLink`);return j(),E(`ul`,pi,[(j(!0),E(M,null,D(e.fns,t=>(j(),E(`li`,{key:t.name,class:w([`fn`,{off:t.available!==!0}])},[e.switchable?(j(),F(C(Ht),{key:0,class:`switch`,"model-value":!t.disabled,label:`Use ${C(J)(t.name)}`,"hide-label":``,"data-testid":`fn-switch`,"onUpdate:modelValue":e=>r(`switch`,t.name,e)},null,8,[`model-value`,`label`,`onUpdate:modelValue`])):(j(),E(`span`,mi,[b(C(Ft),{name:`fn`,size:16})])),T(`div`,hi,[T(`p`,gi,[T(`button`,{type:`button`,class:`label`,"data-testid":`fn-page`,onClick:e=>C(i)?.open(t.name)},P(C(J)(t.name)),9,_i),T(`code`,vi,P(t.name),1),T(`code`,{class:`name`,title:`Version ${t.version}`,"data-testid":`fn-version`},`v `+P(C(br)(t.version)),9,yi)]),T(`p`,bi,P(t.decl.description),1),T(`p`,xi,[t.available===!0?R(``,!0):(j(),F(C(V),{key:0,tone:`warn`,title:t.available.detail},{default:N(()=>[x(P(C(Sr)(t.available)),1)]),_:2},1032,[`title`])),t.paused?(j(),F(C(V),{key:1},{default:N(()=>[...n[0]||=[x(`Paused`,-1)]]),_:1})):R(``,!0),C(yr)(t.decl)?(j(),F(C(V),{key:2,tone:`warn`,title:C(xr),"data-testid":`fn-no-examples`},{default:N(()=>[...n[1]||=[x(`No examples`,-1)]]),_:1},8,[`title`])):R(``,!0),t.origin===`runtime`&&!a.value.runtime?(j(),F(C(V),{key:3,tone:`accent`},{default:N(()=>[...n[2]||=[x(`Added while running`,-1)]]),_:1})):R(``,!0),(j(!0),E(M,null,D(t.decl.tags.filter(e=>!a.value.tags.has(e)),e=>(j(),F(C(V),{key:e},{default:N(()=>[x(P(e),1)]),_:2},1024))),128))])]),b(s,{class:`stats`,to:e.runsOf(t.name),title:t.stats.lastRunAt===void 0?`Never run`:`Last run ${C(St)(t.stats.lastRunAt)}`},{default:N(()=>[T(`span`,Si,P(o(t).toLocaleString())+` `+P(o(t)===1?`run`:`runs`),1),o(t)>0?(j(),E(`span`,Ci,[x(P([C(Er)(t.stats.outcomes),C(Tr)(t.stats.outcomes),C(z)(t.stats.averageTime)].filter(e=>e!==``).join(` · `)),1),t.stats.p95===void 0?R(``,!0):(j(),E(M,{key:0},[x(` (p95 `+P(C(z)(t.stats.p95))+`)`,1)],64)),x(` · `+P(C(B)(t.stats.averageCost)),1)])):R(``,!0),t.stats.lastRunAt===void 0?R(``,!0):(j(),E(`span`,wi,`last `+P(C(Kt)(t.stats.lastRunAt,e.now)),1))]),_:2},1032,[`to`,`title`])],2))),128))])}}}),[[`__scopeId`,`data-v-45377503`]]),Ei=A({__name:`PageFnList`,props:{fns:{}},setup(e){let t=nn();return(n,r)=>(j(),F(Ti,{fns:e.fns,now:C(t),"runs-of":C(y).fnRuns},null,8,[`fns`,`now`,`runs-of`]))}}),Di=e=>e in Pt;function Oi(e){return e!==void 0&&Di(e)?e:`layers`}function ki(e){return e.filter(e=>e.nav===`main`&&e.area!==`admin`).map(e=>({system:e.system,segment:e.segment,title:e.title,icon:Oi(e.icon)}))}function Ai(e){let t=Un.safeParse(e.system),n=e.page;if(!t.success||typeof n!=`string`)return;let r=e.path,i=Array.isArray(r)?r:typeof r==`string`&&r!==``?[r]:[];return{system:t.data,page:n,path:i}}function ji(e){return Object.fromEntries(Object.entries(e).flatMap(([e,t])=>{let n=Array.isArray(t)?t[0]:t;return typeof n==`string`?[[e,n]]:[]}))}function Mi(e){return e.area??`app`}function Ni(e){if(`fn`in e)return y.fn(e.fn);if(`instance`in e){let t=Un.parse(e.instance.system);return y.instance(t,vn.parse(e.instance.instance))}return`connect`in e?y.connect(Un.parse(e.connect)):`resources`in e?y.resources({under:e.resources.under}):y.contextItem(e.context)}function Pi(e){let t=t=>{let n=e.here(),r=t.page??n.page,i=t.path??(r===n.page?n.path:[]);return y.systemPage(n.system,r,i,t.query??{},n.area)},n=(t,n)=>{let r=e.here();e.navigate(y.systemPage(r.system,r.page,r.path,{...r.query,...t},r.area),!n)};return{get user(){return e.user()},hub:e.hub,query:{get values(){return e.here().query},get:t=>e.here().query[t],set:(e,t)=>{n(e,t?.push===!0)},bind:(t,r=``)=>({get value(){return e.here().query[t]??r},set value(e){n({[t]:e===r?void 0:e},!1)}})},href:n=>e.resolve(t(n)),chatHref:t=>e.chatHref(t),goChat:t=>{e.goChat(t)},runHref:t=>e.runHref(t),goRun:t=>{e.goRun(t)},go:(n,r)=>{e.navigate(t(n),r?.replace===!0)},openChat:t=>e.openChat(t),components:e.components,runs:t=>e.runs(t),inbox:e.inbox,notify:e.notify,format:e.format,live:(t,n)=>{e.live(t,n)}}}function Fi(e){return{components:e.components,href:t=>e.resolve(Ni(t)),go:t=>{e.navigate(Ni(t),!1)},bytes:e.bytes}}function Ii(e,t){return t.some(t=>t.system===e.system)?{title:`No such page`,body:`${e.system} has no page called “${e.page}”. It may have been renamed in a newer version.`}:{title:`${e.system} isn’t installed`,body:`This page belongs to the ${e.system} system, which isn’t installed and live here, or you can’t use it. The link will work again once it is.`}}var Li=A({__name:`PageIconButton`,props:{icon:{},label:{},size:{default:`md`},disabled:{type:Boolean,default:!1}},emits:[`click`],setup(e){let t=e,n=k(()=>Oi(t.icon));return(t,r)=>(j(),F(C(Ct),{icon:n.value,label:e.label,size:e.size,disabled:e.disabled,onClick:r[0]||=e=>t.$emit(`click`,e)},null,8,[`icon`,`label`,`size`,`disabled`]))}}),Ri=Object.freeze({Frame:O(ze),Input:O(Rt),Markdown:O(Jt),Icon:O(Ft),Empty:O(At),LoadState:O(Re),Reasoning:O(Ze),Typing:O(Be),ResourceViewer:O(_t),ValueEditor:O(pt),Button:O(H),Select:O(zt),Textarea:O(Lt),Dialog:O(yt),Popover:O(Yt),Form:O(ft),Banner:O(Mt),Badge:O(V),Skeleton:O(Dt),FnPill:O(dt),Approval:O(ri),Conversation:O(fi),Composer:O(ii)}),zi=Object.freeze({Tabs:O(Wt),Segmented:O(Gt),Switch:O(Ht),ChipInput:O(wt),IconButton:O(Li),Card:O(kt),FnList:O(Ei),Facts:O(Le),Confirm:O(Ie)}),Bi=Object.freeze({cost:B,relativeTime:(e,t)=>Kt(e,t),fullTime:e=>St(e)}),Vi=e=>lt(e),Hi=[7,30,90];function Ui(e,t){let{system:n,local:r}=Jn(e);return t===0?`${n} has no fns on this hub now (it may be uninstalled or not connected yet), so ${e} can't be shown.`:`${n} has no fn named ${r} now. It may have been removed or renamed since it ran.`}var Wi=class{#e;#t;#n;name=I(void 0);days=I(7);record=new W;metrics=new W;daily=new W;recent=new W;switching=new U;constructor(e,t){this.#e=e,this.#t=t}async open(e,t){let n=this.name.value===e;n||this.close(),this.name.value=e,this.days.value=t,this.#n??=this.#t(e=>{this.#a(e)}),await Promise.all([this.#r(e,n),this.#i(e,t,n&&this.metrics.value.value!==void 0)])}async switchOn(e){let t=this.record.value.value;return t!==void 0&&(this.record.set({...t,disabled:!e}),(await this.switching.run(()=>this.#e.switchItem.call({section:`fns`,name:t.name,on:e}),`Couldn't switch that.`)).ok?!0:(this.record.set(t),!1))}close(){this.#n?.(),this.#n=void 0,this.name.value=void 0,this.record.reset(),this.metrics.reset(),this.daily.reset(),this.recent.reset()}async#r(e,t){let n=Un.parse(Jn(e).system);await this.record.load(async()=>{let t=await this.#e.systemFns.call({system:n}),r=t.find(t=>t.name===e);if(r===void 0)throw new Ir(Ui(e,t.length));return r},`Couldn't load this fn.`,t)}async#i(e,t,n){await Promise.all([this.metrics.load(async()=>(await this.#e.fnMetrics.call({fn:e,days:t})).find(t=>t.fn===e),`Couldn't load this fn's metrics.`,n),this.daily.load(()=>this.#e.fnMetricsDays.call({fn:e,days:t}),`Couldn't load this fn's days.`,n),this.recent.load(async()=>(await this.#e.runs.call({query:{filters:[{field:`fn`,op:`is`,value:e}],limit:8}})).items,`Couldn't load this fn's runs.`,n)])}#a(e){let t=this.name.value;if(e.type!==`fn`||t===void 0||e.fn!==t)return;let n=this.record.value.value;n!==void 0&&this.record.set({...n,stats:e.stats}),this.#i(t,this.days.value,!0)}},Gi=[`data-testid`],Ki={class:`title`},qi=[`aria-label`],Ji={class:`scale top`},Yi={class:`columns`},Xi=[`aria-label`,`data-day`,`onPointerenter`,`onFocus`],Zi={class:`labels`,"aria-hidden":`true`},Qi={class:`table`},$i=Y(A({__name:`DayBars`,props:{title:{},bars:{},format:{},testid:{default:`day-bars`}},setup(e){let t=e,n=k(()=>wr(Math.max(0,...t.bars.map(e=>e.value)))),r=I(void 0),i=k(()=>Math.max(1,Math.ceil(t.bars.length/7))),a=k(()=>r.value===void 0?void 0:t.bars[r.value]);return(t,o)=>(j(),E(`figure`,{class:`day-bars`,"data-testid":e.testid},[T(`figcaption`,Ki,P(e.title),1),T(`div`,{class:`plot`,role:`img`,"aria-label":`${e.title}: ${e.bars.map(t=>`${t.label} ${e.format(t.value)}`).join(`, `)}`,onPointerleave:o[1]||=e=>r.value=void 0},[T(`span`,Ji,P(e.format(n.value)),1),o[2]||=T(`span`,{class:`scale zero`},`0`,-1),o[3]||=T(`div`,{class:`grid`,"aria-hidden":`true`},null,-1),T(`div`,Yi,[(j(!0),E(M,null,D(e.bars,(e,t)=>(j(),E(`button`,{key:e.day,type:`button`,class:w([`column`,{pointed:r.value===t}]),"aria-label":`${e.label}: ${e.lines.join(`, `)}`,"data-day":e.day,onPointerenter:e=>r.value=t,onFocus:e=>r.value=t,onBlur:o[0]||=e=>r.value=void 0},[T(`span`,{class:`bar`,style:Ce({height:`${e.value<=0?0:Math.max(2,e.value/n.value*100)}%`})},null,4)],42,Xi))),128))]),a.value&&r.value!==void 0?(j(),E(`div`,{key:0,class:`tip`,role:`status`,style:Ce({left:`${Math.min(80,Math.max(20,(r.value+.5)/e.bars.length*100))}%`})},[T(`strong`,null,P(a.value.label),1),(j(!0),E(M,null,D(a.value.lines,e=>(j(),E(`span`,{key:e},P(e),1))),128))],4)):R(``,!0)],40,qi),T(`div`,Zi,[(j(!0),E(M,null,D(e.bars,(e,t)=>(j(),E(`span`,{key:e.day,class:`label`},P(t%i.value===0?e.label:``),1))),128))]),T(`details`,Qi,[o[5]||=T(`summary`,null,`As a table`,-1),T(`table`,null,[T(`thead`,null,[T(`tr`,null,[o[4]||=T(`th`,null,`Day`,-1),T(`th`,null,P(e.title),1)])]),T(`tbody`,null,[(j(!0),E(M,null,D(e.bars,e=>(j(),E(`tr`,{key:e.day},[T(`td`,null,P(e.label),1),T(`td`,null,P(e.lines.join(` · `)),1)]))),128))])])])],8,Gi))}}),[[`__scopeId`,`data-v-94fb9c63`]]),ea={class:`stats`,"data-testid":`fn-stats`},ta={class:`period`},na={class:`period-title`},ra={key:0,class:`strip`,"data-testid":`fn-metrics`},ia=[`data-figure`],aa={class:`label`},oa={class:`value`},sa={key:0,class:`detail`},ca=Y(A({__name:`FnStats`,props:ge({metrics:{},daily:{},loading:{type:Boolean},problem:{},now:{},compact:{type:Boolean}},{days:{required:!0},daysModifiers:{}}),emits:ge([`retry`],[`update:days`]),setup(e,{emit:t}){let n=e,r=_e(e,`days`),i=t,a=Hi.map(e=>({value:String(e),label:`${String(e)} days`})),o=k({get:()=>String(r.value),set:e=>{r.value=Hi.find(t=>String(t)===e)??7}}),s=k(()=>n.metrics===void 0?[]:Dr(n.metrics)),c=k(()=>({period:r.value,now:n.now})),l=k(()=>Or(n.daily,`runs`,c.value)),u=k(()=>Or(n.daily,`time`,c.value));return(t,n)=>(j(),E(`section`,ea,[T(`div`,ta,[T(`h2`,na,`Over the last `+P(r.value)+` days`,1),b(C(Gt),{modelValue:o.value,"onUpdate:modelValue":n[0]||=e=>o.value=e,options:C(a),label:`Period`,"data-testid":`fn-period`},null,8,[`modelValue`,`options`])]),b(Re,{loading:e.loading,problem:e.problem,ready:e.metrics!==void 0||!e.loading,empty:!1,onRetry:n[1]||=e=>i(`retry`)},{default:N(()=>[e.metrics?(j(),E(`ul`,ra,[(j(!0),E(M,null,D(s.value,e=>(j(),E(`li`,{key:e.key,class:`figure`,"data-figure":e.key},[T(`span`,aa,P(e.label),1),T(`span`,oa,P(e.value),1),e.detail?(j(),E(`span`,sa,P(e.detail),1)):R(``,!0)],8,ia))),128))])):(j(),F(C(At),{key:1,icon:`fn`,title:`No runs in this period`,body:`Its numbers show here once it runs.`})),l.value.length>0?(j(),E(`div`,{key:2,class:w([`charts`,{compact:e.compact}])},[b(C(kt),null,{default:N(()=>[b($i,{title:`Runs per day`,bars:l.value,format:e=>e.toLocaleString(),testid:`fn-runs-chart`},null,8,[`bars`,`format`])]),_:1}),b(C(kt),null,{default:N(()=>[b($i,{title:`Typical time per day`,bars:u.value,format:C(z),testid:`fn-time-chart`},null,8,[`bars`,`format`])]),_:1})],2)):R(``,!0)]),_:1},8,[`loading`,`problem`,`ready`])]))}}),[[`__scopeId`,`data-v-3e1752f2`]]),la={key:0,class:`problem`},ua={key:2,class:`note`,"data-testid":`access-fixed`},da={key:3,class:`problem`,role:`alert`},fa=Y(A({__name:`AccessControl`,props:{target:{},label:{default:`Who can use it`},title:{default:`Sharing`},compact:{type:Boolean,default:!1},fixed:{default:void 0}},setup(e){let t=e,n=rn(),r=n?.chat.access,i=Lr().people(),a=L(void 0),o=k(()=>r?.multiUser.value===!0);Se(()=>{r?.load()}),S([()=>Ln(t.target),o],([,e])=>{a.value=e&&r!==void 0?r.view(t.target):void 0},{immediate:!0});let s=k(()=>a.value?.value.value?.sharing.owner),c=L(``);S(s,async e=>{if(c.value=``,e===void 0||e===n?.session.user.value?.id)return;let[t]=await i.label([e]).catch(()=>[]);s.value===e&&(c.value=t===void 0||t.missing===!0?`its owner`:t.label)},{immediate:!0});let l=k({get:()=>{if(t.fixed!==void 0)return{visibility:`private`,with:[]};let e=a.value?.value.value?.sharing;return e===void 0?void 0:{visibility:e.visibility,with:e.with}},set:e=>{e!==void 0&&u(e)}});async function u(e){if(r===void 0||a.value===void 0)return;let n=await r.set(t.target,e);n.ok&&a.value.set(n.value)}return(t,n)=>o.value&&a.value!==void 0?(j(),F(kt,{key:0,title:e.title,compact:e.compact,"data-testid":`access-control`},{default:N(()=>[a.value.problem.value===``?l.value===void 0?R(``,!0):(j(),F(qt,{key:1,modelValue:l.value,"onUpdate:modelValue":n[0]||=e=>l.value=e,people:C(i),label:e.label,owner:c.value,readonly:e.fixed!==void 0||a.value.value.value?.editable===!1},null,8,[`modelValue`,`people`,`label`,`owner`,`readonly`])):(j(),E(`p`,la,P(a.value.problem.value),1)),e.fixed===void 0?R(``,!0):(j(),E(`p`,ua,P(e.fixed),1)),C(r)?.saving.problem.value?(j(),E(`p`,da,P(C(r).saving.problem.value),1)):R(``,!0)]),_:1},8,[`title`,`compact`])):R(``,!0)}}),[[`__scopeId`,`data-v-9e92a917`]]);async function pa(e,t){let n=await e.chat.sessions.create({title:t.title});if(n===void 0)throw Error(e.chat.sessions.problem.value||`Couldn't start a chat.`);if(t.run!==void 0){let r=e.chat.thread(n);if(await r.invoke(t.run.fn,t.run.args)===void 0)throw Error(r.problem.value||`Couldn't run that.`)}return await e.push(y.session(n)),n}function ma(){let{chat:e,toasts:t}=G(),n=ie(),r=I(``);async function i(i){r.value=i;try{await pa({chat:e,push:e=>n.push(e)},{title:J(i),run:{fn:i,args:{}}})}catch(e){t.error(`Couldn't open it in a chat`,e instanceof Error?e.message:String(e))}finally{r.value=``}}return{opening:r,open:i}}var ha={read:{label:`Reads`,about:`Only reads: nothing is changed.`},write:{label:`Writes`,about:`Adds or changes things.`},delete:{label:`Deletes`,about:`Can remove things.`}},ga={read:`neutral`,write:`warn`,delete:`danger`},_a={free:`Spends nothing`,history:`From its runs`,payload:`From the call and the model’s price`,unknown:`Spends, never run yet`};function va(e){return e.basis===`free`?`Free`:e.basis===`unknown`?`Unknown`:e.min===e.max?B(e.typical):`${B(e.typical)} (${B(e.min)}–${B(e.max)})`}function ya(e){let t=[{key:`cost`,label:`Cost a call`,value:va(e.cost),detail:_a[e.cost.basis]}],n=e.times;return n!==void 0&&n.runs>0&&t.push({key:`time`,label:`Typical time`,value:z(n.typical),detail:`The median run`},{key:`slow`,label:`Slow runs`,value:z(n.slow),detail:`Longest ${z(n.longest)}`}),t.push({key:`runs`,label:`Runs`,value:(n?.runs??e.cost.runs).toLocaleString(),detail:`Settled, all time`}),t}function ba(e){let t=JSON.stringify(e);return t.length<=80?t:JSON.stringify(e,null,2)}function xa(e,t){return`${e}(${ba(t.args)})`}var Sa=Xn([`readable`,`stored`]);function Ca(e,t,n){return t!==void 0&&n===`readable`?t:e===void 0?void 0:{language:`json`,code:JSON.stringify(e,null,2)}}var wa=[`data-fn`],Ta={class:`about`},Ea={key:0,class:`description`},Da={class:`badges`},Oa={key:1,class:`signature`,"data-testid":`fn-signature`},ka={key:2,class:`dim`},Aa={key:3,class:`strip`,"data-testid":`fn-facts`},ja=[`data-figure`],Ma={class:`label`},Na={class:`value`},Pa={class:`detail`},Fa={key:4,class:`uses`,"data-testid":`fn-uses`},Ia={class:`examples`,"data-testid":`fn-examples`},La={class:`heading`},Ra={key:0,class:`dim`},za={key:0,class:`bad`,role:`alert`},Ba={key:1,class:`dim`},Va={key:3,class:`example-list`},Ha={key:0,class:`note`},Ua={class:`code`},Wa={key:1,class:`code result`},Ga=Y(A({__name:`FnOverview`,props:{name:{},about:{},facts:{},loading:{type:Boolean},problem:{default:``},examples:{},examplesTotal:{},moreExamples:{type:Boolean},examplesLoading:{type:Boolean},examplesProblem:{default:``},describe:{type:Boolean,default:!0}},emits:[`more`,`retry`],setup(e,{emit:t}){let n=e,r=t,i=k(()=>ct(n.name)),a=k(()=>n.facts===void 0?[]:ya(n.facts)),o=k(()=>n.facts?.mode??n.about?.mode),s=k(()=>(n.facts?.uses??[]).filter(e=>e!==n.name)),c=k(()=>{let e=n.facts?.kind;return e!==void 0&&!rr(e)?`its kind (${e}) works one out when the hub describes it.`:"its author adds them to its declaration (`examples`)."});return(t,n)=>(j(),E(`div`,{class:`fn-overview`,"data-testid":`fn-overview`,"data-fn":e.name},[e.problem===``?e.loading&&e.facts===void 0?(j(),F(C(Dt),{key:1,lines:4})):R(``,!0):(j(),F(C(Mt),{key:0,tone:`danger`},{actions:N(()=>[b(C(H),{size:`sm`,variant:`ghost`,onClick:n[0]||=e=>r(`retry`)},{default:N(()=>[...n[2]||=[x(`Retry`,-1)]]),_:1})]),default:N(()=>[x(P(e.problem)+` `,1)]),_:1})),T(`section`,Ta,[e.describe&&e.about?.description?(j(),E(`p`,Ea,P(e.about.description),1)):R(``,!0),T(`div`,Da,[o.value?(j(),F(C(V),{key:0,tone:C(ga)[o.value],title:C(ha)[o.value].about,"data-testid":`fn-mode`},{default:N(()=>[x(P(C(ha)[o.value].label),1)]),_:1},8,[`tone`,`title`])):R(``,!0),e.facts?.free?(j(),F(C(V),{key:1,tone:`ok`},{default:N(()=>[...n[3]||=[x(`Free`,-1)]]),_:1})):R(``,!0),e.facts?.kind&&e.facts.kind!==`native`?(j(),F(C(V),{key:2},{default:N(()=>[x(P(e.facts.kind),1)]),_:1})):R(``,!0),e.about?.instance?(j(),F(C(V),{key:3},{default:N(()=>[x(P(e.about.instance),1)]),_:1})):R(``,!0),e.about&&!e.about.available?(j(),F(C(V),{key:4,tone:`warn`,title:e.about.blocked?.reason},{default:N(()=>[...n[4]||=[x(`Not available now`,-1)]]),_:1},8,[`title`])):R(``,!0),Me(t.$slots,`badges`,{},void 0,!0)]),e.about?.signature?(j(),E(`code`,Oa,P(e.about.signature),1)):R(``,!0),e.about&&!e.about.available&&e.about.blocked?(j(),E(`p`,ka,P(e.about.blocked.reason),1)):R(``,!0)]),e.facts?.notice?(j(),F(C(Mt),{key:2,tone:`neutral`,"data-testid":`fn-notice`},{default:N(()=>[x(P(e.facts.notice),1)]),_:1})):R(``,!0),a.value.length>0?(j(),E(`ul`,Aa,[(j(!0),E(M,null,D(a.value,e=>(j(),E(`li`,{key:e.key,class:`figure`,"data-figure":e.key},[T(`span`,Ma,P(e.label),1),T(`span`,Na,P(e.value),1),T(`span`,Pa,P(e.detail),1)],8,ja))),128))])):R(``,!0),e.facts&&(e.facts.reads.length>0||e.facts.writes.length>0||s.value.length>0)?(j(),E(`dl`,Fa,[e.facts.reads.length>0?(j(),E(M,{key:0},[n[5]||=T(`dt`,null,`Reads`,-1),T(`dd`,null,[(j(!0),E(M,null,D(e.facts.reads,e=>(j(),E(`code`,{key:e,class:`chip`},P(e),1))),128))])],64)):R(``,!0),e.facts.writes.length>0?(j(),E(M,{key:1},[n[6]||=T(`dt`,null,`Writes`,-1),T(`dd`,null,[(j(!0),E(M,null,D(e.facts.writes,e=>(j(),E(`code`,{key:e,class:`chip write`},P(e),1))),128))])],64)):R(``,!0),s.value.length>0?(j(),E(M,{key:2},[n[7]||=T(`dt`,null,`Uses`,-1),T(`dd`,null,[(j(!0),E(M,null,D(s.value,e=>(j(),F(dt,{key:e,name:e},null,8,[`name`]))),128))])],64)):R(``,!0)])):R(``,!0),T(`section`,Ia,[T(`h3`,La,[n[8]||=x(`Examples`,-1),e.examplesTotal>0?(j(),E(`span`,Ra,` · `+P(e.examplesTotal),1)):R(``,!0)]),e.examplesProblem===``?e.examples.length===0&&e.examplesLoading?(j(),E(`p`,Ba,`Loading…`)):e.examples.length===0?(j(),F(C(Mt),{key:2,tone:`warn`,"data-testid":`fn-no-examples`},{default:N(()=>[x(` No examples. Every fn needs at least one: `+P(c.value),1)]),_:1})):(j(),E(`ol`,Va,[(j(!0),E(M,null,D(e.examples,e=>(j(),E(`li`,{key:e.id,class:`example`},[e.note?(j(),E(`p`,Ha,P(e.note),1)):R(``,!0),T(`pre`,Ua,P(C(xa)(i.value,e)),1),e.result===void 0?R(``,!0):(j(),E(`pre`,Wa,[n[9]||=T(`span`,{class:`arrow`},`→ `,-1),x(P(C(ba)(e.result)),1)]))]))),128))])):(j(),E(`p`,za,P(e.examplesProblem),1)),e.moreExamples?(j(),F(C(H),{key:4,size:`sm`,variant:`ghost`,loading:e.examplesLoading,"data-testid":`fn-more-examples`,onClick:n[1]||=e=>r(`more`)},{default:N(()=>[x(` More examples (`+P(e.examplesTotal-e.examples.length)+` left) `,1)]),_:1},8,[`loading`])):R(``,!0)]),Me(t.$slots,`runs`,{},void 0,!0)],8,wa))}}),[[`__scopeId`,`data-v-e343e112`]]),Ka=A({__name:`FnPayload`,props:ge({payload:{},readable:{},maxHeight:{default:360}},{form:{default:`readable`},formModifiers:{}}),emits:[`update:form`],setup(e){let t=e,n=_e(e,`form`),r=k(()=>[{value:`readable`,label:t.readable?.language.toUpperCase()??`Readable`},{value:`stored`,label:`Stored form`}]),i=k(()=>Ca(t.payload,t.readable,n.value));return(t,a)=>i.value?(j(),F(C(kt),{key:0,title:`What it runs`,"data-testid":`fn-payload`},Ae({default:N(()=>[b(C(Tt),{code:i.value.code,language:i.value.language,wrap:``,"max-height":e.maxHeight},null,8,[`code`,`language`,`max-height`])]),_:2},[e.readable?{name:`actions`,fn:N(()=>[b(C(Gt),{modelValue:n.value,"onUpdate:modelValue":a[0]||=e=>n.value=e,options:r.value,label:`Show it as`,"data-testid":`fn-payload-form`},null,8,[`modelValue`,`options`])]),key:`0`}:void 0]),1024)):R(``,!0)}}),qa=[`aria-current`,`data-testid`],Ja={key:0,class:`mark`},Ya={class:`main`},Xa={class:`top`},Za={class:`title`},Qa={key:0,class:`badges`},$a={key:0,class:`detail`},eo={key:1,class:`figures`},to=[`datetime`,`title`],no=Y(A({__name:`BrowserRow`,props:{title:{},detail:{default:``},at:{default:void 0},now:{},selected:{type:Boolean,default:!1},testid:{default:``}},emits:[`open`],setup(e,{emit:t}){let n=t,r=ve();return(t,i)=>(j(),E(`li`,{class:w([`browser-row`,{selected:e.selected}])},[T(`button`,{type:`button`,class:`open`,"aria-current":e.selected?`true`:void 0,"data-testid":e.testid||void 0,onClick:i[0]||=e=>n(`open`)},[r.mark?(j(),E(`span`,Ja,[Me(t.$slots,`mark`)])):R(``,!0),T(`span`,Ya,[T(`span`,Xa,[T(`span`,Za,P(e.title),1),r.badges?(j(),E(`span`,Qa,[Me(t.$slots,`badges`)])):R(``,!0)]),e.detail===``?R(``,!0):(j(),E(`span`,$a,P(e.detail),1))]),r.figures?(j(),E(`span`,eo,[Me(t.$slots,`figures`)])):R(``,!0),e.at===void 0?R(``,!0):(j(),E(`time`,{key:2,class:`at`,datetime:new Date(e.at).toISOString(),title:C(St)(e.at)},P(C(Kt)(e.at,e.now)),9,to))],8,qa)],2))}}),[[`__scopeId`,`data-v-1a21ed96`]]),ro={key:0,class:`none bad`,role:`alert`},io={key:1,class:`none`},ao={key:2,class:`list`},oo={key:0},so=Y(A({__name:`FnRuns`,props:{runs:{},now:{},title:{},loading:{type:Boolean,default:!1},problem:{default:``},empty:{default:`No runs yet.`}},emits:[`open`],setup(e,{emit:t}){let n=t,r=ve();return(t,i)=>(j(),F(C(kt),{class:`runs`,title:e.title,flush:``,compact:``,"data-testid":`fn-recent`},Ae({default:N(()=>[e.problem===``?e.runs.length===0?(j(),E(`p`,io,P(e.loading?`Loading…`:e.empty),1)):(j(),E(`ul`,ao,[(j(!0),E(M,null,D(e.runs,t=>(j(),F(no,{key:t.id,title:C(Mn)(t.args)||C(J)(t.fn),at:t.createdAt,now:e.now,testid:`fn-run-${t.id}`,onOpen:e=>n(`open`,t.id)},{mark:N(()=>[b(zr,{status:t.status,size:10},null,8,[`status`])]),badges:N(()=>[t.status===`failed`||t.status===`awaiting-approval`?(j(),F(C(V),{key:0,tone:C(fr)[t.status].tone},{default:N(()=>[x(P(C(fr)[t.status].word),1)]),_:2},1032,[`tone`])):R(``,!0),t.attempt>1?(j(),F(C(V),{key:1,tone:`warn`},{default:N(()=>[x(`Try `+P(t.attempt),1)]),_:2},1024)):R(``,!0)]),figures:N(()=>[T(`span`,null,P(C(B)(t.totalCost)),1),C(mr)(t,e.now)===void 0?R(``,!0):(j(),E(`span`,oo,P(C(z)(C(mr)(t,e.now)??0)),1))]),_:2},1032,[`title`,`at`,`now`,`testid`,`onOpen`]))),128))])):(j(),E(`p`,ro,P(e.problem),1))]),_:2},[r.actions?{name:`actions`,fn:N(()=>[Me(t.$slots,`actions`,{},void 0,!0)]),key:`0`}:void 0]),1032,[`title`]))}}),[[`__scopeId`,`data-v-dc316a5b`]]),co=A({__name:`FnDetails`,props:ge({name:{},describe:{type:Boolean,default:!0},compact:{type:Boolean,default:!1}},{days:{required:!0},daysModifiers:{},form:{default:`readable`},formModifiers:{},tab:{default:`about`},tabModifiers:{}}),emits:ge([`run`,`runs`,`switched`],[`update:days`,`update:form`,`update:tab`]),setup(e,{emit:t}){let n=e,r=_e(e,`days`),i=_e(e,`form`),a=_e(e,`tab`),o=t,s=ve(),{admin:c,chat:l,fns:u,toasts:d}=G(),f=c.fn,p=nn(3e4),m=k(()=>{let e=f.record.value.value;return e?.name===n.name?e:void 0}),h=k(()=>f.recent.value.value??[]),g=k(()=>{let e=m.value?.decl.kind;return e!==void 0&&e!==`native`&&l.renderers.drawsKind(e)}),_=k(()=>g.value?h.value.find(e=>e.outcome?.status===`done`):void 0),ee=k(()=>_.value===void 0?void 0:l.renderers.storedResultView(_.value,J(n.name))),{opening:te,open:ne}=ma(),re=k(()=>m.value?.decl.kind===Nr),v=c.injected,ie=k(()=>v.page.value.value?.injections??[]),ae=k(()=>jr(re.value,v.page.value.value===void 0?void 0:ie.value.length)),oe=k(()=>re.value?a.value:`about`);async function se(e,t){await v.switchOn(e,t)||d.error(v.saving.problem.value)}async function ce(e,t){await v.reorder(e,t)||d.error(v.saving.problem.value)}async function le(e){let t=m.value?.name;t!==void 0&&(await f.switchOn(e)?o(`switched`,t,e):d.error(f.switching.problem.value))}return S(()=>[n.name,r.value],([e,t])=>{f.open(e,t)},{immediate:!0}),S(()=>n.name,e=>{u.open(e)},{immediate:!0}),S(()=>[n.name,re.value],([e,t])=>{t?v.open({agent:e}):v.close()},{immediate:!0}),De(()=>{f.close(),u.close(),v.close()}),(t,n)=>(j(),F(Re,{class:`fn-details`,loading:C(f).record.loading.value,problem:C(f).record.problem.value,ready:m.value!==void 0,empty:!1,lines:6,"data-testid":`fn-details`,onRetry:n[10]||=t=>C(f).open(e.name,r.value)},{default:N(()=>[m.value?(j(),E(M,{key:0},[re.value?(j(),F(C(Wt),{key:0,modelValue:a.value,"onUpdate:modelValue":n[0]||=e=>a.value=e,tabs:ae.value,label:`Fn`,"data-testid":`fn-tabs`},null,8,[`modelValue`,`tabs`])):R(``,!0),oe.value===`injected`?(j(),F(Pr,{key:1,per:`agent`,views:ie.value,loading:C(v).page.loading.value,problem:C(v).page.problem.value,busy:C(v).busyKey.value,now:C(p),"data-testid":`fn-injected`,onSwitch:se,onReorder:ce,onRetry:n[1]||=e=>C(v).refresh()},null,8,[`views`,`loading`,`problem`,`busy`,`now`])):(j(),E(M,{key:2},[g.value?(j(),F(C(kt),{key:0,title:`Latest result`,"data-testid":`fn-widget`},{actions:N(()=>[b(C(H),{size:`sm`,icon:`play`,loading:C(te)===e.name,"data-testid":`fn-widget-open`,onClick:n[2]||=t=>C(ne)(e.name)},{default:N(()=>[...n[11]||=[x(`Open in chat`,-1)]]),_:1},8,[`loading`])]),default:N(()=>[ee.value&&_.value?(j(),F(Rr,{key:_.value.id,view:ee.value,label:C(J)(e.name)},null,8,[`view`,`label`])):(j(),F(C(At),{key:1,icon:`grid`,title:`Not run yet`,body:`Open it in a chat to run it; its latest run shows here.`}))]),_:1})):R(``,!0),b(Ga,{name:e.name,about:C(u).about.value.value,facts:C(u).facts.value.value,loading:C(u).facts.loading.value,problem:C(u).facts.problem.value,describe:e.describe,examples:C(u).examples.value,"examples-total":C(u).examplesTotal.value,"more-examples":C(u).examplesNext.value!==void 0,"examples-loading":C(u).examplesLoading.value,"examples-problem":C(u).examplesProblem.value,onMore:n[3]||=e=>C(u).moreExamples(),onRetry:n[4]||=t=>C(u).open(e.name)},Ae({badges:N(()=>[b(C(Ht),{"model-value":!m.value.disabled,label:`In use`,disabled:C(f).switching.busy.value,"data-testid":`fn-on`,"onUpdate:modelValue":le},null,8,[`model-value`,`disabled`]),m.value.paused?(j(),F(C(V),{key:0},{default:N(()=>[...n[12]||=[x(`Paused`,-1)]]),_:1})):R(``,!0),(j(!0),E(M,null,D(m.value.decl.tags,e=>(j(),F(C(V),{key:e},{default:N(()=>[x(P(e),1)]),_:2},1024))),128))]),_:2},[s.runs?{name:`runs`,fn:N(()=>[Me(t.$slots,`runs`)]),key:`0`}:void 0]),1032,[`name`,`about`,`facts`,`loading`,`problem`,`describe`,`examples`,`examples-total`,`more-examples`,`examples-loading`,`examples-problem`]),b(ca,{days:r.value,"onUpdate:days":n[5]||=e=>r.value=e,metrics:C(f).metrics.value.value,daily:C(f).daily.value.value??[],loading:C(f).metrics.loading.value,problem:C(f).metrics.problem.value||C(f).daily.problem.value,now:C(p),compact:e.compact,onRetry:n[6]||=t=>C(f).open(e.name,r.value)},null,8,[`days`,`metrics`,`daily`,`loading`,`problem`,`now`,`compact`]),b(Ka,{form:i.value,"onUpdate:form":n[7]||=e=>i.value=e,payload:m.value.decl.payload,readable:m.value.decl.readable,"max-height":e.compact?240:360},null,8,[`form`,`payload`,`readable`,`max-height`]),b(fa,{target:{kind:`fn`,fn:e.name}},null,8,[`target`]),b(Ar,{item:{system:m.value.system,section:`fns`,name:e.name}},null,8,[`item`]),b(so,{runs:h.value,now:C(p),title:`Latest runs`,loading:C(f).recent.loading.value,problem:C(f).recent.problem.value,onOpen:n[9]||=e=>o(`run`,e)},{actions:N(()=>[b(C(H),{size:`sm`,variant:`ghost`,icon:`arrow-right`,"data-testid":`fn-runs`,onClick:n[8]||=t=>o(`runs`,e.name)},{default:N(()=>[...n[13]||=[x(`All its runs`,-1)]]),_:1})]),_:1},8,[`runs`,`now`,`loading`,`problem`])],64))],64)):R(``,!0)]),_:3},8,[`loading`,`problem`,`ready`]))}}),lo=A({__name:`FnModal`,props:{modal:{},fn:{}},setup(e){let t=e,{fns:n,session:r}=G(),i=ie(),a=u(),o=k({get:()=>{let e=le.safeParse(a.query[_r]);return e.success?e.data:`about`},set:e=>{let t={...a.query};e===`about`?Reflect.deleteProperty(t,_r):t[_r]=e,i.replace({query:t,hash:a.hash})}}),s=k(()=>r.user.value?.role===`admin`),c=I(7),l=I(`readable`),d=nn(3e4),f=k({get:()=>!0,set:e=>{e||t.modal.close()}}),p=k(()=>[...(t.modal.scope.value.runs?.()??[]).filter(e=>e.fn===t.fn)].reverse());S([()=>t.fn,s],([e,t])=>{t||n.open(e)},{immediate:!0}),De(()=>{s.value||n.close()});function m(e){i.push(e)}return(t,r)=>(j(),F(C(yt),{open:f.value,"onUpdate:open":r[12]||=e=>f.value=e,title:C(J)(e.fn),description:e.fn,width:`720px`},{footer:N(()=>[b(C(H),{variant:`ghost`,onClick:r[10]||=t=>e.modal.close()},{default:N(()=>[...r[13]||=[x(`Close`,-1)]]),_:1}),s.value?(j(),F(C(H),{key:0,variant:`secondary`,icon:`arrow-right`,"data-testid":`fn-open-page`,onClick:r[11]||=t=>m(C(y).fn(e.fn,o.value===`about`?{}:{tab:o.value}))},{default:N(()=>[...r[14]||=[x(`Open page`,-1)]]),_:1})):R(``,!0)]),default:N(()=>[s.value?(j(),F(co,{key:0,days:c.value,"onUpdate:days":r[1]||=e=>c.value=e,form:l.value,"onUpdate:form":r[2]||=e=>l.value=e,tab:o.value,"onUpdate:tab":r[3]||=e=>o.value=e,name:e.fn,compact:``,onRun:r[4]||=t=>e.modal.openRun(t),onRuns:r[5]||=e=>m(C(y).fnRuns(e)),onSwitched:r[6]||=(t,n)=>e.modal.scope.value.switched?.(t,n)},Ae({_:2},[p.value.length>0?{name:`runs`,fn:N(()=>[b(so,{runs:p.value,now:C(d),title:`Its runs here`,onOpen:r[0]||=t=>e.modal.openRun(t)},null,8,[`runs`,`now`])]),key:`0`}:void 0]),1032,[`days`,`form`,`tab`,`name`])):(j(),F(Ga,{key:1,name:e.fn,about:C(n).about.value.value,facts:C(n).facts.value.value,loading:C(n).facts.loading.value,problem:C(n).facts.problem.value,examples:C(n).examples.value,"examples-total":C(n).examplesTotal.value,"more-examples":C(n).examplesNext.value!==void 0,"examples-loading":C(n).examplesLoading.value,"examples-problem":C(n).examplesProblem.value,onMore:r[8]||=e=>C(n).moreExamples(),onRetry:r[9]||=t=>C(n).open(e.fn)},Ae({_:2},[p.value.length>0?{name:`runs`,fn:N(()=>[b(so,{runs:p.value,now:C(d),title:`Its runs here`,onOpen:r[7]||=t=>e.modal.openRun(t)},null,8,[`runs`,`now`])]),key:`0`}:void 0]),1032,[`name`,`about`,`facts`,`loading`,`problem`,`examples`,`examples-total`,`more-examples`,`examples-loading`,`examples-problem`]))]),_:1},8,[`open`,`title`,`description`]))}}),uo={"approval-needed":{icon:`shield`,tone:`warn`,label:`Approval needed`},"input-needed":{icon:`edit`,tone:`warn`,label:`Input needed`},"config-needed":{icon:`settings`,tone:`warn`,label:`Setup needed`},message:{icon:`chat`,tone:`accent`,label:`Message`},replied:{icon:`chat`,tone:`accent`,label:`Reply`},"turn-finished":{icon:`success`,tone:`ok`,label:`Finished`},"turn-failed":{icon:`error`,tone:`danger`,label:`Failed`},"pairing-requested":{icon:`key`,tone:`accent`,label:`Pairing`},"system-disconnected":{icon:`offline`,tone:`danger`,label:`Disconnected`},"spend-limit":{icon:`warning`,tone:`danger`,label:`Spend limit`},"system-paused":{icon:`pause`,tone:`danger`,label:`System paused`},"system-notice":{icon:`warning`,tone:`warn`,label:`System notice`},"system-message":{icon:`info`,tone:`neutral`,label:`Update`}},fo={ok:{icon:`success`,tone:`ok`,label:`Went well`},failed:{icon:`error`,tone:`danger`,label:`Failed`}};function po(e){let t=uo[e.reason],n=e.tone===void 0||e.tone===`info`?t:{...fo[e.tone],label:t.label};return e.resolved===void 0?n:{icon:`check`,tone:`neutral`,label:`${n.label} · ${e.resolved}`}}var mo=[`data-testid`],ho={class:`text`},go={class:`top`},_o={class:`title`},vo=[`datetime`,`title`],yo={key:0,class:`body`},bo={key:0,class:`dot`,"aria-hidden":`true`},xo={key:1,class:`sr-only`},So={class:`side`},Co=Y(A({__name:`NotificationRow`,props:{notification:{},now:{},compact:{type:Boolean,default:!1}},emits:[`open`,`also`,`read`],setup(e){let t=e,n=k(()=>po(t.notification));return(t,r)=>(j(),E(`li`,{class:w([`row`,{unread:!e.notification.read,resolved:e.notification.resolved!==void 0,compact:e.compact}]),"data-testid":`notification-${e.notification.id}`},[T(`button`,{type:`button`,class:`open`,onClick:r[0]||=n=>t.$emit(`open`,e.notification)},[T(`span`,{class:w([`mark`,`tone-${n.value.tone}`])},[b(C(Ft),{name:n.value.icon,size:16},null,8,[`name`])],2),T(`span`,ho,[T(`span`,go,[T(`span`,_o,P(e.notification.title),1),T(`time`,{class:`time`,datetime:new Date(e.notification.createdAt).toISOString(),title:C(St)(e.notification.createdAt)},P(C(Kt)(e.notification.createdAt,e.now)),9,vo)]),e.notification.body===``?R(``,!0):(j(),E(`span`,yo,P(e.notification.body),1)),T(`span`,{class:w([`reason`,`tone-${n.value.tone}`]),"data-testid":`notification-reason`},[e.notification.read?R(``,!0):(j(),E(`span`,bo)),x(` `+P(n.value.label),1),e.notification.read?R(``,!0):(j(),E(`span`,xo,`, unread`))],2)])]),T(`div`,So,[e.notification.also?(j(),F(C(H),{key:0,class:`also`,size:`sm`,variant:`ghost`,"data-testid":`notification-also`,onClick:r[1]||=n=>t.$emit(`also`,e.notification)},{default:N(()=>[x(P(e.notification.also.label),1)]),_:1})):R(``,!0),e.notification.read?R(``,!0):(j(),F(C(Ct),{key:1,class:`read`,icon:`check`,label:`Mark as read`,size:`sm`,onClick:r[2]||=n=>t.$emit(`read`,e.notification)}))])],10,mo))}}),[[`__scopeId`,`data-v-3a6b7c55`]]),wo=[`aria-busy`],To={key:1,class:`skeletons`,"aria-label":`Loading notifications`},Eo={key:4,class:`more`},Do=Y(A({__name:`NotificationList`,props:{items:{},now:{},loading:{type:Boolean},loaded:{type:Boolean},problem:{default:``},hasMore:{type:Boolean,default:!1},loadingMore:{type:Boolean,default:!1},compact:{type:Boolean,default:!1},emptyTitle:{default:`All caught up`},emptyBody:{default:`Approvals, replies and finished work show up here.`}},emits:[`open`,`also`,`read`,`more`,`retry`],setup(e){return(n,r)=>(j(),E(`div`,{class:w([`list`,{compact:e.compact}]),"aria-busy":e.loading?`true`:`false`},[e.problem===``?R(``,!0):(j(),F(C(Mt),{key:0,tone:`danger`,class:`problem`},{actions:N(()=>[b(C(H),{size:`sm`,variant:`ghost`,onClick:r[0]||=e=>n.$emit(`retry`)},{default:N(()=>[...r[5]||=[x(`Retry`,-1)]]),_:1})]),default:N(()=>[x(P(e.problem)+` `,1)]),_:1})),e.loading&&!e.loaded?(j(),E(`ul`,To,[(j(!0),E(M,null,D(e.compact?3:5,e=>(j(),E(`li`,{key:e,class:`skeleton`},[b(C(Dt),{shape:`circle`,size:32}),b(C(Dt),{shape:`lines`,lines:2,class:`lines`})]))),128))])):e.loaded&&e.items.length===0?(j(),F(C(At),{key:2,icon:`inbox`,title:e.emptyTitle,body:e.emptyBody},null,8,[`title`,`body`])):(j(),F(t,{key:3,tag:`ul`,name:`row`,class:`rows`},{default:N(()=>[(j(!0),E(M,null,D(e.items,t=>(j(),F(Co,{key:t.id,notification:t,now:e.now,compact:e.compact,onOpen:r[1]||=e=>n.$emit(`open`,e),onAlso:r[2]||=e=>n.$emit(`also`,e),onRead:r[3]||=e=>n.$emit(`read`,e)},null,8,[`notification`,`now`,`compact`]))),128))]),_:1})),e.hasMore&&e.items.length>0?(j(),E(`div`,Eo,[b(C(H),{variant:`ghost`,size:`sm`,loading:e.loadingMore,onClick:r[4]||=e=>n.$emit(`more`)},{default:N(()=>[...r[6]||=[x(`Load older`,-1)]]),_:1},8,[`loading`])])):R(``,!0)],10,wo))}}),[[`__scopeId`,`data-v-c9cb4a65`]]),Oo={class:`panel`,"data-testid":`inbox-panel`},ko={class:`head`},Ao={class:`foot`},jo=Y(A({__name:`InboxPanel`,props:{items:{},unread:{},now:{},loading:{type:Boolean},loaded:{type:Boolean},problem:{default:``},limit:{default:6}},emits:[`open`,`also`,`read`,`readAll`,`all`,`retry`],setup(e){let t=e,n=k(()=>t.items.slice(0,t.limit));return(t,r)=>(j(),E(`div`,Oo,[T(`header`,ko,[r[7]||=T(`h2`,{class:`title`},`Notifications`,-1),e.unread>0?(j(),F(C(H),{key:0,size:`sm`,variant:`ghost`,icon:`check`,onClick:r[0]||=e=>t.$emit(`readAll`)},{default:N(()=>[...r[6]||=[x(`Mark all read`,-1)]]),_:1})):R(``,!0)]),b(Do,{items:n.value,now:e.now,loading:e.loading,loaded:e.loaded,problem:e.problem,compact:``,onOpen:r[1]||=e=>t.$emit(`open`,e),onAlso:r[2]||=e=>t.$emit(`also`,e),onRead:r[3]||=e=>t.$emit(`read`,e),onRetry:r[4]||=e=>t.$emit(`retry`)},null,8,[`items`,`now`,`loading`,`loaded`,`problem`]),T(`footer`,Ao,[b(C(H),{size:`sm`,variant:`ghost`,"icon-right":`arrow-right`,block:``,onClick:r[5]||=e=>t.$emit(`all`)},{default:N(()=>[...r[8]||=[x(`Open inbox`,-1)]]),_:1})])]))}}),[[`__scopeId`,`data-v-d2b5d353`]]),Mo={class:`steps`,"data-testid":`install-sheet`},No=Y(A({__name:`InstallSheet`,props:ge({name:{}},{open:{type:Boolean,required:!0},openModifiers:{}}),emits:[`update:open`],setup(e){let t=_e(e,`open`);return(n,r)=>(j(),F(C(yt),{open:t.value,"onUpdate:open":r[1]||=e=>t.value=e,title:`Add to Home Screen`,description:`Put ${e.name} on your home screen, like any other app.`,width:`420px`},{footer:N(()=>[b(C(H),{variant:`primary`,onClick:r[0]||=e=>t.value=!1},{default:N(()=>[...r[6]||=[x(`Got it`,-1)]]),_:1})]),default:N(()=>[T(`ol`,Mo,[r[4]||=T(`li`,null,[T(`span`,null,[x(`Tap `),T(`strong`,null,`Share`)]),T(`svg`,{class:`glyph`,viewBox:`0 0 24 24`,"aria-label":`the Share button`,role:`img`},[T(`path`,{d:`M12 3v12M8 7l4-4 4 4`}),T(`path`,{d:`M7 10H5v11h14V10h-2`})]),T(`span`,{class:`dim`},`at the bottom of Safari (at the top on an iPad).`)],-1),r[5]||=T(`li`,null,[T(`span`,null,[x(`Scroll down and tap `),T(`strong`,null,`Add to Home Screen`),x(`.`)])],-1),T(`li`,null,[T(`span`,null,[r[2]||=x(`Tap `,-1),r[3]||=T(`strong`,null,`Add`,-1),x(`. Open `+P(e.name)+` from your home screen from now on.`,1)])])]),r[7]||=T(`p`,{class:`dim note`},`Only Safari can add it. In another browser, open this page in Safari first.`,-1)]),_:1},8,[`open`,`description`]))}}),[[`__scopeId`,`data-v-f47f52f1`]]),Po=[`title`],Fo=[`width`,`height`],Io={key:0,class:`name`,"data-testid":`brand-name`},Lo=Y(A({__name:`AppBrand`,props:{name:{},markOnly:{type:Boolean,default:!1},size:{default:28}},setup(e){return(t,n)=>(j(),E(`span`,{class:`brand`,title:e.markOnly?e.name:void 0},[(j(),E(`svg`,{class:`mark`,width:e.size,height:e.size,viewBox:`0 0 32 32`,"aria-hidden":`true`},[...n[0]||=[be(`<rect width="32" height="32" rx="9" class="tile" data-v-c7bc8cf6></rect><g class="lines" stroke-width="2" stroke-linecap="round" data-v-c7bc8cf6><path d="M16 16 9 9M16 16l7-7M16 16v8" data-v-c7bc8cf6></path></g><circle cx="16" cy="16" r="3.5" class="hub" data-v-c7bc8cf6></circle><circle cx="9" cy="9" r="2.3" class="node" data-v-c7bc8cf6></circle><circle cx="23" cy="9" r="2.3" class="node" data-v-c7bc8cf6></circle><circle cx="16" cy="24" r="2.3" class="node" data-v-c7bc8cf6></circle>`,6)]],8,Fo)),e.markOnly?R(``,!0):(j(),E(`span`,Io,P(e.name),1))],8,Po))}}),[[`__scopeId`,`data-v-c7bc8cf6`]]),Ro={class:`head`},zo={class:`head-tools`},Bo={class:`entries`},Vo={class:`label`},Ho=[`aria-label`],Uo={class:`middle`},Wo={key:0,class:`foot`},Go=[`title`,`onClick`],Ko={class:`who`},qo={class:`name`},Jo={class:`email`},Yo=Y(A({__name:`AppSidebar`,props:{brand:{},entries:{},user:{},unread:{},collapsed:{type:Boolean,default:!1},collapsible:{type:Boolean,default:!0},installable:{type:Boolean,default:!1}},emits:[`toggle`,`inbox`,`settings`,`install`,`signOut`,`navigate`],setup(e,{emit:t}){let n=e,r=t,i=ve(),a=k(()=>[{value:`settings`,label:`Settings`,icon:`settings`},...n.installable?[{value:`install`,label:`Install app`,icon:`download`}]:[],{kind:`separator`},{value:`sign-out`,label:`Sign out`,icon:`log-out`,danger:!0}]);function o(e){e.currentTarget instanceof HTMLElement&&r(`inbox`,e.currentTarget)}function s(e){switch(e){case`settings`:r(`settings`);break;case`install`:r(`install`);break;case`sign-out`:r(`signOut`)}}return(t,n)=>{let r=ye(`RouterLink`);return j(),E(`nav`,{class:w([`sidebar`,{collapsed:e.collapsed}]),"aria-label":`Main`},[T(`div`,Ro,[b(Lo,{name:e.brand,"mark-only":e.collapsed},null,8,[`name`,`mark-only`]),T(`div`,zo,[b(C(Ct),{icon:`bell`,label:e.unread>0?`Notifications, ${C(Nt)(e.unread)} unread`:`Notifications`,badge:e.unread,"data-testid":`open-inbox`,onClick:o},null,8,[`label`,`badge`]),e.collapsible?(j(),F(C(Ct),{key:0,icon:`sidebar`,label:e.collapsed?`Expand sidebar`:`Collapse sidebar`,"data-testid":`toggle-sidebar`,onClick:n[0]||=e=>t.$emit(`toggle`)},null,8,[`label`])):R(``,!0)])]),T(`ul`,Bo,[(j(!0),E(M,null,D(e.entries,i=>(j(),E(`li`,{key:i.id},[b(r,{to:i.to,class:w([`entry`,{active:i.active}]),"aria-current":i.active?`page`:void 0,title:e.collapsed?i.label:void 0,"data-testid":`nav-${i.id}`,onClick:n[1]||=e=>t.$emit(`navigate`)},{default:N(()=>[b(C(Ft),{name:i.icon,size:18},null,8,[`name`]),T(`span`,Vo,P(i.label),1),i.count>0?(j(),E(`span`,{key:0,class:`count`,"aria-label":`${i.count} unread`},P(C(Nt)(i.count)),9,Ho)):R(``,!0)]),_:2},1032,[`to`,`class`,`aria-current`,`title`,`data-testid`])]))),128))]),T(`div`,Uo,[i.default&&!e.collapsed?Me(t.$slots,`default`,{},void 0,!0,0):R(``,!0)]),e.user?(j(),E(`div`,Wo,[b(C(It),{items:a.value,label:`Account`,side:`top`,align:`start`,onSelect:s},{trigger:N(({toggle:t,attrs:n})=>[T(`button`,we({type:`button`,class:`person`},n,{title:e.collapsed?e.user.name:void 0,"data-testid":`user-menu`,onClick:t}),[b(C(jt),{name:e.user.name,size:30},null,8,[`name`]),T(`span`,Ko,[T(`span`,qo,P(e.user.name),1),T(`span`,Jo,P(e.user.email),1)]),b(C(Ft),{name:`chevron-up`,size:16,class:`chevron`})],16,Go)]),_:1},8,[`items`])])):R(``,!0)],2)}}}),[[`__scopeId`,`data-v-db84e1b2`]]),Xo={class:`topbar`},Zo={class:`title`},Qo=Y(A({__name:`AppTopBar`,props:{title:{},unread:{}},emits:[`menu`,`inbox`],setup(e,{emit:t}){let n=t;function r(e){e.currentTarget instanceof HTMLElement&&n(`inbox`,e.currentTarget)}return(t,n)=>(j(),E(`header`,Xo,[b(C(Ct),{icon:`menu`,label:`Open navigation`,"data-testid":`open-nav`,onClick:n[0]||=e=>t.$emit(`menu`)}),T(`h1`,Zo,P(e.title),1),b(C(Ct),{icon:`bell`,label:e.unread>0?`Notifications, ${C(Nt)(e.unread)} unread`:`Notifications`,badge:e.unread,"data-testid":`open-inbox`,onClick:r},null,8,[`label`,`badge`])]))}}),[[`__scopeId`,`data-v-58e88c22`]]),$o=[{id:`chat`,to:y.chat(),label:`Chat`,icon:`chat`,routes:[v.chat,v.session,v.turnTree],adminOnly:!1},{id:`inbox`,to:y.inbox(),label:`Inbox`,icon:`inbox`,routes:[v.inbox],adminOnly:!1},{id:`resources`,to:y.resources(),label:`Resources`,icon:`layers`,routes:[v.resources],adminOnly:!1},{id:`context`,to:y.context(),label:`Context`,icon:`book`,routes:[v.context,v.contextItem],adminOnly:!1},{id:`data`,to:y.data(),label:`Data`,icon:`database`,routes:[v.data,v.dataType],adminOnly:!1},{id:`admin`,to:y.systems(),label:`Admin`,icon:`shield`,adminOnly:!0,routes:[v.admin,v.systems,v.system,v.review,v.instance,v.fn,v.graph,v.models,v.limits,v.people,v.policies,v.actorSettings,v.runs,v.llmCalls,v.modelCalls,v.mcps,v.mcp,v.adminSystemPage]},{id:`settings`,to:y.settings(),label:`Settings`,icon:`settings`,routes:[v.settings],adminOnly:!1}],es=e=>typeof e==`string`&&Object.values(v).includes(e);function ts(e,t,n){let r=e.filter(e=>e.system===t);return r.find(e=>e.segment===n)??r[0]}function ns(e,t,n,r=[],i=[]){let a=es(e.name)?e.name:void 0,o=$o.filter(e=>!e.adminOnly||t?.role===`admin`).map(e=>({id:e.id,to:e.to,label:e.label,icon:e.icon,active:a!==void 0&&e.routes.includes(a),count:e.id===`inbox`?n.inbox:e.id===`admin`?n.admin:0})),s=r.map(t=>({id:`connect-${t.system}`,to:y.connect(t.system),label:t.title,icon:t.icon,active:a===v.connect&&e.params?.system===t.system,count:0})),c=i.map(t=>({id:`page-${t.system}-${t.segment}`,to:y.systemPage(t.system,t.segment),label:t.title,icon:t.icon,active:a===v.systemPage&&t===ts(i,e.params?.system,e.params?.page),count:0})),l=o.findIndex(e=>e.id===`context`)+1;return[...o.slice(0,l),...s,...c,...o.slice(l)]}function rs(){let{keeper:e}=G(),t=ie();return async()=>{await e.signOut(),window.location.replace(t.resolve(y.signIn()).href)}}function is(){let{session:e}=G(),t=ie();S(e.signedIn,e=>{let n=t.currentRoute.value;e||n.meta.public===!0||window.location.replace(t.resolve(y.signIn(n.fullPath)).href)})}function as(e){return[`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">`,`<rect width="32" height="32" rx="9" fill="#5b5bd6"/>`,`<g stroke="#fff" stroke-width="2" stroke-linecap="round" opacity="0.7"><path d="M16 16 9 9M16 16l7-7M16 16v8"/></g>`,`<circle cx="16" cy="16" r="3.5" fill="#fff"/><circle cx="9" cy="9" r="2.3" fill="#fff"/><circle cx="23" cy="9" r="2.3" fill="#fff"/><circle cx="16" cy="24" r="2.3" fill="#fff"/>`,e?`<circle cx="26" cy="26" r="6" fill="#e5484d" stroke="#fff" stroke-width="2"/>`:``,`</svg>`].join(``)}function os(e){return`data:image/svg+xml,${encodeURIComponent(as(e))}`}function ss(e,t){let n=e.querySelector(`link[rel="icon"]`);n===null&&(n=e.createElement(`link`),n.rel=`icon`,e.head.append(n)),n.type=`image/svg+xml`,n.href=os(t)}function cs(e,t,n){let r=t>0?`(${t>99?`99+`:String(t)}) `:``;return e===n?`${r}${n}`:`${r}${e} · ${n}`}var ls={class:`titlebar`,"aria-hidden":`true`,"data-testid":`titlebar`},us={class:`titlebar-name`},ds=[`aria-busy`],fs={key:0,class:`connection`,"data-testid":`connection-banner`},ps=Y(A({__name:`AppShell`,setup(e){let{session:t,identity:n,keeper:r,layout:i,toasts:a,inbox:o,connection:s,admin:c,chat:l,pages:d,outsideImages:f,install:p}=G(),m=rs(),h=u(),g=ie(),_=Vt(Wr),ee=nn(),te=t.signedIn,ne=k(()=>h.meta.bare===!0||!te.value),re=k(()=>ns(h,t.user.value,{inbox:o.unread.value,admin:c.systems.pending.value},l.connections.nav.value,d.nav.value)),ae=k(()=>i.pageTitle.value===void 0?(h.name===v.connect?l.connections.nav.value.find(e=>e.system===h.params.system):void 0)?.title??h.meta.title??n.name.value:i.pageTitle.value),oe=k(()=>_.value&&h.meta.ownHeader!==!0),se=L(!1),ce=L(null);S(te,(e,t)=>{n.load(),e?(r.start(),n.start(),o.start(),l.connections.load(!0),d.start(),d.load(!0),f.load()):(d.clear(),f.clear(),r.stop(),o.stop(),n.stop(),t===!0&&h.meta.public!==!0&&g.replace(y.signIn(h.fullPath)))},{immediate:!0}),S([ae,o.unread,n.name],([e,t,n])=>{document.title=cs(e,t,n),ss(document,t>0)},{immediate:!0}),S(()=>h.fullPath,()=>{i.drawerOpen.value=!1,se.value=!1});function le(e){se.value&&ce.value===e?se.value=!1:(ce.value=e,i.drawerOpen.value=!1,se.value=!0,o.load(`all`))}async function ue(e,t=`link`){se.value=!1,e.read||o.markRead([e.id]),await g.push(await de(e,e=>l.sessionOfRun(e),t))}async function fe(){i.drawerOpen.value=!1,await p.install()===`accepted`&&a.ok(`Installed`)}async function pe(){await o.markAllRead()&&a.ok(`All caught up`)}return(e,r)=>{let c=ye(`RouterView`);return j(),E(`div`,{class:w([`shell`,{bare:ne.value,compact:C(_),"no-bar":C(_)&&!oe.value,collapsed:!C(_)&&C(i).collapsed}])},[T(`div`,ls,[T(`span`,us,P(C(n).name.value),1)]),ne.value?R(``,!0):(j(),E(M,{key:0},[C(_)?oe.value?(j(),F(Qo,{key:1,title:ae.value,unread:C(o).unread.value,onMenu:r[2]||=e=>C(i).drawerOpen.value=!0,onInbox:le},null,8,[`title`,`unread`])):R(``,!0):(j(),F(Yo,{key:0,class:`side`,brand:C(n).name.value,entries:re.value,user:C(t).user.value,unread:C(o).unread.value,collapsed:C(i).collapsed,installable:C(p).offered,onToggle:r[0]||=e=>C(i).toggleSidebar(),onInbox:le,onSettings:r[1]||=e=>C(g).push(C(y).settings()),onSignOut:C(m),onInstall:fe},null,8,[`brand`,`entries`,`user`,`unread`,`collapsed`,`installable`,`onSignOut`])),C(_)?(j(),F(C(vt),{key:2,open:C(i).drawerOpen.value,"onUpdate:open":r[5]||=e=>C(i).drawerOpen.value=e,placement:`left`,label:`Navigation`,width:`300px`},{default:N(()=>[b(Yo,{brand:C(n).name.value,entries:re.value,user:C(t).user.value,unread:C(o).unread.value,collapsible:!1,installable:C(p).offered,onInbox:le,onSettings:r[3]||=e=>C(g).push(C(y).settings()),onSignOut:C(m),onNavigate:r[4]||=e=>C(i).drawerOpen.value=!1,onInstall:fe},null,8,[`brand`,`entries`,`user`,`unread`,`installable`,`onSignOut`])]),_:1},8,[`open`])):R(``,!0)],64)),T(`main`,{class:`page`,"aria-busy":C(o).loading.value?`true`:void 0},[!ne.value&&C(s).state.value!==`online`?(j(),E(`div`,fs,[b(C(Mt),{tone:C(s).state.value===`offline`?`warn`:`ok`,icon:C(s).state.value===`offline`?`offline`:`success`},{default:N(()=>[x(P(C(s).state.value===`offline`?`Reconnecting to the hub…`:`Back online`),1)]),_:1},8,[`tone`,`icon`])])):R(``,!0),b(c,null,{default:N(({Component:e,route:t})=>[(j(),F(je(e),{key:t.meta.group??t.matched[0]?.path??t.path,class:`routed`}))]),_:1})],8,ds),b(C(Yt),{open:se.value,"onUpdate:open":r[11]||=e=>se.value=e,anchor:ce.value,side:C(_)?`bottom`:`right`,align:`start`,label:`Notifications`},{default:N(()=>[b(jo,{items:C(o).items.value,unread:C(o).unread.value,now:C(ee),loading:C(o).loading.value,loaded:C(o).loaded.value,problem:C(o).problem.value,onOpen:r[6]||=e=>ue(e),onAlso:r[7]||=e=>ue(e,`also`),onRead:r[8]||=e=>C(o).markRead([e.id]),onReadAll:pe,onAll:r[9]||=e=>C(g).push(C(y).inbox()),onRetry:r[10]||=e=>C(o).load(`all`)},null,8,[`items`,`unread`,`now`,`loading`,`loaded`,`problem`])]),_:1},8,[`open`,`anchor`,`side`]),b(No,{open:C(p).sheetOpen.value,"onUpdate:open":r[12]||=e=>C(p).sheetOpen.value=e,name:C(n).name.value},null,8,[`open`,`name`]),b(C(Bt),{toasts:C(a).items,onDismiss:r[13]||=e=>C(a).dismiss(e),onAction:r[14]||=e=>C(a).act(e),onHold:r[15]||=e=>C(a).hold(e),onRelease:r[16]||=e=>C(a).release(e)},null,8,[`toasts`])],2)}}}),[[`__scopeId`,`data-v-73b0dbae`]]),ms=A({__name:`App`,setup(e){let{chat:t,itemVersions:n,session:i,outsideImages:s}=G();Ee(Ut,()=>s.value.value),Ee(tn,t.types),Ee(kr,n),Ee($t,e=>t.renderers.inputView(e)),Ee(r,_t),Ee(o,Ne),Ee(a,Ri),Ee(Fe,t.visuals),is();let c=hr(ie());return(e,t)=>(j(),E(M,null,[b(ps),C(c).name.value&&C(i).signedIn.value?(j(),F(lo,{key:0,modal:C(c),fn:C(c).name.value},null,8,[`modal`,`fn`])):R(``,!0)],64))}});function hs(e,t){let n=g({history:t,routes:oe,scrollBehavior:(e,t,n)=>n??{top:0}});return n.beforeEach(t=>{let n=e.signedIn.value;return t.name===v.signIn&&n?fe(t.query.next)??y.chat():t.meta.public===!0?!0:n?t.meta.admin===!0&&e.user.value?.role!==`admin`?y.chat():!0:y.signIn(t.fullPath)}),n}var gs=K({server:K({name:q(),version:q()}),instructions:q().optional(),tools:Yn(K({name:q(),description:q().optional()}))}),_s=`2025-06-18`,vs=Nn([K({jsonrpc:mn(`2.0`),id:Nn([Cn(),q()]),result:Rn()}),K({jsonrpc:mn(`2.0`),id:Nn([Cn(),q(),sn()]),error:K({code:Cn(),message:q()})})]),ys=K({serverInfo:K({name:q(),version:q()}),instructions:q().optional()}),bs=K({tools:Yn(K({name:q(),description:q().optional()}))});function xs(e,t){if(!e.includes(`text/event-stream`))return JSON.parse(t);let n=t.split(/\r?\n/).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trim()).filter(e=>e!==``);for(let e of n.reverse())try{return JSON.parse(e)}catch{}throw Error(`The MCP sent no answer.`)}var Ss=class{#e;constructor(e){this.#e=e}async tools(e,t){let n,r=async(r,i,a)=>{let o=await this.#e(e,{method:`POST`,headers:{"content-type":`application/json`,accept:`application/json, text/event-stream`,authorization:`Bearer ${t}`,"mcp-protocol-version":_s,...n===void 0?{}:{"mcp-session-id":n}},body:JSON.stringify({jsonrpc:`2.0`,method:i,params:a,...r===void 0?{}:{id:r}})});if(o.status===401||o.status===403)throw Error(`The MCP refused that secret.`);if(!o.ok&&o.status!==202)throw Error(`The MCP answered ${o.status}.`);if(n=o.headers.get(`mcp-session-id`)??n,r===void 0)return;let s=vs.parse(xs(o.headers.get(`content-type`)??``,await o.text()));if(`error`in s)throw Error(s.error.message);return s.result},i=ys.parse(await r(1,`initialize`,{protocolVersion:_s,capabilities:{},clientInfo:{name:`harness-admin`,version:`1`}}));await r(void 0,`notifications/initialized`,{});let a=bs.parse(await r(2,`tools/list`,{}));return gs.parse({server:i.serverInfo,...i.instructions===void 0?{}:{instructions:i.instructions},tools:a.tools})}},Cs=class{#e;#t;secrets=new W;revoking=new U;constructor(e){this.#e=e}async load(e,t=!1){this.#t=e,await this.secrets.load(()=>this.#e.autoPairs.call({system:e}),`Couldn't load the auto pair secrets.`,t)}async revoke(e){let t=await this.revoking.run(async()=>(await this.#e.revokeAutoPair.call({id:e})).ok,`Couldn't revoke that secret.`);return t.ok&&this.#t!==void 0&&await this.load(this.#t,!0),t}},ws=class{#e;decision=new W;saving=new U;preview=new W;search=new W;searchSaving=new U;constructor(e){this.#e=e}async load(e=!1){await this.decision.load(()=>this.#e.suggestDecision.call({}),`Couldn't load the suggestions setting.`,e)}async save(e){let t=await this.saving.run(()=>this.#e.setSuggestDecision.call(e),`Couldn't save the suggestions setting.`);return t.ok&&this.decision.set(t.value),t}async loadSearch(e=!1){await this.search.load(()=>this.#e.searchDecisions.call({}),`Couldn't load the search settings.`,e)}async saveSearch(e,t){let n=await this.searchSaving.run(()=>this.#e.setSearchDecision.call({item:e,value:t}),`Couldn't save the search setting.`);return n.ok&&this.search.set(n.value),n}async try(e,t){await this.preview.load(()=>this.#e.previewSuggestions.call({session:e,text:t}),`Couldn't try the suggestions.`)}},Ts=class{#e;setting=new W;saving=new U;constructor(e){this.#e=e}async load(e=!1){await this.setting.load(()=>this.#e.autoClassifier.call({}),`Couldn't load the auto mode classifier.`,e)}async save(e){let t=await this.saving.run(()=>this.#e.setAutoClassifier.call(e),`Couldn't save the auto mode classifier.`);return t.ok&&this.setting.set(t.value),t}},Es=class{#e;setting=new W;saving=new U;constructor(e){this.#e=e}async load(e=!1){await this.setting.load(()=>this.#e.imageEmbedding.call({}),`Couldn't load where pictures are embedded.`,e)}async save(e){let t=await this.saving.run(()=>this.#e.setImageEmbedding.call(e),`Couldn't save where pictures are embedded.`);return t.ok&&this.setting.set(t.value),t}},Ds=class{#e;list=new W;#t=k(()=>new Map((this.list.value.value??[]).map(e=>[e.id,e])));constructor(e){this.#e=e}async load(e=!1){(e||this.list.value.value===void 0&&!this.list.loading.value)&&await this.list.load(()=>this.#e.actors.call({}),`Couldn't load people and groups.`)}nameOf=e=>this.#t.value.get(e)?.name??e;options(e){return(this.list.value.value??[]).filter(t=>e.includes(t.kind)&&!t.disabled).map(e=>({id:e.id,name:e.name,kind:e.kind,detail:e.kind===`user`?e.email:e.about})).sort((e,t)=>e.name.localeCompare(t.name))}},Os=class{#e;#t=new Set;byRun=L(new Map);problem=I(``);constructor(e){this.#e=e}async load(e){let t=[...new Set(e)].filter(e=>!this.#t.has(e)).slice(0,200);if(t.length!==0){for(let e of t)this.#t.add(e);try{let e=await this.#e.approvals.call({runs:t}),n=new Map(this.byRun.value);for(let t of e)t.status===`pending`&&n.set(t.run,t);this.byRun.value=n,this.problem.value=``}catch(e){for(let e of t)this.#t.delete(e);this.problem.value=X(e)}}}async decide(e,t,n,r){let i=this.byRun.value,a=new Map(i);a.delete(e.run),this.byRun.value=a;try{return await this.#e.approve.call({approval:e.id,approve:t,remember:`once`,...n===``?{}:{reason:n},...r===void 0?{}:{answer:r}}),!0}catch(e){return this.byRun.value=i,this.problem.value=X(e),!1}}};function ks(e){return e.run===void 0?{query:e.query}:{run:e.run}}var As=class{#e;list;opened=new W;openedId=L(void 0);constructor(e,t){this.#e=e,this.list=new f(e,t)}async open(e){let t=this.openedId.value===e;t||this.opened.reset(),this.openedId.value=e,await this.opened.load(()=>this.#e.one(e),this.#e.oneFailure,t)}close(){this.openedId.value=void 0,this.opened.reset()}},js=class extends As{#e;control=new U;constructor(e,t){super(e,{}),this.#e=t}async background(e){let t=await this.control.run(()=>this.#e.background.call({run:e}),`Couldn't move it to the background.`);return t.ok&&this.open(e),t}async undoTurn(e){let t=await this.control.run(()=>this.#e.undoTurn.call({turn:e}),`Couldn't undo the turn.`);return t.ok&&this.list.refresh(),t}};function Ms(e,t){return new js({fetch:(t,n,r)=>e.runs.call(h({query:t},r,n)),key:e=>e.id,failure:`Couldn't load runs.`,limit:50,one:e=>t.run.call({run:e}),oneFailure:`Couldn't load this run.`},t)}function Ns(e,t){return new As({fetch:(t,n,r)=>e.llmCalls.call(h({query:t},r,n)),key:e=>e.id,failure:`Couldn't load LLM calls.`,limit:50,one:e=>t.llmCall.call({id:e}),oneFailure:`Couldn't load this LLM call.`},{})}function Ps(e,t){return new As({fetch:(t,n,r)=>e.modelCalls.call(h(ks(t),r,n)),key:e=>e.id,failure:`Couldn't load model calls.`,limit:50,one:async n=>{let r=await e.modelCall.call({id:n});return r.interaction===void 0?{call:r}:{call:r,interaction:await t.llmCall.call({id:r.interaction})}},oneFailure:`Couldn't load this model call.`},{query:{}})}function Fs(e,t){return new As({fetch:(t,n,r)=>e.resources.call(h({query:t},r,n)),key:e=>e.uri,failure:`Couldn't load resources.`,limit:50,one:e=>t.resource.call({uri:e,want:[`text`,`links`]}),oneFailure:`Couldn't open this resource.`},{})}var Is=class{#e;#t;#n;key=L(void 0);instances=new W;configForm=new W;config=new U;exporting=new U;removing=new U;view=k(()=>this.instances.value.value?.find(e=>e.instance===this.key.value?.instance));constructor(e,t){this.#e=e,this.#t=t}async open(e){let t=this.key.value?.system===e.system&&this.key.value.instance===e.instance;t||this.close(),this.key.value=e,this.#n??=this.#t(e=>{this.#i(e)}),await Promise.all([this.#r(e.system,t),this.configForm.load(async()=>{let t=await this.#e.system.call({system:e.system});return{type:t.configType,secrets:t.configSecrets??[],instanceMode:t.instanceMode,store:t.store}},`Couldn't load this system.`,t)])}close(){this.#n?.(),this.#n=void 0,this.key.value=void 0,this.instances.reset(),this.configForm.reset()}async configure(e){let t=this.key.value;if(t===void 0)return{ok:!1,problems:[`No instance is open.`]};let n=await this.config.run(()=>this.#e.configureSystem.call({system:t.system,instance:t.instance,config:e}),`Couldn't save the config.`);return n.ok?`problems`in n.value?{ok:!1,problems:n.value.problems}:(this.#r(t.system,!0),{ok:!0,version:n.value.version}):{ok:!1,problems:[n.problem]}}async exportData(e,t=this.key.value){return t===void 0?{ok:!1,problem:`No instance is open.`}:this.exporting.run(async()=>{let n=await this.#e.exportSystemData.call({...t,...e?{withSecrets:e}:{}});return{url:n.url,size:n.size}},`Couldn't export this instance's data.`)}async remove(e){let t=this.key.value;if(t===void 0)return!1;let n=await this.removing.run(()=>this.#e.removeInstance.call({...t,...e===void 0?{}:{keepStore:e}}),`Couldn't remove ${t.system}@${t.instance}.`);return n.ok&&n.value.ok}async#r(e,t){await this.instances.load(()=>this.#e.instances.call({system:e}),`Couldn't load this system's instances.`,t)}#i(e){let t=this.key.value;e.type===`system`&&t!==void 0&&e.system===t.system&&this.#r(t.system,!0)}};function Ls(e,t){return e.filter(e=>e.decl.routing?.to===`instance`&&e.decl.routing.instance===t)}function Rs(e,t,n){return{list:`types`,query:{filters:[{field:`system`,op:`is`,value:e.system},...e.instance===void 0?[]:[{field:`instance`,op:`is`,value:e.instance}]],sort:[{field:`name`,dir:`asc`}],limit:n,...t===void 0?{}:{cursor:t}}}}function zs(e,t){let n=$n.safeParse(t.includes(`/`)?t:`${e}/${t}`);return n.success?n.data:void 0}function Bs(e,t){let n=new Set;for(let r of t)for(let t of r.preview?.parts??[]){if(t.type!==`type-diff`)continue;let r=zs(e,t.name);r!==void 0&&n.add(r)}return n}function Vs(e,t){return e.filter(e=>e.status===`awaiting-approval`&&e.instance===t)}function Hs(e){return e.filter(e=>e.proposed===!0&&e.status===`pending`)}function Us(e,t){return[...new Set([...e??[],...Ws(t)])]}function Ws(e,t=``){return e===`•••• kept`?t===``?[]:[t]:qn(e)?Object.entries(e).flatMap(([e,n])=>Ws(n,t===``?e:`${t}.${e}`)):[]}function Gs(e,t,n,r=!1){let i=[{label:`Version`,value:e.version}];return e.address!==void 0&&!r&&i.push({label:`Address`,value:e.address}),i.push({label:`Key`,value:e.keyFingerprint}),e.pairedAt!==void 0&&i.push({label:`Paired`,value:`${Kt(e.pairedAt,t)}${e.pairedBy===void 0?``:` by ${n(e.pairedBy)}`}`,title:St(e.pairedAt)}),e.lastSeenAt!==void 0&&i.push({label:`Last seen`,value:e.status===`connected`?`Online now`:Kt(e.lastSeenAt,t),title:St(e.lastSeenAt)}),e.config!==void 0&&i.push({label:`Config`,value:`Version ${e.config.version}, ${Kt(e.config.setAt,t)}`,title:St(e.config.setAt)}),i.push({label:`Manifest`,value:e.manifestHash,code:!0}),i}var Ks=class{#e;#t=L(void 0);fns=new W;types;typeCount=I(void 0);waitingRuns=new W;desk;proposals=k(()=>Hs((this.waitingRuns.value.value??[]).flatMap(e=>{let t=this.desk.byRun.value.get(e.id);return t===void 0?[]:[t]})));changing=k(()=>{let e=this.#t.value;return e===void 0?new Set:Bs(e.system,this.proposals.value)});constructor(e,t){this.#e=e,this.desk=new Os(t),this.types=new f({fetch:async(e,t,n)=>{if(e===void 0)return{items:[]};let r=await this.#e.query.call(Rs(e,t,n));return t===void 0&&(this.typeCount.value=r.total),{items:Pn.array().parse(r.items),...r.cursor===void 0?{}:{cursor:r.cursor}}},key:e=>e.name,failure:`Couldn't load this instance's types.`,limit:100},void 0)}async open(e){let t=this.#t.value,n=t?.system===e.system&&t.instance===e.instance;n||this.close(),this.#t.value=e,await Promise.all([this.fns.load(async()=>Ls(await this.#e.systemFns.call({system:e.system}),e.instance),`Couldn't load this instance's fns.`,n),this.waitingRuns.load(async()=>{let t=Vs((await this.#e.runs.call({query:{filters:[{field:`system`,op:`is`,value:e.system},{field:`status`,op:`is`,value:`awaiting-approval`}],limit:100}})).items,e.instance);return await this.desk.load(t.map(e=>e.id)),t},`Couldn't load the changes waiting for approval.`,n),this.types.load(e)])}async decide(e,t,n){let r=await this.desk.decide(e,t,n),i=this.#t.value;return r&&i!==void 0&&this.open(i),r}close(){this.#t.value=void 0,this.fns.reset(),this.types.load(void 0),this.typeCount.value=void 0,this.waitingRuns.reset()}},qs=class{#e;list=new W;create=new U;constructor(e){this.#e=e}async load(e=!1){await this.list.load(()=>this.#e.mcps.call({}),`Couldn't load the MCPs.`,e)}async make(e){let t=await this.create.run(()=>this.#e.createMcp.call(e),`Couldn't make that MCP.`);return t.ok&&this.list.set([...this.list.value.value??[],t.value.mcp]),t}},Js=class{#e;#t;id=I(void 0);view=new W;sessions=new W;draft=L(void 0);preview=new W;save=new U;rotate=new U;remove=new U;secret=I(``);tried=new W;changed=k(()=>this.draft.value!==void 0&&JSON.stringify(this.draft.value)!==JSON.stringify(this.view.value.value?.rules));constructor(e,t){this.#e=e,this.#t=t}async open(e,t=``){this.id.value!==e&&this.close(),this.id.value=e,t!==``&&(this.secret.value=t),await this.view.load(()=>this.#e.mcp.call({mcp:e}),`Couldn't load this MCP.`,this.view.value.value?.id===e);let n=this.view.value.value;n!==void 0&&this.draft.value===void 0&&this.edit(n.rules)}close(){this.id.value=void 0,this.view.reset(),this.sessions.reset(),this.preview.reset(),this.tried.reset(),this.draft.value=void 0,this.secret.value=``}edit(e){this.draft.value=e,this.preview.load(()=>this.#e.previewMcp.call({rules:e}),`Couldn't preview these rules.`,this.preview.value.value!==void 0)}revert(){let e=this.view.value.value;e!==void 0&&this.edit(e.rules)}async update(e={}){let t=this.id.value;if(t===void 0)return{ok:!1,problem:`No MCP is open.`};let n=e.rules??this.draft.value,r=await this.save.run(()=>this.#e.updateMcp.call({mcp:t,...e,...n===void 0?{}:{rules:n}}),`Couldn't save the MCP.`);return r.ok&&(this.view.set(r.value),this.draft.value=r.value.rules),r}async rotateSecret(){let e=this.id.value;if(e===void 0)return{ok:!1,problem:`No MCP is open.`};let t=await this.rotate.run(()=>this.#e.rotateMcpSecret.call({mcp:e}),`Couldn't rotate the secret.`);return t.ok&&(this.secret.value=t.value.secret,this.sessions.set([])),t}async delete(){let e=this.id.value;if(e===void 0)return!1;let t=await this.remove.run(()=>this.#e.deleteMcp.call({mcp:e}),`Couldn't delete the MCP.`);return t.ok&&t.value.ok}async loadSessions(e=!1){let t=this.id.value;t!==void 0&&await this.sessions.load(()=>this.#e.mcpSessions.call({mcp:t}),`Couldn't load this MCP's sessions.`,e)}async tryIt(e){let t=this.view.value.value,n=e.trim()===``?this.secret.value:e.trim();t!==void 0&&n!==``&&await this.tried.load(()=>this.#t.tools(t.url,n),`Couldn't reach the MCP with that secret.`)}};async function Ys(e,t,n,r,i,a){let o=n.type===``?`application/octet-stream`:n.type,{url:s,upload:c}=await e.upload.call({name:r,mime:o,size:n.size});return await t.put(s,n,i,a),e.uploaded.call({upload:c})}var Xs={make:e=>e.type.startsWith(`image/`)?URL.createObjectURL(e):void 0,revoke:e=>{URL.revokeObjectURL(e)}},Zs=class{#e;#t;#n;#r=new Map;#i=1;items=L([]);busy=k(()=>this.items.value.some(e=>e.status===`uploading`));parts=k(()=>this.items.value.flatMap(e=>e.ref===void 0?[]:[{type:`file`,ref:e.ref,name:e.name}]));constructor(e,t,n=Xs){this.#e=e,this.#t=t,this.#n=n}add(e){for(let t of e){let e=this.#i++,n=this.#n.make(t);this.#r.set(e,{file:t,abort:new AbortController}),this.items.value=[...this.items.value,{id:e,name:t.name===``?`pasted file`:t.name,size:t.size,mime:t.type,status:`uploading`,progress:0,...n===void 0?{}:{preview:n}}],this.#a(e)}}remove(e){this.#r.get(e)?.abort.abort(),this.#r.delete(e);let t=this.items.value.find(t=>t.id===e);t?.preview!==void 0&&this.#n.revoke(t.preview),this.items.value=this.items.value.filter(t=>t.id!==e)}retry(e){let t=this.#r.get(e);t!==void 0&&(this.#r.set(e,{file:t.file,abort:new AbortController}),this.#o(e,{status:`uploading`,progress:0}),this.#a(e))}clear(){for(let e of[...this.#r.keys()])this.remove(e)}async#a(e){let t=this.#r.get(e);if(t!==void 0)try{let n=await Ys(this.#e,this.#t,t.file,t.file.name===``?`pasted file`:t.file.name,t=>{this.#o(e,{progress:t})},t.abort.signal);this.#o(e,{status:`ready`,progress:1,ref:n})}catch(t){if(!this.#r.has(e))return;this.#o(e,{status:`failed`,problem:X(t,t instanceof Error?t.message:`Upload failed.`)})}}#o(e,t){this.items.value=this.items.value.map(n=>n.id===e?{...n,...t}:n)}};function Qs(e){return/\.zip$/i.test(e.name)}var $s=class{#e;#t;install=new U;progress=I(0);#n;constructor(e,t){this.#e=e,this.#t=t}async installZip(e,t){if(!Qs(e))return{ok:!1,problem:`A package is a .zip made by harness system pack.`};let n=t.instance.trim();if(n!==``&&!vn.safeParse(n).success)return{ok:!1,problem:`An instance name is lowercase letters, digits and dashes, starting with a letter.`};this.#n=new AbortController;let r=this.#n.signal;return this.progress.value=0,this.install.run(async()=>{let i=await Ys(this.#e,this.#t,e,e.name,e=>{this.progress.value=e},r),a=t.data===void 0?void 0:await Ys(this.#e,this.#t,t.data,t.data.name,()=>void 0,r);return this.#e.installPackage.call({zip:i,autoStart:t.autoStart,...n===``?{}:{instance:vn.parse(n)},...t.config===void 0?{}:{config:t.config},...a===void 0?{}:{data:a},...t.store===void 0?{}:{store:t.store}})},`Couldn't install that package.`)}cancel(){this.#n?.abort()}},ec=2e3;function tc(e){return e!==void 0&&e.phase!==`done`&&e.phase!==`failed`}function nc(e){let t=e?.status?.state;return e?.holding===!0||t===`preparing`||t===`migrating`||t===`moving`||tc(e?.move)}var rc=class{#e;view=new W;moveTask=new U;answering=new U;deleting=new U;deletedNote=I(``);#t;#n;constructor(e){this.#e=e}async open(e,t,n=!1){let r=this.#t?.system!==e||this.#t.instance!==t;r&&this.close(),this.#t={system:e,instance:t},await this.view.load(()=>this.#e.systemStore.call({system:e,...t===void 0?{}:{instance:t}}),`Couldn't read its storage.`,n&&!r),this.#a()}async refresh(){this.#t!==void 0&&await this.open(this.#t.system,this.#t.instance,!0)}async move(e){if(this.#t===void 0)return{ok:!1,problem:`No store is open.`};let t=await this.moveTask.run(()=>this.#e.systemStoreMove.call({...this.#r(),to:e}),`Couldn't start the move.`);return t.ok&&this.#i(t.value),this.refresh(),t}async answer(e){let t=await this.answering.run(()=>this.#e.systemStoreMoveAnswer.call({...this.#r(),answer:e}),`Couldn't answer the move.`);return t.ok&&this.#i(t.value),this.refresh(),t}async deleteBackup(e){this.deletedNote.value=``;let t=await this.deleting.run(()=>this.#e.systemStoreBackupDelete.call({...this.#r(),backup:e}),`Couldn't delete that backup.`);if(!t.ok)return!1;this.deletedNote.value=t.value.note??``;let n=this.view.value.value;return n!==void 0&&this.view.set({...n,backups:n.backups.filter(t=>t.id!==e)}),this.refresh(),!0}close(){this.#n!==void 0&&clearTimeout(this.#n),this.#n=void 0,this.#t=void 0,this.deletedNote.value=``,this.view.reset()}#r(){let e=this.#t;if(e===void 0)throw Error(`no store is open`);return{system:e.system,...e.instance===void 0?{}:{instance:e.instance}}}#i(e){let t=this.view.value.value;t!==void 0&&this.view.set({...t,move:e}),this.#a()}#a(){this.#n!==void 0&&clearTimeout(this.#n),this.#n=void 0,this.#t!==void 0&&nc(this.view.value.value)&&(this.#n=setTimeout(()=>{this.refresh()},ec))}},Q={hub:`Hub`,group:`Group`,user:`Person`,session:`Chat`,turn:`Message`,system:`System`,fn:`Fn`,model:`Model`},ic=[`hub`,`group`,`user`,`session`,`system`,`fn`,`model`],ac=[`hub`,`group`,`user`,`session`,`turn`],oc={urgent:`Urgent`,interactive:`Interactive`,normal:`Normal`,background:`Background`};function sc(e,t){switch(e.scope){case`hub`:return`Whole hub`;case`group`:return`${Q.group}: ${t(e.group)}`;case`user`:return`${Q.user}: ${t(e.user)}`;case`session`:return`${Q.session}: ${e.session}`;case`turn`:return`${Q.turn}: ${e.turn}`;case`system`:return`${Q.system}: ${e.system}`;case`fn`:return`${Q.fn}: ${J(e.fn)}`;case`model`:return`${Q.model}: ${e.model}`}}var cc=[{label:`Hour`,ms:36e5},{label:`Day`,ms:864e5},{label:`Week`,ms:6048e5},{label:`30 days`,ms:2592e6}];function lc(e){if(e===`all-time`)return`all time`;if(e===`per-turn`)return`per message`;let t=cc.find(t=>t.ms===e.window);return t===void 0?`per ${z(e.window)}`:`per ${t.label.toLowerCase()}`}var uc={refuse:`Refuses`,wait:`Waits for room`,ask:`Asks to raise it`};function dc(e){let t=e.maxCost<=0?1:Math.min(1,Math.max(0,e.spent/e.maxCost));return{fraction:t,tone:t>=1?`danger`:t>=.8?`warn`:`ok`}}function fc(e){let t=[`${B(e.maxCost)} ${lc(e.period)}`];return e.maxTokens!==void 0&&t.push(`${e.maxTokens.toLocaleString()} tokens`),e.maxCalls!==void 0&&t.push(`${e.maxCalls.toLocaleString()} calls`),e.maxTime!==void 0&&t.push(`${z(e.maxTime)} each`),t.join(` · `)}function pc(e){let t=`${Q[e.priorityFrom.default].toLowerCase()} default`,n=e.priorityFrom.cappedBy===void 0?``:`, capped by the ${Q[e.priorityFrom.cappedBy].toLowerCase()}`;return{priority:`${oc[e.priority]}, from the ${t}${n}.`,turn:`Each message may spend up to ${B(e.turn.cost)} and run for ${z(e.turn.time)}.`,tightest:e.limitedBy===void 0?-1:e.budgets.findIndex(t=>t.rule===e.limitedBy)}}var mc={setBudget:An.endpoints.setBudget.cfg.body,setPriority:An.endpoints.setPriority.cfg.body,setPolicy:An.endpoints.setPolicy.cfg.body,setModelCategory:An.endpoints.setModelCategory.cfg.body,createPairingToken:An.endpoints.createPairingToken.cfg.body,upgradeSystem:An.endpoints.upgradeSystem.cfg.body},hc=e=>e.trim()===``?void 0:Number(e),gc=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``)),_c=e=>e===void 0?``:String(e),vc={group:`group`,user:`user`};function yc(e){return e.level===`hub`?{scope:`hub`}:{scope:e.level,[e.level]:e.target.trim()}}function bc(e){let t=e[e.scope];return{level:e.scope,target:typeof t==`string`?t:``}}function xc(e){let t=e?.period;return{scope:e===void 0?{level:`hub`,target:``}:bc(e.target),period:t===void 0||typeof t==`object`?`window`:t,window:t!==void 0&&typeof t==`object`?t.window:cc[1].ms,maxCost:e===void 0?``:String(e.maxCost),maxTokens:_c(e?.maxTokens),maxCalls:_c(e?.maxCalls),maxTime:e?.maxTime===void 0?``:String(e.maxTime/1e3),share:e?.share??`pooled`,onLimit:e?.onLimit??`refuse`}}function Sc(e){let t=e.period===`window`?{window:e.window}:e.period,n=hc(e.maxTime);return Z(mc.setBudget,gc({target:yc(e.scope),period:t,maxCost:hc(e.maxCost)??NaN,maxTokens:hc(e.maxTokens),maxCalls:hc(e.maxCalls),maxTime:e.period===`per-turn`&&n!==void 0?Math.round(n*1e3):void 0,share:e.scope.level===`group`?e.share:void 0,onLimit:e.onLimit}))}function Cc(e){return{scope:e===void 0?{level:`hub`,target:``}:bc(e.target),default:e?.default??``,max:e?.max??``}}function wc(e){return e.default===``&&e.max===``?{ok:!1,problems:{default:`Set a default, a ceiling, or both.`}}:Z(mc.setPriority,gc({target:yc(e.scope),default:e.default,max:e.max}))}function Tc(e){let t=e?.subject,n=e?.decision,r=n?.effect===`ask`?n.approver:void 0;return{description:e?.description??``,subject:t===void 0||`everyone`in t?`everyone`:`actor`in t?`actor`:`group`in t?`group`:`kind`,subjectValue:t===void 0||`everyone`in t?``:`actor`in t?t.actor:`group`in t?t.group:t.kind,fn:e?.target.fn??``,system:e?.target.system??``,kind:e?.target.kind??``,tags:[...e?.target.tags??[]],effect:n?.effect??`ask`,reason:n?.effect===`deny`?n.reason:``,approver:r?.by??`turn-user`,approverValue:r===void 0?``:r.by===`actor`?r.actor:r.by===`group`?r.group:r.by===`judge`?r.fn:``,quorum:r?.by===`group`?_c(r.quorum):``,priority:String(e?.priority??0)}}function Ec(e){let t=e.subjectValue.trim(),n=e.subject===`everyone`?{everyone:!0}:{[e.subject]:t},r=e.tags.map(e=>e.trim()).filter(e=>e!==``),i=gc({fn:e.fn.trim(),system:e.system.trim(),kind:e.kind.trim(),tags:r.length===0?void 0:r}),a=e.approverValue.trim(),o=e.approver===`actor`?{by:`actor`,actor:a}:e.approver===`group`?gc({by:`group`,group:a,quorum:hc(e.quorum)}):e.approver===`judge`?{by:`judge`,fn:a}:{by:e.approver},s=e.effect===`allow`?{effect:`allow`}:e.effect===`deny`?{effect:`deny`,reason:e.reason.trim()}:{effect:`ask`,approver:o};return e.effect===`deny`&&e.reason.trim()===``?{ok:!1,problems:{decision:`Say why, for the people it stops.`}}:e.description.trim()===``?{ok:!1,problems:{description:`Required.`}}:Z(mc.setPolicy,{description:e.description.trim(),subject:n,target:i,decision:s,priority:hc(e.priority)??0})}function Dc(e){return{name:e?.name??``,description:e?.description??``,models:e?.models??[]}}function Oc(e){return e.name.trim()===``?{ok:!1,problems:{name:`Required.`}}:e.models.length===0?{ok:!1,problems:{models:`Add at least one model.`}}:Z(mc.setModelCategory,{name:e.name.trim(),description:e.description.trim(),models:[...e.models]})}var kc=[{value:`keys`,label:`Access keys`},{value:`apiKey`,label:`API key`}],Ac={apiKey:{label:`API key`,secret:!0},baseURL:{label:`Base URL`,secret:!1},contextWindow:{label:`Context window (tokens)`,secret:!1,kind:`number`},decisionModels:{label:`Decision models`,secret:!1,kind:`list`,placeholder:`qwen3-systemone`,hint:`System One models to treat as decision models, comma separated. Only needed when the server’s /api/show lists no capabilities; newer servers say so themselves.`},region:{label:`Region`,secret:!1,placeholder:`us-east-1`},accessKeyId:{label:`Access key ID`,secret:!1},secretAccessKey:{label:`Secret access key`,secret:!0},sessionToken:{label:`Session token`,secret:!0,hint:`Only for temporary credentials.`},profilePrefix:{label:`Inference profile prefix`,secret:!1,placeholder:`us.`,hint:`Left empty, one is picked for the region.`}},jc={openai:`OpenAI`,anthropic:`Anthropic`,google:`Google Gemini`,openrouter:`OpenRouter`,ollama:`Ollama`,aws:`Amazon Bedrock`};function Mc(e){let t=pn.safeParse(e);return t.success?jc[t.data]:e}var Nc=e=>e in Ac;function Pc(e){let t=Zn.options.find(t=>t.shape.provider.value===e);if(t===void 0)throw Error(`No provider input schema for ${e}`);return t}function Fc(e){let t=Pc(`aws`).shape;if(!(`auth`in t))throw Error(`The AWS provider input has no sign-in`);let n=t.auth.options.find(t=>t.shape.kind.value===e);if(n===void 0)throw Error(`No AWS sign-in schema for ${e}`);return n}function Ic(e){return Object.entries(e).flatMap(([e,t])=>Nc(e)?[{name:e,...Ac[e],required:!t.safeParse(void 0).success}]:[])}function Lc(e,t=`keys`){let n=Pc(e).shape;if(e!==`aws`)return Ic(n);let r=Ic(n);return[...r.filter(e=>e.name===`region`),...Ic(Fc(t).shape),...r.filter(e=>e.name!==`region`)]}function Rc(e,t,n=`keys`){let r=e=>gc(Object.fromEntries(e.map(e=>[e.name,zc(e,t[e.name])]))),i=e===`aws`?Ic(Fc(n).shape):[],a=Lc(e,n).filter(e=>!i.includes(e)),o=e===`aws`?{provider:e,...r(a),auth:{kind:n,...r(i)}}:{provider:e,...r(a)},s=Z(Pc(e),o);if(s.ok)return{ok:!0,value:s.value};let c={},l=e===`aws`&&`auth`in s.problems?{...s.problems,...Bc(n,o)}:s.problems;for(let[e,t]of Object.entries(l))Nc(e)&&(c[e]=t);return{ok:!1,problems:c}}function zc(e,t){let n=t?.trim();if(n!==void 0&&n!==``){if(e.kind===`number`)return Number(n);if(e.kind===`list`){let e=n.split(/[,\n]/).map(e=>e.trim()).filter(e=>e!==``);return e.length===0?void 0:e}return n}}function Bc(e,t){let n=Z(Fc(e),t.auth);return n.ok?{}:n.problems}var Vc=[`package`,`path`,`git`];function Hc(e){let t=_n.options.find(t=>e in t.shape);if(t===void 0)throw Error(`No install source schema for ${e}`);return t}function Uc(e){return Object.keys(Hc(e).shape).filter(Gc)}var Wc={package:!0,version:!0,path:!0,git:!0,ref:!0,zip:!0,file:!0},Gc=e=>Object.hasOwn(Wc,e);function Kc(e){let t=Uc(e.kind),n=Object.fromEntries(t.map(t=>[t,(e.fields[t]??``).trim()])),r=Z(Hc(e.kind),n),i=r.ok?{}:r.problems,a={};for(let e of t){let t=n[e]===``?`Required.`:i[e];t!==void 0&&(a[e]=t)}return r.ok&&Object.keys(a).length===0?{ok:!0,value:r.value}:{ok:!1,problems:a}}var qc=[{label:`15 minutes`,ms:9e5},{label:`1 hour`,ms:36e5},{label:`1 day`,ms:864e5}],Jc=[{label:`90 days`,ms:7776e6},{label:`30 days`,ms:2592e6},{label:`1 year`,ms:31536e6},{label:`Never ends`,ms:null}];function Yc(e){return e===void 0?{}:{autoPair:e}}function Xc(e,t){let n=e.trim(),r=Z(mc.createPairingToken,n===``?{expiresIn:t}:{name:n,expiresIn:t});return r.ok?r:{ok:!1,problems:{...r.problems,...r.problems.name===void 0?{}:{name:`Lowercase letters, digits and dashes, starting with a letter.`}}}}var Zc=class{#e;#t;#n;#r;request=new W;answer=new U;system=I(void 0);status=L(void 0);#i=I(void 0);phase=k(()=>{if(this.#i.value===`refused`)return`refused`;if(this.answer.busy.value)return`pairing`;if(this.#i.value===`approved`)return this.status.value===`connected`?`connected`:this.status.value===`needs-config`?`needs-config`:`joining`;let e=this.request.value.value;return e===void 0?`loading`:e.status===`expired`||e.expiresAt<=this.#n()?`expired`:e.status===`pending`?`waiting`:`elsewhere`});constructor(e,t,n=Date.now){this.#e=e,this.#t=t,this.#n=n}async open(e){this.request.value.value?.id!==e&&this.close(),this.#r??=this.#t(e=>{this.#a(e)}),await this.request.load(()=>this.#e.pairing.call({pairing:e}),`Couldn't load this pairing request. It may have expired or been answered.`)}close(){this.#r?.(),this.#r=void 0,this.request.reset(),this.system.value=void 0,this.status.value=void 0,this.#i.value=void 0}codeMatches(e){let t=this.request.value.value;return t===void 0?!1:t.code===void 0||t.code===e.trim()}async approve(e,t,n,r){let i=this.request.value.value;if(i===void 0)return{ok:!1,problem:`No pairing request is open.`};let a=await this.answer.run(()=>this.#e.approvePairing.call({pairing:i.id,approve:!0,...e===void 0?{}:{instance:e},...t===void 0?{}:{config:t},...Yc(n),...r===void 0?{}:{store:r}}),`Couldn't pair it.`);return a.ok&&(this.#i.value=`approved`,this.system.value=a.value.system??i.name,this.status.value??=`pairing`),a}async refuse(){let e=this.request.value.value;if(e===void 0)return!1;let t=await this.answer.run(()=>this.#e.approvePairing.call({pairing:e.id,approve:!1}),`Couldn't refuse it.`);return t.ok&&(this.#i.value=`refused`),t.ok}#a(e){let t=this.request.value.value;if(e.type===`pairing`&&t!==void 0&&e.pairing.id===t.id){this.request.set(e.pairing);return}let n=this.system.value??t?.name;e.type===`system`&&e.system===n&&(this.status.value=e.status)}},Qc=class{#e;budgets=new W;priorities=new W;resolved=new W;save=new U;remove=new U;constructor(e){this.#e=e}async load(e=!1){await Promise.all([this.#t(e),this.#n(e)])}async saveBudget(e){let t=await this.save.run(()=>this.#e.setBudget.call(e),`Couldn't save the budget.`);return t.ok&&this.#t(!0),t}async savePriority(e){let t=await this.save.run(()=>this.#e.setPriority.call(e),`Couldn't save the priority rule.`);return t.ok&&this.#n(!0),t}async removeBudget(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`budget`,id:e}),`Couldn't remove the budget.`);return t.ok&&this.budgets.set((this.budgets.value.value??[]).filter(t=>t.id!==e)),t.ok}async removePriority(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`priority`,id:e}),`Couldn't remove the priority rule.`);return t.ok&&this.priorities.set((this.priorities.value.value??[]).filter(t=>t.id!==e)),t.ok}async resolve(e,t){await this.resolved.load(()=>this.#e.resolveLimits.call({user:e,...t===void 0?{}:{session:t}}),`Couldn't work out the limits.`)}#t(e){return this.budgets.load(()=>this.#e.budgets.call({}),`Couldn't load budgets.`,e)}#n(e){return this.priorities.load(()=>this.#e.priorityRules.call({}),`Couldn't load priority rules.`,e)}},$c=class{#e;providers=new W;models=new W;categories=new W;save=new U;remove=new U;modelIds=k(()=>(this.models.value.value??[]).map(e=>e.id).sort());constructor(e){this.#e=e}async load(e=!1){await Promise.all([this.providers.load(()=>this.#e.providers.call({}),`Couldn't load providers.`,e),this.models.load(()=>this.#e.models.call({}),`Couldn't load models.`,e),this.categories.load(()=>this.#e.modelCategories.call({}),`Couldn't load model categories.`,e)])}async saveProvider(e){let t=await this.save.run(()=>this.#e.configureProvider.call(e),`Couldn't save the provider.`);return t.ok&&this.load(!0),t}async saveCategory(e){let t=await this.save.run(()=>this.#e.setModelCategory.call(e),`Couldn't save the category.`);return t.ok&&this.categories.load(()=>this.#e.modelCategories.call({}),`Couldn't load model categories.`,!0),t}async removeCategory(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`category`,id:e}),`Couldn't remove the category.`);return t.ok&&this.categories.set((this.categories.value.value??[]).filter(t=>t.id!==e)),t.ok}async removeProvider(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`provider`,id:e}),`Couldn't remove the provider.`);return t.ok&&this.load(!0),t.ok}},el={user:{plural:`people`,label:`People`},group:{plural:`groups`,label:`Groups`},agent:{plural:`agents`,label:`Agents`},system:{plural:`systems`,label:`Systems`},mcp:{plural:`MCP clients`,label:`MCP clients`}};function tl(e,t){return`actor`in e?t(e.actor):`group`in e?`Group ${t(e.group)}`:`kind`in e?`All ${el[e.kind].plural}`:`Everyone`}function nl(e){let t=[];if(e.fn!==void 0){let n=$n.safeParse(e.fn);t.push(n.success&&!e.fn.includes(`*`)?J(n.data):e.fn)}return e.system!==void 0&&t.push(`fns of ${e.system}`),e.kind!==void 0&&t.push(e.kind===`native`?`native fns`:`${e.kind} fns`),e.tags!==void 0&&e.tags.length>0&&t.push(`tagged ${e.tags.join(`, `)}`),e.when!==void 0&&t.push(`when its args match`),t.length===0?`any fn`:t.join(`, `)}function rl(e,t){switch(e.by){case`turn-user`:return`the message's sender`;case`actor`:return t(e.actor);case`group`:return`group ${t(e.group)}${e.quorum===void 0?``:` (${e.quorum} needed)`}`;case`judge`:return`the judge ${J(e.fn)}`;case`hub`:return`the hub`;case`admins`:return`an admin`}}function il(e,t){switch(e.effect){case`allow`:return{word:`Allow`,detail:`runs without asking`,tone:`ok`};case`deny`:return{word:`Deny`,detail:e.reason,tone:`danger`};case`ask`:return{word:`Ask`,detail:`asks ${rl(e.approver,t)}`,tone:`warn`}}}function al(e){let t={deny:0,ask:1,allow:2};return[...e].sort((e,n)=>n.priority-e.priority||t[e.decision.effect]-t[n.decision.effect])}var ol=class{#e;list=new W;sorted=k(()=>al(this.list.value.value??[]));save=new U;remove=new U;constructor(e){this.#e=e}async load(e=!1){await this.list.load(()=>this.#e.policies.call({}),`Couldn't load policies.`,e)}async savePolicy(e){let t=await this.save.run(()=>this.#e.setPolicy.call(e),`Couldn't save the policy.`);return t.ok&&this.load(!0),t}async removePolicy(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`policy`,id:e}),`Couldn't remove the policy.`);return t.ok&&this.list.set((this.list.value.value??[]).filter(t=>t.id!==e)),t.ok}},sl=class{#e;users;groups;person=new W;members=new W;signIn=new W;checks=L(new Map);checking=L(void 0);test=new W;save=new U;constructor(e){this.#e=e,this.users=new f({fetch:(t,n,r)=>e.people.call(h(t,r,n)),key:e=>e.id,failure:`Couldn’t load the people.`,limit:50},{}),this.groups=new f({fetch:(t,n,r)=>e.groups.call(h(t,r,n)),key:e=>e.id,failure:`Couldn’t load the groups.`,limit:50},{})}openPerson(e,t=!1){return this.person.load(async()=>(await this.#e.people.call({filters:[{field:`email`,op:`is`,value:e}],limit:1})).items[0],`Couldn’t load them.`,t)}openGroup(e,t=!1){return this.members.load(()=>this.#e.groupMembers.call({group:e,limit:200}),`Couldn’t load the group.`,t)}loadSignIn(e=!1){return this.signIn.load(()=>this.#e.signInSettings.call({}),`Couldn’t load how people sign in.`,e)}loadTest(e){return this.test.load(()=>this.#e.ssoTestResult.call({test:e}),`Couldn’t read the test sign-in.`)}async check(e){this.checking.value=e;try{let t=await this.#e.checkSsoProvider.call({provider:e});this.checks.value=new Map([...this.checks.value,[e,t]])}catch(t){let n=t instanceof Error?t.message:String(t);this.checks.value=new Map([...this.checks.value,[e,{provider:e,ok:!1,discovery:{ok:!1,detail:n},keys:{ok:!1,detail:`Not checked.`},checkedAt:Date.now()}]])}finally{this.checking.value=void 0}}startTest(e){return this.save.run(()=>this.#e.testSsoSignIn.call({provider:e}),`Couldn’t start the test sign-in.`)}addPerson(e){let t={name:e.name,email:e.email,role:e.role,...e.groups===void 0?{}:{groups:[...e.groups]}};return this.#t(this.save.run(()=>this.#e.addUser.call(t),`Couldn’t add them.`))}addGroup(e){return this.#t(this.save.run(()=>this.#e.addGroup.call(e),`Couldn’t add the group.`))}update(e){return this.#t(this.save.run(()=>this.#e.updateUser.call(e),`Couldn’t change them.`))}membership(e){return this.#t(this.save.run(()=>this.#e.setMembership.call(e),`Couldn’t change the group.`))}async setPolicy(e){let t=await this.save.run(()=>this.#e.setSignInPolicy.call(e),`Couldn’t save who can join.`);return t.ok&&this.loadSignIn(!0),t}async setLimits(e){let t=await this.save.run(()=>this.#e.setSignInLimits.call(e),`Couldn’t save the sign-in limits.`);return t.ok&&this.loadSignIn(!0),t}async setProxy(e){let t=await this.save.run(()=>this.#e.setProxyTrust.call(e),`Couldn’t save the proxy setting.`);return t.ok&&this.loadSignIn(!0),t}async#t(e){let t=await e;if(!t.ok)return t;this.users.refresh(),this.groups.refresh();let n=this.person.value.value;n!==void 0&&this.openPerson(n.email,!0);let r=this.members.value.value?.group;return r!==void 0&&this.openGroup(r.id,!0),t}};function cl(e,t,n){let r=e??[];return r.some(e=>n(e,t))?r.map(e=>n(e,t)?t:e):[...r,t]}var ll=class{#e;roles=new W;limits=new W;save=new U;constructor(e){this.#e=e}async loadRoles(e=!1){await this.roles.load(()=>this.#e.modelRoles.call({}),`Couldn't load the model roles.`,e)}async loadLimits(e=!1){await this.limits.load(()=>this.#e.modelLimits.call({}),`Couldn't load the model limits.`,e)}role(e){return this.roles.value.value?.find(t=>t.role===e)}async setRole(e){let t=await this.save.run(()=>this.#e.setModelRole.call(e),`Couldn't save that role.`);return t.ok&&this.roles.set(cl(this.roles.value.value,t.value,(e,t)=>e.role===t.role)),t}async clearRole(e){let t=await this.save.run(()=>this.#e.clearModelRole.call({role:e}),`Couldn't clear that role.`);return t.ok&&this.roles.set(cl(this.roles.value.value,t.value,(e,t)=>e.role===t.role)),t}async setLimits(e,t){let n=await this.save.run(()=>this.#e.setModelLimits.call({model:e,limits:t}),`Couldn't save the limits of ${e}.`);return n.ok&&this.limits.set(cl(this.limits.value.value,n.value,(e,t)=>e.model===t.model)),n}},ul=class{#e;data=new W;save=new U;groups=k(()=>{let e=this.data.value.value;if(e===void 0)return[];let t=new Map;for(let n of[...e.declared].sort((e,t)=>e.setting.localeCompare(t.setting))){let r={view:n,values:e.values.filter(e=>e.setting===n.setting)};t.set(n.system,[...t.get(n.system)??[],r])}return[...t].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({system:e,settings:t}))});constructor(e){this.#e=e}async load(e=!1){await this.data.load(()=>this.#e.actorSettings.call({}),`Couldn't load actor settings.`,e)}async set(e,t,n,r,i){let a=await this.save.run(()=>this.#e.setActorSetting.call({setting:e,actor:t,value:n}),`Couldn't save the setting.`),o=this.data.value.value;if(!a.ok||!a.value.ok||o===void 0)return a.ok&&a.value.ok;let s={setting:e,actor:t,value:n,setBy:r,updatedAt:i};return this.data.set({...o,values:[...o.values.filter(n=>n.setting!==e||n.actor!==t),s]}),!0}},dl=class{#e;review=new W;refusals;switching=new U;deciding=new U;decidingChange=I(void 0);testing=new U;off=k(()=>Kr(this.review.value.value?.off??[]));constructor(e){this.#e=e,this.refusals=new f({fetch:async({system:e,rule:t},n,r)=>{if(e===void 0)return{items:[]};let i=await this.#e.refusals.call({system:e,limit:r,...t===void 0?{}:{rule:t},...n===void 0?{}:{cursor:n}});return{items:i.items,...i.next===void 0?{}:{cursor:i.next}}},key:e=>e.id,failure:`Couldn't load the refusals.`,limit:50},{system:void 0,rule:void 0})}async open(e){let t=this.review.value.value?.system===e;t||this.review.reset(),await this.review.load(()=>this.#e.systemReview.call({system:e}),`Couldn't load this system's review.`,t)}async loadRefusals(e,t){await this.refusals.load({system:e,rule:t})}isOn(e){return!this.off.value.has(Gr(e))}async switch(e,t){let n=this.review.value.value;if(n===void 0)return!1;let r=n.off;this.review.set({...n,off:Jr(r,e,t)});let i=await this.switching.run(()=>this.#t(n.system,e,t),`Couldn't switch that.`);if(!i.ok){let n=this.review.value.value;n!==void 0&&this.review.set({...n,off:Jr(n.off,e,!t)})}return i.ok}async#t(e,t,n){let{section:r,name:i}=t;r===`fns`||r===`context`?await this.#e.switchItem.call({section:r,name:$n.parse(i),on:n}):await this.#e.switchPart.call({system:e,section:r,name:i,on:n})}#n(e){let t=this.review.value.value;return t===void 0?void 0:{system:t.system,hash:e,off:t.off}}async goLive(){let e=this.review.value.value,t=e===void 0?void 0:this.#n(e.manifest.hash);if(e===void 0||t===void 0)return{ok:!1,problem:`No system is open.`};let n=await this.deciding.run(()=>this.#e.goLive.call(t),`Couldn't go live.`);return this.open(e.system),n.ok?{ok:!0,value:n.value.stage}:n}async approve(){let e=this.review.value.value,t=e?.pending,n=t===void 0?void 0:this.#n(t.hash);if(e===void 0||n===void 0)return{ok:!1,problem:`Nothing waits for review.`};let r=await this.deciding.run(()=>this.#e.approveReview.call(n),`Couldn't approve the changes.`);return this.open(e.system),r.ok?{ok:!0,value:r.value.hash}:r}async decide(e,t){let n=this.review.value.value,r=n?.pending;if(n===void 0||r===void 0)return{ok:!1,problem:`Nothing waits for review.`};this.decidingChange.value=Yr(e);let i=qr(e),a={system:n.system,hash:r.hash,approve:t===`approve`?[i]:[],decline:t===`decline`?[i]:[],off:[]};try{let e=await this.deciding.run(()=>this.#e.decideReview.call(a),t===`approve`?`Couldn't approve that change.`:`Couldn't decline that change.`);return await this.open(n.system),e}finally{this.decidingChange.value=void 0}}async reject(){let e=this.review.value.value,t=e?.pending;if(e===void 0||t===void 0)return{ok:!1,problem:`Nothing waits for review.`};let n=await this.deciding.run(()=>this.#e.rejectReview.call({system:e.system,hash:t.hash}),`Couldn't reject the changes.`);return this.open(e.system),n.ok?{ok:!0,value:n.value.ok}:n}async testCall(e,t){let n=await this.testing.run(()=>this.#e.testCall.call({fn:e,args:t}),`Couldn't run that.`);return n.ok?{ok:!0,value:n.value.run}:n}close(){this.review.reset(),this.refusals.load({system:void 0,rule:void 0})}},fl=1e3,pl=`Restarted by an admin from its page`,ml=class{#e;#t;#n;#r;#i;name=I(void 0);view=new W;fns=new W;logs=new W;config=new U;enabling=new U;switching=new U;action=new U;acting=L(void 0);constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}async open(e){this.name.value!==e&&(this.close(),this.name.value=e),this.#r??=this.#t(e=>{this.#o(e)}),await this.view.load(()=>this.#e.system.call({system:e}),`Couldn't load this system.`,this.view.value.value?.name===e)}close(){this.#r?.(),this.#r=void 0,this.unfollowLogs(),this.name.value=void 0,this.view.reset(),this.fns.reset(),this.logs.reset()}async loadFns(){let e=this.name.value;e!==void 0&&await this.fns.load(()=>this.#e.systemFns.call({system:e}),`Couldn't load this system's fns.`)}fnSwitched(e,t){let n=this.fns.value.value;n!==void 0&&this.fns.set(n.map(n=>n.name===e?{...n,disabled:!t}:n))}async switchFn(e,t){if(this.fnSwitched(e,t),!(await this.switching.run(()=>this.#e.switchItem.call({section:`fns`,name:e,on:t}),`Couldn't switch that.`)).ok)return this.fnSwitched(e,!t),!1;let n=this.name.value;return n!==void 0&&await this.fns.load(()=>this.#e.systemFns.call({system:n}),`Couldn't load this system's fns.`,!0),!0}async followLogs(){let e=this.name.value;e!==void 0&&(this.#i??=this.#n(e,e=>{let t=this.logs.value.value??[];this.logs.set([...t,e].slice(-1e3))}),await this.logs.load(()=>this.#e.systemLogs.call({system:e,limit:fl}),`Couldn't load this system's output.`))}unfollowLogs(){this.#i?.(),this.#i=void 0}async configure(e){let t=this.name.value;if(t===void 0)return{ok:!1,problems:[`No system is open.`]};let n=await this.config.run(()=>this.#e.configureSystem.call({system:t,config:e}),`Couldn't save the config.`);return n.ok?`problems`in n.value?{ok:!1,problems:n.value.problems}:(this.open(t),{ok:!0,version:n.value.version}):{ok:!1,problems:[n.problem]}}async enable(e,t){let n=this.name.value,r=this.view.value.value;if(n===void 0||r===void 0)return!1;this.view.set({...r,enabled:{...r.enabled,[e]:t}});let i=await this.enabling.run(()=>this.#e.enableSystem.call({system:n,[e]:t}),`Couldn't change that.`),a=this.view.value.value;return a===void 0||this.view.set({...a,enabled:i.ok?i.value.enabled:r.enabled}),i.ok}async act(e,t,n){let r=this.name.value;if(r===void 0)return{ok:!1,problem:`No system is open.`};this.acting.value=e;let i=await this.action.run(()=>this.#a(r,e,t,n),`Couldn't ${e} ${r}.`);return this.acting.value=void 0,i.ok&&e!==`remove`&&this.open(r),i}async#a(e,t,n,r){switch(t){case`start`:return await this.#e.startSystem.call({system:e}),{kind:`done`};case`stop`:return await this.#e.stopSystem.call({system:e}),{kind:`done`};case`restart`:return await this.#e.restartSystem.call({system:e,reason:pl}),{kind:`done`};case`upgrade`:return{kind:`upgrade`,...await this.#e.upgradeSystem.call({system:e,...n===void 0||n===``?{}:{version:n}})};case`reimport`:return{kind:`reimport`,report:await this.#e.reimport.call({system:e})};case`remove`:return await this.#e.removeSystem.call({system:e,...r===void 0?{}:{keepStore:r}}),{kind:`done`}}}#o(e){let t=this.view.value.value;if(t===void 0||e.type!==`system`&&e.type!==`fn`||e.system!==t.name)return;if(e.type===`system`){this.view.set({...t,status:e.status});return}let n=this.fns.value.value;n?.some(t=>t.name===e.fn)===!0&&this.fns.set(n.map(t=>t.name===e.fn?{...t,stats:e.stats}:t))}},hl=class{#e;#t;context;types;contextCount=I(void 0);typeCount=I(void 0);others=new W;roots=new W;switching=new U;constructor(e){this.#e=e,this.context=new f({fetch:async(e,t,n)=>{if(e===void 0)return{items:[]};let r=await this.#e.query.call(vr(e,t,n));return t===void 0&&(this.contextCount.value=r.total),{items:In.array().parse(r.items),...r.cursor===void 0?{}:{cursor:r.cursor}}},key:e=>e.name,failure:`Couldn't load this system's context.`,limit:50},void 0),this.types=new f({fetch:async(e,t,n)=>{if(e===void 0)return{items:[]};let r=await this.#e.query.call(Rs({system:e},t,n));return t===void 0&&(this.typeCount.value=r.total),{items:Pn.array().parse(r.items),...r.cursor===void 0?{}:{cursor:r.cursor}}},key:e=>e.name,failure:`Couldn't load this system's types.`,limit:50},void 0)}async loadContext(e){this.context.filter.value===e&&this.context.loaded.value?await this.context.refresh():(this.contextCount.value=void 0,await this.context.load(e))}async loadTypes(e){this.types.filter.value===e&&this.types.loaded.value?await this.types.refresh():(this.typeCount.value=void 0,await this.types.load(e))}async loadOthers(e){let t=this.#t===e&&this.others.value.value!==void 0;t||(this.others.reset(),this.roots.reset()),this.#t=e,await Promise.all([this.others.load(()=>this.#e.systemParts.call({system:e}),`Couldn't load what this system added.`,t),this.roots.load(()=>this.#e.exploreRoots.call({system:e}),`Couldn't load this system's resource roots.`,t)])}async switchContext(e,t){this.context.update(e,e=>({...e,status:t?`active`:`hidden`}));let n=await this.switching.run(()=>this.#e.switchItem.call({section:`context`,name:e,on:t}),`Couldn't switch that.`);return n.ok||this.context.update(e,e=>({...e,status:t?`hidden`:`active`})),n.ok}close(){this.others.reset(),this.roots.reset(),this.#t=void 0,this.context.load(void 0),this.types.load(void 0),this.contextCount.value=void 0,this.typeCount.value=void 0}},gl=class{#e;#t;#n;list=new W;pairings=new W;query=L({});sorted=k(()=>{let e=this.list.value.value??[];return this.query.value.sort===void 0?Cr(e):e});pending=k(()=>(this.pairings.value.value??[]).filter(e=>e.status===`pending`).length);answering=L(new Set);answer=new U;token=new U;install=new U;constructor(e,t){this.#e=e,this.#t=t}start(){this.#n??=this.#t(e=>{this.#i(e)})}stop(){this.#n?.(),this.#n=void 0}async load(e=!1){await Promise.all([this.#r(e),this.pairings.load(()=>this.#e.pairings.call({status:`pending`}),`Couldn't load pairing requests.`,e)])}async search(e){JSON.stringify(e)!==JSON.stringify(this.query.value)&&(this.query.value=e,await this.#r(!1))}async#r(e){let t=this.query.value;await this.list.load(()=>this.#e.systems.call(Object.keys(t).length===0?{}:{query:t}),`Couldn't load systems.`,e)}async answerPairing(e,t,n,r){this.answering.value=new Set([...this.answering.value,e]);let i=await this.answer.run(()=>this.#e.approvePairing.call({pairing:e,approve:t,...t?Yc(n):{},...t&&r!==void 0?{store:r}:{}}),t?`Couldn't approve the pairing.`:`Couldn't reject the pairing.`);return this.answering.value=new Set([...this.answering.value].filter(t=>t!==e)),i.ok&&(this.pairings.set((this.pairings.value.value??[]).filter(t=>t.id!==e)),t&&this.#r(!0)),i}async createToken(e,t,n){return this.token.run(()=>this.#e.createPairingToken.call({expiresIn:t,...e===void 0?{}:{name:e},...Yc(n)}),`Couldn't make a pairing token.`)}async installSystem(e,t,n,r){let i=await this.install.run(()=>this.#e.installSystem.call({source:e,autoStart:t,...n===void 0?{}:{config:n},...r===void 0?{}:{store:r}}),`Couldn't install the system.`);return i.ok&&this.load(!0),i}#i(e){if(e.type===`system`){let t=this.list.value.value;if(t===void 0)return;if(!t.some(t=>t.name===e.system)){this.load(!0);return}this.list.set(t.map(t=>t.name===e.system?{...t,status:e.status}:t))}else if(e.type===`pairing`){let t=e.pairing,n=(this.pairings.value.value??[]).filter(e=>e.id!==t.id);this.pairings.set(t.status===`pending`?[t,...n]:n)}}},_l=class{actors;systems;system;systemParts;review;models;roles;limits;policies;settings;runs;runApprovals;llm;modelCalls;fn;injected;itemInjected;instance;instanceParts;packages;storage;mcps;mcp;pairing;resources;fns;suggestions;classifier;images;autoPairs;people;constructor(e){let{api:t}=e;this.actors=new Ds(t),this.systems=new gl(t,e.userEvents),this.system=new ml(t,e.userEvents,e.systemLogs),this.systemParts=new hl(t),this.review=new dl(t),this.models=new $c(t),this.roles=new ll(t),this.limits=new Qc(t),this.policies=new ol(t),this.settings=new ul(t),this.runs=Ms(t,e.chat),this.runApprovals=new Os(e.chat),this.llm=Ns(t,e.chat),this.modelCalls=Ps(t,e.chat),this.fn=new Wi(t,e.userEvents),this.injected=new Mr(t),this.itemInjected=new Mr(t),this.instance=new Is(t,e.userEvents),this.instanceParts=new Ks(t,e.chat),this.packages=new $s(t,e.sender),this.storage=new rc(t),this.mcps=new qs(t),this.mcp=new Js(t,e.probe),this.pairing=new Zc(t,e.userEvents),this.resources=Fs(t,e.chat),this.suggestions=new ws(t),this.classifier=new Ts(t),this.images=new Es(t),this.autoPairs=new Cs(t),this.people=new sl(t),this.fns=new f({fetch:(e,n,r)=>t.fns.call({...e,limit:r,...n===void 0?{}:{cursor:n}}),key:e=>e.name,failure:`Couldn't load the fns.`,limit:50},{})}start(){this.systems.start(),this.systems.pairings.value.value===void 0&&this.systems.load(!0)}stop(){this.systems.stop(),this.system.close()}};function vl(e){return{systems:e.caller(`systems`,{dedupe:!0}),system:e.caller(`system`,{dedupe:!0}),pairings:e.caller(`pairings`,{dedupe:!0}),approvePairing:e.caller(`approvePairing`),createPairingToken:e.caller(`createPairingToken`),configureSystem:e.caller(`configureSystem`),enableSystem:e.caller(`enableSystem`),switchItem:e.caller(`switchItem`),switchPart:e.caller(`switchPart`),systemReview:e.caller(`systemReview`,{dedupe:!0}),goLive:e.caller(`goLive`),approveReview:e.caller(`approveReview`),rejectReview:e.caller(`rejectReview`),decideReview:e.caller(`decideReview`),testCall:e.caller(`testCall`),refusals:e.caller(`refusals`,{lastOnly:!0}),removeSystem:e.caller(`removeSystem`),installSystem:e.caller(`installSystem`),systemStore:e.caller(`systemStore`),systemStoreMove:e.caller(`systemStoreMove`),systemStoreMoveState:e.caller(`systemStoreMoveState`),systemStoreMoveAnswer:e.caller(`systemStoreMoveAnswer`),systemStoreBackups:e.caller(`systemStoreBackups`),systemStoreBackupDelete:e.caller(`systemStoreBackupDelete`),startSystem:e.caller(`startSystem`),stopSystem:e.caller(`stopSystem`),restartSystem:e.caller(`restartSystem`),upgradeSystem:e.caller(`upgradeSystem`),reimport:e.caller(`reimport`),systemFns:e.caller(`systemFns`,{dedupe:!0}),systemLogs:e.caller(`systemLogs`,{dedupe:!0}),systemParts:e.caller(`systemParts`,{dedupe:!0}),exploreRoots:e.caller(`exploreRoots`,{dedupe:!0}),providers:e.caller(`providers`,{dedupe:!0}),configureProvider:e.caller(`configureProvider`),models:e.caller(`models`,{dedupe:!0}),modelCategories:e.caller(`modelCategories`,{dedupe:!0}),setModelCategory:e.caller(`setModelCategory`),budgets:e.caller(`budgets`,{dedupe:!0}),setBudget:e.caller(`setBudget`),priorityRules:e.caller(`priorityRules`,{dedupe:!0}),setPriority:e.caller(`setPriority`),resolveLimits:e.caller(`resolveLimits`,{lastOnly:!0}),policies:e.caller(`policies`,{dedupe:!0}),setPolicy:e.caller(`setPolicy`),removeRule:e.caller(`removeRule`),actors:e.caller(`actors`,{dedupe:!0}),actorSettings:e.caller(`actorSettings`,{dedupe:!0}),setActorSetting:e.caller(`setActorSetting`),runs:e.caller(`runs`,{lastOnly:!0}),fns:e.caller(`fns`,{lastOnly:!0}),llmCalls:e.caller(`llmCalls`,{lastOnly:!0}),query:e.caller(`query`),resources:e.caller(`resources`,{lastOnly:!0}),modelRoles:e.caller(`modelRoles`,{dedupe:!0}),setModelRole:e.caller(`setModelRole`),clearModelRole:e.caller(`clearModelRole`),modelLimits:e.caller(`modelLimits`,{dedupe:!0}),setModelLimits:e.caller(`setModelLimits`),modelCalls:e.caller(`modelCalls`,{lastOnly:!0}),modelCall:e.caller(`modelCall`,{dedupe:!0}),fnMetrics:e.caller(`fnMetrics`,{dedupe:!0}),fnMetricsDays:e.caller(`fnMetricsDays`,{dedupe:!0}),mcps:e.caller(`mcps`,{dedupe:!0}),mcp:e.caller(`mcp`,{dedupe:!0}),createMcp:e.caller(`createMcp`),updateMcp:e.caller(`updateMcp`),rotateMcpSecret:e.caller(`rotateMcpSecret`),deleteMcp:e.caller(`deleteMcp`),previewMcp:e.caller(`previewMcp`,{lastOnly:!0}),mcpSessions:e.caller(`mcpSessions`,{dedupe:!0}),pairing:e.caller(`pairing`,{dedupe:!0}),instances:e.caller(`instances`,{dedupe:!0}),installPackage:e.caller(`installPackage`),removeInstance:e.caller(`removeInstance`),addInstance:e.caller(`addInstance`),readFn:e.caller(`readFn`),exportSystemData:e.caller(`exportSystemData`),autoPairs:e.caller(`autoPairs`,{dedupe:!0}),revokeAutoPair:e.caller(`revokeAutoPair`),suggestDecision:e.caller(`suggestDecision`,{dedupe:!0}),setSuggestDecision:e.caller(`setSuggestDecision`),previewSuggestions:e.caller(`previewSuggestions`,{lastOnly:!0}),searchDecisions:e.caller(`searchDecisions`,{dedupe:!0}),setSearchDecision:e.caller(`setSearchDecision`),injections:e.caller(`injections`,{lastOnly:!0}),setInjection:e.caller(`setInjection`),autoClassifier:e.caller(`autoClassifier`,{dedupe:!0}),setAutoClassifier:e.caller(`setAutoClassifier`),imageEmbedding:e.caller(`imageEmbedding`,{dedupe:!0}),setImageEmbedding:e.caller(`setImageEmbedding`),upload:e.caller(`upload`),uploaded:e.caller(`uploaded`),people:e.caller(`people`,{lastOnly:!0}),groups:e.caller(`groups`,{lastOnly:!0}),groupMembers:e.caller(`groupMembers`,{lastOnly:!0}),addUser:e.caller(`addUser`),addGroup:e.caller(`addGroup`),updateUser:e.caller(`updateUser`),setMembership:e.caller(`setMembership`),signInSettings:e.caller(`signInSettings`,{dedupe:!0}),setSignInPolicy:e.caller(`setSignInPolicy`),setSignInLimits:e.caller(`setSignInLimits`),setProxyTrust:e.caller(`setProxyTrust`),checkSsoProvider:e.caller(`checkSsoProvider`),testSsoSignIn:e.caller(`testSsoSignIn`),ssoTestResult:e.caller(`ssoTestResult`,{lastOnly:!0})}}function yl(e){return(t,n)=>e.on(`systemLog`,{system:t},n)}var bl=`connections`;function xl(e){return{connectPages:e.caller(`connectPages`,{cache:{ttl:3e4,tags:[bl]},dedupe:!0}),connect:e.caller(`connect`,{invalidates:[bl]}),updateConnection:e.caller(`updateConnection`,{invalidates:[bl]}),disconnect:e.caller(`disconnect`,{invalidates:[bl]})}}var Sl=`access`;function Cl(e){return{pick:e.caller(`pick`,{cache:{ttl:15e3},dedupe:!0}),accessInfo:e.caller(`accessInfo`,{cache:{ttl:6e4},dedupe:!0}),access:e.caller(`access`,{cache:{ttl:3e4,tags:[Sl]},dedupe:!0}),setAccess:e.caller(`setAccess`,{invalidates:[Sl]})}}var wl=`sessions`,Tl=`capabilities`;function El(e){return{capabilities:e.caller(`capabilities`,{cache:{ttl:6e4,tags:[Tl]},dedupe:!0}),types:e.caller(`types`,{cache:{ttl:3e5,tags:[Tl]},dedupe:!0}),sessions:e.caller(`sessions`,{cache:{ttl:5e3,tags:[wl]},dedupe:!0,lastOnly:!0}),searchSessions:e.caller(`sessions`,{debounce:250,lastOnly:!0}),session:e.caller(`session`,{dedupe:!0}),listValues:e.caller(`listValues`,{cache:{ttl:1e4},dedupe:!0}),createSession:e.caller(`createSession`,{invalidates:[wl]}),updateSession:e.caller(`updateSession`,{invalidates:[wl]}),deleteSession:e.caller(`deleteSession`,{invalidates:[wl]}),limits:e.caller(`limits`,{dedupe:!0}),messages:e.caller(`messages`,{dedupe:!0}),send:e.caller(`send`,{invalidates:[wl]}),invoke:e.caller(`invoke`),compare:e.caller(`compare`,{invalidates:[wl]}),compareView:e.caller(`compareView`,{lastOnly:!0}),chooseVariant:e.caller(`chooseVariant`,{invalidates:[wl]}),control:e.caller(`control`),controls:e.caller(`controls`,{dedupe:!0}),background:e.caller(`background`),undoTurn:e.caller(`undoTurn`),continueTurn:e.caller(`continueTurn`),tree:e.caller(`tree`,{dedupe:!0}),treeRefresh:e.caller(`tree`,{debounce:400,lastOnly:!0}),run:e.caller(`run`,{dedupe:!0}),llmCall:e.caller(`llmCall`,{cache:{ttl:3e5},dedupe:!0}),suggest:e.caller(`suggest`,{debounce:700,lastOnly:!0}),mentions:e.caller(`mentions`),mentionHover:e.caller(`mentionHover`,{cache:{ttl:3e4},dedupe:!0}),waiting:e.caller(`waiting`),approve:e.caller(`approve`),approvals:e.caller(`approvals`,{dedupe:!0}),contributions:e.caller(`contributions`,{cache:{ttl:6e4,tags:[Tl]},dedupe:!0}),setBudget:e.caller(`setBudget`),answer:e.caller(`answer`),presence:e.caller(`presence`),resource:e.caller(`resource`,{cache:{ttl:3e4},dedupe:!0}),upload:e.caller(`upload`),uploaded:e.caller(`uploaded`),transcribe:e.caller(`transcribe`),act:e.caller(`act`),submit:e.caller(`submit`),state:e.caller(`state`,{dedupe:!0}),previewSelection:e.caller(`previewSelection`,{lastOnly:!0}),...Cl(e),...xl(e)}}function Dl(e){return(t,n)=>e.on(`session`,{session:t},n)}var Ol=class{put(e,t,n,r){return new Promise((i,a)=>{let o=new XMLHttpRequest;o.open(`PUT`,e),t.type!==``&&o.setRequestHeader(`content-type`,t.type),o.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&n(e.loaded/e.total)},o.onload=()=>{o.status>=200&&o.status<300?(n(1),i()):a(Error(`Upload failed (${o.status}).`))},o.onerror=()=>{a(Error(`Upload failed.`))},o.onabort=()=>{a(new DOMException(`Upload cancelled.`,`AbortError`))},r.addEventListener(`abort`,()=>{o.abort()},{once:!0}),o.send(t)})}};function kl(e){return{setup:e.caller(`setup`,{cache:{ttl:5e3},dedupe:!0}),createAdmin:e.caller(`createAdmin`),signIn:e.caller(`signIn`),refresh:e.caller(`refresh`),redeemSso:e.caller(`redeemSso`),signOut:e.caller(`signOut`),me:e.caller(`me`,{dedupe:!0}),account:e.caller(`account`,{dedupe:!0})}}var Al={transport:`http`};function jl(e){return{identity:e.caller(`identity`,{dedupe:!0}),setHubName:e.caller(`setHubName`)}}function Ml(e){return{outsideImages:e.caller(`outsideImages`,{dedupe:!0}),setOutsideImages:e.caller(`setOutsideImages`)}}function Nl(e){return{https:e.caller(`https`,{dedupe:!0}),setHttps:e.caller(`setHttps`)}}var Pl=`inbox`;function Fl(e){return{list:e.caller(`notifications`,{cache:{ttl:1e4,tags:[Pl]},dedupe:!0}),markRead:e.caller(`readNotifications`,{invalidates:[Pl],retry:{attempts:3}}),pushKey:e.caller(`pushKey`,{cache:{ttl:36e5},dedupe:!0}),subscribePush:e.caller(`subscribePush`,{retry:{attempts:3}})}}function Il(e,t){return n=>{let r,i=S(t,t=>{r?.(),r=t===void 0?void 0:e.on(`user`,{user:t},n)},{immediate:!0});return()=>{i(),r?.()}}}function Ll(e){return{browse:e.caller(`browseResources`,{lastOnly:!0}),browseGroup:e.caller(`browseResources`),find:e.caller(`browseResources`,{lastOnly:!0}),forms:e.caller(`resourceForms`,{dedupe:!0}),read:e.caller(`readResource`,{dedupe:!0}),convert:e.caller(`convertResource`),download:e.caller(`downloadResource`,{dedupe:!0}),importResource:e.caller(`importResource`),rename:e.caller(`renameResource`),remove:e.caller(`deleteResource`),contextFrom:e.caller(`contextFromResource`),upload:e.caller(`upload`),uploaded:e.caller(`uploaded`),systemRead:e.caller(`resource`,{dedupe:!0}),exploreRoots:e.caller(`exploreRoots`,{lastOnly:!0}),exploreList:e.caller(`exploreList`),exploreRead:e.caller(`exploreRead`,{lastOnly:!0})}}function Rl(e){return t=>e(e=>{e.type===`resource`&&t({uri:e.uri,forms:e.forms})})}function zl(e){return{list:e.caller(`contexts`,{lastOnly:!0}),item:e.caller(`contextItem`,{dedupe:!0}),remember:e.caller(`remember`),updateMemory:e.caller(`updateMemory`),forget:e.caller(`forget`),link:e.caller(`linkContext`),unlink:e.caller(`unlinkContext`),fromResource:e.caller(`contextFromResource`),values:e.caller(`listValues`),metadata:e.caller(`contextMetadata`,{dedupe:!0}),setStatus:e.caller(`setContextStatus`),review:e.caller(`contextReview`,{lastOnly:!0}),merge:e.caller(`mergeContext`),notDuplicate:e.caller(`notDuplicate`),reextract:e.caller(`reextractContext`),newStatus:e.caller(`newContextStatus`),setNewStatus:e.caller(`setNewContextStatus`),plans:e.caller(`contextPlans`,{lastOnly:!0}),plan:e.caller(`contextPlan`),answerPlan:e.caller(`answerPlan`)}}function Bl(e){return t=>e(e=>{e.type===`context`&&t(e.name)})}function Vl(e){return{searchFns:e.caller(`searchFns`,{cache:{ttl:3e4},dedupe:!0}),fnFacts:e.caller(`fnFacts`,{dedupe:!0}),fnExamples:e.caller(`fnExamples`,{dedupe:!0}),fnsOfModelNames:e.caller(`fnsOfModelNames`,{dedupe:!0})}}function Hl(e){return{graph:e.caller(`graph`,{lastOnly:!0})}}var Ul=`records`;function Wl(e){return{dataSets:e.caller(`dataSets`,{cache:{ttl:1e4,tags:[Ul]},dedupe:!0,lastOnly:!0}),records:e.caller(`records`,{dedupe:!0,lastOnly:!0}),recordTable:e.caller(`recordTable`,{lastOnly:!0}),record:e.caller(`record`,{dedupe:!0}),saveRecord:e.caller(`saveRecord`,{invalidates:[Ul]}),removeRecord:e.caller(`removeRecord`,{invalidates:[Ul]}),recordVersions:e.caller(`recordVersions`,{dedupe:!0}),rowActions:e.caller(`rowActions`,{cache:{ttl:3e4},dedupe:!0}),readFn:e.caller(`readFn`),exportCsv:e.caller(`export`),itemVersions:e.caller(`itemVersions`,{dedupe:!0})}}function Gl(e){return{systemPages:e.caller(`systemPages`,{dedupe:!0})}}function Kl(e,t){let n=Il(e,t);return{auth:kl(e),identity:jl(e),outsideImages:Ml(e),https:Nl(e),notifications:Fl(e),userEvents:n,chat:El(e),sessionEvents:Dl(e),admin:vl(e),systemLogs:yl(e),resources:Ll(e),resourceEvents:Rl(n),context:zl(e),fns:Vl(e),graph:Hl(e),data:Wl(e),pages:Gl(e),contextEvents:Bl(n),connection:e.connection}}function ql(e){let t=new Map(e.questions.map(e=>[e.name,e])),n=Hn(e),r=new Set(e.roots.filter(e=>t.has(e))),i=new Map;for(let t of e.questions)for(let e of t.options)for(let n of e.raises)r.has(n)&&i.set(n,[...i.get(n)??[],{question:t,via:e.label}]);let a=new Set,o=[],s=(e,c,l)=>{let u=t.get(e);if(u===void 0)return;let d=n.get(e)?.live===!0,f=a.has(e),p=c===0&&!f?i.get(e):void 0;if(o.push({question:u,indent:c,...l===void 0?{}:{via:l},live:d,repeat:f,...p===void 0?{}:{alsoRaisedBy:p}}),!f){a.add(e);for(let e of u.options)for(let t of e.raises)r.has(t)||s(t,c+1,e.label)}};for(let t of e.roots)s(t,0,void 0);for(let t of e.questions)a.has(t.name)||s(t.name,0,void 0);return o}function Jl(e,t){return!t||e.status===`not_applicable`?{label:`Ruled out`,tone:`neutral`}:e.known===!0?{label:`Answered in context`,tone:`ok`}:bn(e)?{label:`Answered`,tone:`ok`}:e.status===`hidden`?{label:`Hidden`,tone:`warn`}:e.planned?{label:`Open`,tone:`accent`}:{label:`No options yet`,tone:`warn`}}var Yl={person:`For you`,system:`For the system`,research:`To research`};function Xl(e){return e.stop===`complete`?er(e.counts):`${er(e.counts)} · ${Sn[e.stop]}`}function Zl(e){return[`${e.answered} answered`,`${e.open} open`,`${e.decide} to decide now`,...e.ruledOut>0?[`${e.ruledOut} ruled out`]:[]]}function Ql(e){return`plan-${e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)||`plan`}.md`}function $l(e,t){return Math.max(0,Math.round((e-t)/2))}var eu=28,tu=72,nu=36,ru=252,iu=16,au=24,ou=6.4,su=4,cu=20,lu=16,uu=[.62,.5,.74,.4,.84,.3,.9,.22];function du(e,t){let n=e.y+64;return{x1:e.x+100,y1:n,x2:t.x+100,y2:t.y,bend:Math.max(30,Math.abs(t.y-n)/2)}}function fu(e,t){let{x1:n,y1:r,x2:i,y2:a,bend:o}=e,s=1-t,[c,l,u,d]=[s*s*s,3*s*s*t,3*s*t*t,t*t*t];return{x:c*n+l*n+u*i+d*i,y:c*r+l*(r+o)+u*(a-o)+d*a}}function pu(e,t){return e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height}function mu(e,t,n,r,i){for(let a of uu){let o=fu(e,a);for(let e of[0,-t/2-2,t/2+2]){let a={x:o.x+e-t/2,y:o.y-n/2,width:t,height:n};if(!(a.x<0||a.y<0||a.x+a.width>i.width||a.y+a.height>i.height)&&!r.some(e=>pu(a,e)))return a}}}function hu(e){let t=Hn(e),n=ql(e).filter(e=>!e.repeat).map(e=>e.question),r=new Map;for(let e of n)r.set(e.depth,[...r.get(e.depth)??[],e]);let i=[...r.keys()].sort((e,t)=>e-t),a=Math.max(1,...[...r.values()].map(e=>e.length)),o=32+a*200+(a-1)*eu,s=new Map;for(let t of e.questions)for(let e of t.options)for(let n of e.raises){let r=t.picked.includes(e.id)?`picked`:t.picked.length>0?`not`:`open`,i=`${t.name} ${n}`,a=s.get(i);s.set(i,a===void 0?{from:t.name,to:n,label:e.label,state:r}:{from:t.name,to:n,label:`${a.label} / ${e.label}`,state:a.state===`picked`||r===`picked`?`picked`:a.state===`open`||r===`open`?`open`:`not`})}let c=[...s.values()],l={picked:0,open:1,not:2},u=[...c].sort((e,t)=>l[e.state]-l[t.state]),d=i.slice(1).map(()=>tu);for(;;){let e=new Map,n=[],a=iu;i.forEach((i,s)=>{let c=r.get(i)??[],l=c.length*200+(c.length-1)*eu,u=(o-l)/2;c.forEach((r,i)=>{let o=t.get(r.name)?.live===!0?bn(r)?`answered`:r.planned?`open`:`unplanned`:`out`,c=r.options.filter(e=>r.picked.includes(e.id)).map(e=>e.label).join(`, `);n.push({name:r.name,label:r.question,x:u+i*228,y:a,state:o,picked:c}),e.set(r.name,s)}),a+=64+(d[s]??0)});let s=a-(d[i.length-1]??0)+iu,l={width:o,height:s},f=new Map(n.map(e=>[e.name,e])),p=n.map(e=>({x:e.x-4,y:e.y-4,width:208,height:72})),m=new Map,h=new Set,g=[];for(let t of u){let n=f.get(t.from),r=f.get(t.to);if(n===void 0||r===void 0)continue;let i=_u(t.label,au,2),a=mu(du(n,r),Math.max(...i.map(e=>e.length))*ou+8,i.length*13+su,p,l);a===void 0?(g.push(t),h.add(e.get(t.from)??0)):(p.push(a),m.set(`${t.from} ${t.to}`,{...a,lines:i}))}let _=!1;for(let e of h){let t=d[e];t!==void 0&&t<ru&&(d[e]=Math.min(ru,t+nu),_=!0)}if(g.length>0&&_)continue;let ee=new Map,te=[];for(let e of g){let t=f.get(e.from),n=f.get(e.to);if(t===void 0||n===void 0)continue;let r=du(t,n),i=mu(r,cu,lu,p,l),a=i===void 0?fu(r,.5):{x:i.x+cu/2,y:i.y+lu/2},o=te.length+1;i!==void 0&&p.push(i),ee.set(`${e.from} ${e.to}`,{n:o,x:a.x,y:a.y}),te.push({n:o,label:e.label,state:e.state})}return{width:o,height:s,nodes:n,edges:c.flatMap(e=>{let t=f.get(e.from),n=f.get(e.to);if(t===void 0||n===void 0)return[];let{x1:r,y1:i,x2:a,y2:o,bend:s}=du(t,n),c=`${e.from} ${e.to}`,l=m.get(c),u=ee.get(c);return[{...e,path:`M ${r} ${i} C ${r} ${i+s}, ${a} ${o-s}, ${a} ${o}`,...l===void 0?{}:{placed:l},...u===void 0?{}:{marker:u}}]}),legend:te}}}function gu(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function _u(e,t,n){let r=[],i=``;for(let n of e.split(/\s+/))i===``?i=n:i.length+1+n.length<=t?i=`${i} ${n}`:(r.push(i),i=n);if(i!==``&&r.push(i),r.length<=n)return r;let a=r.slice(0,n);return a[n-1]=gu(`${a[n-1]??``} ${r.slice(n).join(` `)}`,t),a}var vu={class:`plan-graph-wrap`},yu=[`width`,`height`,`viewBox`,`aria-label`],bu={class:`edges`},xu=[`d`],Su=[`d`],Cu={class:`labels`},wu=[`data-x`,`data-y`,`data-w`,`data-h`],Tu=[`x`,`y`,`width`,`height`],Eu=[`x`,`y`],Du=[`x`,`dy`],Ou=[`x`,`y`],ku=[`x`,`y`],Au=[`transform`,`aria-label`,`data-question`,`data-state`,`onClick`,`onKeydown`],ju=[`width`,`height`],Mu={x:`12`,y:`20`},Nu=[`dy`],Pu=[`y`],Fu={key:0,class:`legend`,"data-testid":`plan-graph-legend`,"aria-label":`Options too long to fit on their edges`},Iu={class:`n`},Lu=Y(A({__name:`PlanGraph`,props:{plan:{}},emits:[`pick`],setup(e,{emit:t}){let n=e,r=t,i=k(()=>hu(n.plan)),a=I(null),o=async()=>{await ke(),a.value!==null&&(a.value.scrollLeft=$l(i.value.width,a.value.clientWidth))};Se(()=>{o()}),S(()=>i.value.width,()=>{o()});let c=e=>_u(e.label,30,e.picked===``?3:2),l={answered:`answered`,open:`open`,out:`ruled out`,unplanned:`no options yet`};return(e,t)=>(j(),E(`div`,vu,[T(`div`,{ref_key:`box`,ref:a,class:`plan-graph`,"data-testid":`plan-graph`,tabindex:`0`,"aria-label":`The plan as a graph; scrolls both ways`},[(j(),E(`svg`,{width:i.value.width,height:i.value.height,viewBox:`0 0 ${i.value.width} ${i.value.height}`,role:`img`,"aria-label":`${i.value.nodes.length} questions and how they connect`},[t[0]||=T(`defs`,null,[T(`marker`,{id:`plan-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`},[T(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,class:`arrow`})])],-1),T(`g`,bu,[(j(!0),E(M,null,D(i.value.edges,e=>(j(),E(`g`,{key:`${e.from}-${e.to}`,class:w([`edge`,e.state]),"data-testid":`plan-graph-edge`},[T(`title`,null,P(e.label),1),T(`path`,{d:e.path,"marker-end":`url(#plan-arrow)`},null,8,xu),T(`path`,{d:e.path,class:`hit`},null,8,Su)],2))),128))]),T(`g`,Cu,[(j(!0),E(M,null,D(i.value.edges,e=>(j(),E(M,{key:`${e.from}-${e.to}-label`},[e.placed?(j(),E(`g`,{key:0,class:w([`label`,e.state]),"data-testid":`plan-graph-label`,"data-x":e.placed.x,"data-y":e.placed.y,"data-w":e.placed.width,"data-h":e.placed.height},[T(`title`,null,P(e.label),1),T(`rect`,{x:e.placed.x,y:e.placed.y,width:e.placed.width,height:e.placed.height,rx:`4`},null,8,Tu),T(`text`,{x:e.placed.x+e.placed.width/2,y:e.placed.y+C(13)-1,"text-anchor":`middle`},[(j(!0),E(M,null,D(e.placed.lines,(t,n)=>(j(),E(`tspan`,{key:n,x:e.placed.x+e.placed.width/2,dy:n===0?0:C(13)},P(t),9,Du))),128))],8,Eu)],10,wu)):e.marker?(j(),E(`g`,{key:1,class:w([`label`,`numbered`,e.state]),"data-testid":`plan-graph-marker`},[T(`title`,null,P(e.marker.n)+`: `+P(e.label),1),T(`rect`,{x:e.marker.x-10,y:e.marker.y-8,width:`20`,height:`16`,rx:`8`},null,8,Ou),T(`text`,{x:e.marker.x,y:e.marker.y+4,"text-anchor":`middle`},P(e.marker.n),9,ku)],2)):R(``,!0)],64))),128))]),(j(!0),E(M,null,D(i.value.nodes,e=>(j(),E(`g`,{key:e.name,class:w([`node`,e.state]),transform:`translate(${e.x} ${e.y})`,role:`button`,tabindex:`0`,"aria-label":`${e.label} (${l[e.state]})`,"data-testid":`plan-graph-node`,"data-question":e.name,"data-state":e.state,onClick:t=>r(`pick`,e.name),onKeydown:s(t=>r(`pick`,e.name),[`enter`])},[T(`rect`,{width:C(200),height:C(64),rx:`10`},null,8,ju),T(`text`,Mu,[(j(!0),E(M,null,D(c(e),(e,t)=>(j(),E(`tspan`,{key:t,x:`12`,dy:t===0?0:15},P(e),9,Nu))),128))]),e.picked===``?R(``,!0):(j(),E(`text`,{key:0,x:`12`,y:C(64)-10,class:`picked`},`✓ `+P(C(gu)(e.picked,28)),9,Pu))],42,Au))),128))],8,yu))],512),i.value.legend.length>0?(j(),E(`ol`,Fu,[(j(!0),E(M,null,D(i.value.legend,e=>(j(),E(`li`,{key:e.n,class:w(e.state)},[T(`span`,Iu,P(e.n),1),x(` `+P(e.label),1)],2))),128))])):R(``,!0)]))}}),[[`__scopeId`,`data-v-c009da68`]]),Ru=[`data-question`,`data-state`],zu={key:0,class:`again`},Bu={key:0,class:`via`},Vu={class:`head`},Hu=[`title`],Uu=[`id`],Wu={key:0,class:`also faint`,"data-testid":`plan-question-also`},Gu={key:0},Ku=[`title`,`onClick`],qu={class:`facts`},Ju={key:0,class:`faint`},Yu={key:1,class:`reason`,"data-testid":`plan-question-reason`},Xu={key:2,class:`reason-edit`},Zu={class:`row-actions`},Qu={key:3,class:`faint`},$u=[`aria-label`],ed=[`aria-pressed`,`disabled`,`title`,`data-option`,`onClick`],td={key:5,class:`faint`},nd={key:6,class:`own`},rd={class:`row-actions`},id=Y(A({__name:`PlanQuestionRow`,props:{row:{},busy:{type:Boolean,default:!1},deeper:{type:Boolean,default:!1},canDeepen:{type:Boolean,default:!0}},emits:[`answer`,`reason`,`deeper`,`jump`],setup(e,{emit:t}){let n=e,r=t,i=k(()=>n.row.question),a=k(()=>Jl(i.value,n.row.live)),o=k(()=>!n.row.live||i.value.status===`not_applicable`),s=k(()=>i.value.known===!0),c=I(i.value.text??``),l=I(i.value.statusReason??``),u=I(!1);S(()=>i.value.text,e=>{c.value=e??``}),S(()=>i.value.statusReason,e=>{l.value=e??``});let d=k(()=>c.value.trim()!==(i.value.text??``).trim()),f=k(()=>!i.value.planned&&!bn(i.value));function p(e){if(o.value||s.value)return;let t=i.value.picked.includes(e)?i.value.picked.filter(t=>t!==e):[...i.value.picked,e];r(`answer`,{question:i.value.name,picked:t,...c.value.trim()===``?{}:{text:c.value.trim()}})}function h(){r(`answer`,{question:i.value.name,picked:[...i.value.picked],...c.value.trim()===``?{}:{text:c.value.trim()}})}function g(){let e=l.value.trim();e!==``&&(r(`reason`,{question:i.value.name,reason:e}),u.value=!1)}return(t,n)=>(j(),E(`li`,{class:w([`plan-q`,{out:o.value,repeat:e.row.repeat}]),style:Ce({"--indent":String(Math.min(e.row.indent,6))}),"data-testid":`plan-question`,"data-question":i.value.name,"data-state":a.value.label},[e.row.repeat?(j(),E(`div`,zu,[e.row.via?(j(),E(`span`,Bu,P(e.row.via)+` →`,1)):R(``,!0),T(`button`,{type:`button`,class:`link`,"data-testid":`plan-question-jump`,onClick:n[0]||=e=>r(`jump`,i.value.name)},P(i.value.question),1),n[7]||=T(`span`,{class:`faint`},`(shown above)`,-1)])):(j(),E(M,{key:1},[T(`div`,Vu,[e.row.via?(j(),E(`span`,{key:0,class:`via`,title:`Raised by choosing “${e.row.via}”`},P(e.row.via)+` →`,9,Hu)):R(``,!0),T(`h3`,{id:`q-${i.value.name}`,class:`words`},P(i.value.question),9,Uu)]),e.row.alsoRaisedBy!==void 0&&e.row.alsoRaisedBy.length>0?(j(),E(`p`,Wu,[n[8]||=x(` Also raised by `,-1),(j(!0),E(M,null,D(e.row.alsoRaisedBy,(e,t)=>(j(),E(M,{key:`${e.question.name}-${e.via}`},[t>0?(j(),E(`span`,Gu,`, `)):R(``,!0),T(`button`,{type:`button`,class:`link`,"data-testid":`plan-question-also-jump`,title:`Choosing “${e.via}” for “${e.question.question}”`,onClick:t=>r(`jump`,e.question.name)},` “`+P(e.via)+`” `,9,Ku)],64))),128))])):R(``,!0),T(`div`,qu,[b(C(V),{tone:a.value.tone,"data-testid":`plan-question-state`},{default:N(()=>[x(P(a.value.label),1)]),_:1},8,[`tone`]),i.value.askedBy?(j(),E(`span`,Ju,P(C(Yl)[i.value.askedBy]??i.value.askedBy),1)):R(``,!0),b(C(m),{class:`faint item-link`,to:C(y).contextItem(i.value.name),"data-testid":`plan-question-item`,title:`Open ${i.value.name} on its context page to edit it`},{default:N(()=>[b(C(Ft),{name:`edit`,size:12}),n[9]||=x(` Context item `,-1)]),_:1},8,[`to`,`title`])]),o.value?(j(),E(`p`,Yu,[u.value?R(``,!0):(j(),E(M,{key:0},[T(`span`,null,P(i.value.statusReason??`Ruled out`),1),T(`button`,{type:`button`,class:`link`,"data-testid":`plan-reason-edit`,onClick:n[1]||=e=>u.value=!0},`Edit reason`)],64))])):R(``,!0),o.value&&u.value?(j(),E(`div`,Xu,[b(C(Lt),{modelValue:l.value,"onUpdate:modelValue":n[2]||=e=>l.value=e,label:`Why it doesn't apply`,rows:2,"data-testid":`plan-reason-text`},null,8,[`modelValue`]),T(`div`,Zu,[b(C(H),{size:`sm`,variant:`ghost`,onClick:n[3]||=e=>u.value=!1},{default:N(()=>[...n[10]||=[x(`Cancel`,-1)]]),_:1}),b(C(H),{size:`sm`,loading:e.busy,"data-testid":`plan-reason-save`,onClick:g},{default:N(()=>[...n[11]||=[x(`Save reason`,-1)]]),_:1},8,[`loading`])])])):R(``,!0),s.value?(j(),E(`p`,Qu,`Answered in context before this plan; change it on its context page.`)):R(``,!0),i.value.options.length>0?(j(),E(`div`,{key:4,class:`chips`,role:`group`,"aria-label":`Options for ${i.value.question}`},[(j(!0),E(M,null,D(i.value.options,t=>(j(),E(`button`,{key:t.id,type:`button`,class:w([`chip`,{picked:i.value.picked.includes(t.id)}]),"aria-pressed":i.value.picked.includes(t.id)?`true`:`false`,disabled:o.value||s.value||e.busy,title:t.detail,"data-testid":`plan-option`,"data-option":t.id,onClick:e=>p(t.id)},[i.value.picked.includes(t.id)?(j(),F(C(Ft),{key:0,name:`check`,size:12})):R(``,!0),x(P(t.label),1)],10,ed))),128))],8,$u)):f.value?(j(),E(`p`,td,`No options yet: planning deeper writes them.`)):R(``,!0),!o.value&&!s.value?(j(),E(`div`,nd,[b(C(Lt),{modelValue:c.value,"onUpdate:modelValue":n[4]||=e=>c.value=e,label:`Your own detail`,placeholder:`Anything the options leave out`,rows:1,"max-rows":6,disabled:e.busy,"data-testid":`plan-question-text`},null,8,[`modelValue`,`disabled`]),T(`div`,rd,[e.deeper&&e.canDeepen?(j(),F(C(H),{key:0,size:`sm`,variant:`ghost`,icon:`tree`,"data-testid":`plan-deeper-here`,onClick:n[5]||=e=>r(`deeper`,i.value.name)},{default:N(()=>[...n[12]||=[x(`Plan deeper here`,-1)]]),_:1})):f.value&&e.canDeepen?(j(),F(C(H),{key:1,size:`sm`,variant:`ghost`,icon:`tree`,"data-testid":`plan-deeper-here`,onClick:n[6]||=e=>r(`deeper`,i.value.name)},{default:N(()=>[...n[13]||=[x(`Write its options`,-1)]]),_:1})):R(``,!0),d.value?(j(),F(C(H),{key:2,size:`sm`,loading:e.busy,"data-testid":`plan-question-save`,onClick:h},{default:N(()=>[...n[14]||=[x(`Save`,-1)]]),_:1},8,[`loading`])):R(``,!0)])])):R(``,!0)],64))],14,Ru))}}),[[`__scopeId`,`data-v-0a11b25c`]]),ad={key:0,class:`plan`},od={class:`top`},sd={class:`line`,"data-testid":`plan-dialog-counts`},cd={key:0,class:`outline`,"data-testid":`plan-outline`},ld=Y(A({__name:`PlanDialog`,props:ge({run:{},canDeepen:{type:Boolean,default:!0}},{open:{type:Boolean,required:!0},openModifiers:{}}),emits:ge([`deeper`],[`update:open`]),setup(e,{emit:t}){let n=e,r=_e(e,`open`),i=t,{context:a,toasts:o}=G(),s=a.plans,c=I(`outline`),l=[{value:`outline`,label:`Outline`,icon:`list`},{value:`graph`,label:`Graph`,icon:`graph`}];S([r,()=>n.run],([e])=>{e&&s.show(n.run)},{immediate:!0}),a.follow();let u=k(()=>s.open.value.value?.run===n.run?s.open.value.value.plan:void 0),d=k(()=>u.value===void 0?[]:ql(u.value)),f=k(()=>new Set(s.deeper.value));async function p(e){let t=await s.answer(n.run,e);if(!t.ok){o.error(`Couldn't save that`,t.problem);return}let[r]=t.value.skipped;r!==void 0&&o.error(`Part of that wasn't saved`,r.reason)}async function m(e){c.value=`outline`,await ke(),document.querySelector(`[data-testid="plan-question"][data-question="${CSS.escape(e)}"]`)?.scrollIntoView({block:`center`,behavior:`smooth`})}async function h(){let e=await s.markdown(n.run);if(e===void 0){o.error(`Couldn't export the plan`);return}let t=URL.createObjectURL(new Blob([e],{type:`text/markdown`})),r=document.createElement(`a`);r.href=t,r.download=Ql(u.value?.description??`plan`),r.click(),URL.revokeObjectURL(t)}async function g(){let e=await s.markdown(n.run);e===void 0||!await xt(e)?o.error(`Couldn't copy the plan`):o.ok(`Copied the plan as markdown`)}return(t,n)=>(j(),F(C(yt),{open:r.value,"onUpdate:open":n[6]||=e=>r.value=e,title:`Plan`,description:u.value?.description??``,width:`min(920px, 100vw)`,"data-testid":`plan-dialog`},{footer:N(()=>[b(C(H),{variant:`ghost`,icon:`copy`,"data-testid":`plan-copy`,onClick:g},{default:N(()=>[...n[7]||=[x(`Copy markdown`,-1)]]),_:1}),b(C(H),{variant:`ghost`,icon:`download`,"data-testid":`plan-export`,onClick:h},{default:N(()=>[...n[8]||=[x(`Export`,-1)]]),_:1}),e.canDeepen?(j(),F(C(H),{key:0,icon:`tree`,"data-testid":`plan-deeper`,onClick:n[5]||=e=>i(`deeper`,void 0)},{default:N(()=>[...n[9]||=[x(`Plan deeper`,-1)]]),_:1})):R(``,!0)]),default:N(()=>[b(Re,{loading:C(s).open.loading.value&&u.value===void 0,problem:C(s).open.problem.value,ready:u.value!==void 0,empty:!1,onRetry:n[4]||=t=>C(s).show(e.run)},{default:N(()=>[u.value?(j(),E(`div`,ad,[T(`div`,od,[T(`p`,sd,P(C(Xl)(u.value)),1),b(C(Gt),{modelValue:c.value,"onUpdate:modelValue":n[0]||=e=>c.value=e,options:l,label:`Plan view`,"data-testid":`plan-view`},null,8,[`modelValue`])]),c.value===`outline`?(j(),E(`ul`,cd,[(j(!0),E(M,null,D(d.value,(t,r)=>(j(),F(id,{key:`${t.question.name}-${r}`,row:t,busy:C(s).busyQuestion.value===t.question.name,deeper:f.value.has(t.question.name),"can-deepen":e.canDeepen,onAnswer:n[1]||=e=>p({answer:e}),onReason:n[2]||=e=>p({reason:e}),onDeeper:n[3]||=e=>i(`deeper`,e),onJump:m},null,8,[`row`,`busy`,`deeper`,`can-deepen`]))),128))])):(j(),F(Lu,{key:1,plan:u.value,onPick:m},null,8,[`plan`]))])):R(``,!0)]),_:1},8,[`loading`,`problem`,`ready`])]),_:1},8,[`open`,`description`]))}}),[[`__scopeId`,`data-v-e412ee45`]]),ud=[`data-run`],dd={key:0,class:`lead`},fd={class:`title`},pd=[`title`],md={class:`counts`,"data-testid":`plan-card-counts`},hd={key:0},gd={key:1,class:`limited`,"data-testid":`plan-card-stop`},_d={class:`actions`},vd=Y(A({__name:`PlanCardBody`,props:{planRun:{},plan:{},lead:{default:``}},emits:[`deeper`],setup(e,{emit:t}){let n=e,r=t,i=rn(),a=I(!1),o=k(()=>n.plan.stop===`complete`?``:Sn[n.plan.stop]),s=I(!1);function c(e){a.value=!1,s.value=!0,r(`deeper`,e),setTimeout(()=>{s.value=!1},1500)}return(t,n)=>(j(),E(`section`,{class:`plan-card`,"data-testid":`plan-card`,"data-run":e.planRun},[e.lead===``?R(``,!0):(j(),E(`p`,dd,P(e.lead),1)),T(`div`,fd,[b(C(Ft),{name:`tree`,size:16}),T(`p`,{class:`description`,title:e.plan.description},P(e.plan.description),9,pd)]),T(`p`,md,[T(`strong`,null,P(C(er)(e.plan.counts)),1),e.plan.counts.ruledOut>0?(j(),E(`span`,hd,` · `+P(e.plan.counts.ruledOut)+` ruled out`,1)):R(``,!0)]),o.value===``?R(``,!0):(j(),E(`p`,gd,P(o.value)+`; Plan deeper goes on from there.`,1)),T(`div`,_d,[C(i)?(j(),F(C(H),{key:0,size:`sm`,variant:`primary`,icon:`maximize`,"data-testid":`plan-card-open`,onClick:n[0]||=e=>a.value=!0},{default:N(()=>[...n[3]||=[x(`Open`,-1)]]),_:1})):R(``,!0),b(C(H),{size:`sm`,icon:`tree`,loading:s.value,"data-testid":`plan-card-deeper`,onClick:n[1]||=e=>c(void 0)},{default:N(()=>[...n[4]||=[x(`Plan deeper`,-1)]]),_:1},8,[`loading`])]),C(i)&&a.value?(j(),F(ld,{key:2,open:a.value,"onUpdate:open":n[2]||=e=>a.value=e,run:e.planRun,onDeeper:c},null,8,[`open`,`run`])):R(``,!0)],8,ud))}}),[[`__scopeId`,`data-v-b7e399b0`]]),yd=i(l,{results:{fns:{ctx_plan:A({__name:`PlanResult`,props:{run:{},fn:{},args:{},result:{},title:{},system:{}},setup(e){let t=e,n=k(()=>cn.safeParse(t.result));function r(e){t.system.run.ctx_plan_expand({run:t.run,...e===void 0?{}:{under:e}})}return(t,i)=>n.value.success?(j(),F(vd,{key:0,"plan-run":e.run,plan:n.value.data,onDeeper:r},null,8,[`plan-run`,`plan`])):R(``,!0)}}),ctx_plan_expand:A({__name:`PlanExpandResult`,props:{run:{},fn:{},args:{},result:{},title:{},system:{}},setup(e){let t=e,n=k(()=>zn.safeParse(t.result)),r=k(()=>t.args.replan===!0?`Re-planned`:`Planned deeper`);function i(e){n.value.success&&t.system.run.ctx_plan_expand({run:n.value.data.run,...e===void 0?{}:{under:e}})}return(e,t)=>n.value.success?(j(),F(vd,{key:0,"plan-run":n.value.data.run,plan:n.value.data.plan,lead:r.value,onDeeper:i},null,8,[`plan-run`,`plan`,`lead`])):R(``,!0)}})}}}),bd=class{#e;multiUser=I(!1);saving=new U;#t=!1;constructor(e){this.#e=e}async load(){if(!this.#t){this.#t=!0;try{this.multiUser.value=(await this.#e.accessInfo.call({})).multiUser}catch{this.#t=!1}}}view(e){let t=new W;return t.load(async()=>{let[t]=await this.#e.access.call({targets:[e]});if(t===void 0)throw Error(`The hub did not say who can use this.`);return t},`Couldn’t load who can use this.`),t}async set(e,t){return this.saving.run(()=>this.#e.setAccess.call({target:e,sharing:t}),`Couldn’t change who can use this.`)}};function xd(e,t){let n=[...e.connections].sort((e,t)=>t.updatedAt-e.updatedAt);return{own:n.find(e=>e.owner===t),shared:n.filter(e=>e.owner!==t)}}function Sd(e,t){return Object.entries(e.decl.fns).map(([n,r])=>{let i=t?.fns[n],a=i??r;return{local:n,name:`${e.system}/${n}`,option:a,changed:i!==void 0&&(i.on!==r.on||i.ask!==r.ask)}})}function Cd(e,t,n){return Object.fromEntries(e.map(e=>[e.local,e.local===t?{...e.option,...n}:e.option]))}var wd={pending:{label:`Waiting for sign-in`,tone:`warn`},connected:{label:`Connected`,tone:`ok`},expired:{label:`Expired`,tone:`warn`},failed:{label:`Failed`,tone:`danger`}},Td=e=>e in Pt;function Ed(e){let t=e.decl.icon;return t!==void 0&&Td(t)?t:`link`}function Dd(e){return e.map(e=>({system:e.system,title:e.decl.title,icon:Ed(e)})).sort((e,t)=>e.title.localeCompare(t.title))}var Od=e=>e.name===`optional`?e.generic?.T??e:e,kd=e=>{let t=e.replace(/([a-z])([A-Z])/g,`$1 $2`).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)};function Ad(e,t){let n=e.name===`obj`?e.props:void 0;if(n===void 0||t===void 0)return;let r=Object.entries(n).map(([e,n])=>{let r=t[e];if(r!==void 0)return{key:e,label:kd(e),hint:n.docs??``,many:Od(n.type).name===`list`,options:r}});return r.every(e=>e!==void 0)&&r.length>0?r:void 0}function jd(e,t){let n=typeof e==`object`&&e&&!Array.isArray(e)?e[t]:void 0;return Array.isArray(n)?n.filter(e=>typeof e==`string`):typeof n==`string`?[n]:[]}function Md(e,t){return Object.fromEntries(e.flatMap(e=>{let n=t[e.key]??[];return n.length===0?[]:[[e.key,e.many?[...n]:n[0]??``]]}))}function Nd(e,t){return`key`in t?e.key===t.key:e.instance===t.instance}function Pd(e){return e.decl.scope===`instance`||e.decl.scope===`key`}function Fd(e,t,n){let r=[...e.connections].sort((e,t)=>t.updatedAt-e.updatedAt);return[...(e.instances??[]).map(e=>({target:{instance:e.instance},id:e.instance,label:e.label,connect:e.connect})),...(e.keys??[]).map(e=>({target:{key:e.key},id:e.key,label:e.label,connect:e.connect,host:e.host}))].map(e=>{let i=r.filter(t=>Nd(t,e.target)),a=e.connect.flow?.flow??`none`;return{...e,own:i.find(e=>e.owner===t),shared:i.filter(e=>e.owner!==t),flow:a,mayConnect:a!==`none`&&(!e.connect.share||n)}}).sort((e,t)=>e.label.localeCompare(t.label))}var Id=class{#e;pages=new W;saving=new U;nav=k(()=>Dd(this.pages.value.value??[]));constructor(e){this.#e=e}async load(e=!1){await this.pages.load(()=>this.#e.connectPages.call({}),`Couldn’t load the connect pages.`,e)}page(e){return this.pages.value.value?.find(t=>t.system===e)}async connect(e,t,n){let r={system:e,...t===void 0?{}:{form:t},...n},i=await this.saving.run(()=>this.#e.connect.call(r),`Couldn’t start connecting.`);return i.ok&&`connection`in i.value&&this.#t(i.value.connection),i}async update(e){let t=await this.saving.run(()=>this.#e.updateConnection.call(e),`Couldn’t save the change.`);return t.ok&&this.#t(t.value),t}async disconnect(e){let t=await this.saving.run(async()=>(await this.#e.disconnect.call({connection:e})).ok,`Couldn’t disconnect.`);return t.ok&&this.#n(e),t}#t(e){this.#r(e.system,t=>[e,...t.filter(t=>t.id!==e.id)])}#n(e){let t=this.pages.value.value?.find(t=>t.connections.some(t=>t.id===e));t!==void 0&&this.#r(t.system,t=>t.filter(t=>t.id!==e))}#r(e,t){let n=this.pages.value.value;n!==void 0&&this.pages.set(n.map(n=>n.system===e?{...n,connections:t(n.connections)}:n))}},Ld=class{#e;#t=new Map;#n;constructor(e){this.#e=e}source(e){let t=this.#t.get(e);if(t!==void 0)return t;let n={search:async t=>this.#e.pick.call({source:e,limit:12,...t===``?{}:{text:t}}),label:async t=>t.length===0?[]:this.#e.pick.call({source:e,values:[...t]})};return this.#t.set(e,n),n}people(){if(this.#n!==void 0)return this.#n;let e=this.source(`person`),t=this.source(`group`);return this.#n={search:async n=>(await Promise.all([e.search(n),t.search(n)])).flat(),label:async n=>Rd(n,await Promise.all([e.label(n),t.label(n)]))},this.#n}};function Rd(e,t){let n=t.flat();return e.map(e=>n.find(t=>t.value===e&&t.missing!==!0)??{value:e,label:e,missing:!0})}var zd=class{#e;#t;#n;#r=0;value=L(void 0);session=I(void 0);problem=I(``);can=k(()=>{let e=this.value.value;return{mention:(e?.mentions.length??0)>0,command:(e?.commands.length??0)>0,invoke:(e?.invocations.length??0)>0,upload:e?.uploads===!0,voice:e?.voiceInput===!0}});constructor(e,t){this.#e=e,this.#t=t}start(){this.#n===void 0&&(this.#n=this.#t(e=>{this.#i(e)}))}stop(){this.#n?.(),this.#n=void 0}async load(e=this.session.value){this.session.value=e;let t=++this.#r;try{let n=await this.#e.capabilities.call(e===void 0?{}:{session:e});if(t!==this.#r)return;this.value.value=n,this.problem.value=``}catch(e){t===this.#r&&(this.problem.value=X(e,`Couldn't load what this chat can do.`))}}online(e){return this.value.value?.systems.find(t=>t.name===e)?.status===`connected`}invocation(e){return this.value.value?.invocations.find(t=>t.fn===e)}commandFor(e){return this.value.value?.commands.find(t=>t.context===e)}#i(e){if(e.type===`capabilities`)this.#e.capabilities.invalidate(),this.load();else if(e.type===`system`){let t=this.value.value;if(t===void 0)return;this.value.value={...t,systems:t.systems.map(t=>t.name===e.system?{...t,status:e.status}:t)}}}},Bd=`harness.runCards`,Vd=new Set([`hub/ctx_plan`,`hub/ctx_plan_expand`]),Hd=gn([Vn,En()]);function Ud(e){return e.status===`done`&&e.fn!==void 0&&Vd.has(e.fn)||e.status===`done`&&e.outcome?.status===`done`&&Xr(e.outcome.result)?!1:e.status===`done`||e.status===`undone`}var Wd=class{#e;constructor(e){this.#e=Ur(e,Bd,Yn(Hd),[])}choice(e){return this.#e.value.find(([t])=>t===e)?.[1]}isCollapsed(e){return this.choice(e.id)??Ud(e)}set(e,t){this.setAll([e],t)}setAll(e,t){let n=new Set(e),r=this.#e.value.filter(([e])=>!n.has(e));this.#e.value=[...r,...e.map(e=>[e,t])].slice(-500)}};async function Gd(e,t,n,r,i){let a=n.outgoing();if(a===void 0)return{ok:!1,problem:`Write the message to compare first.`};let o=n.snapshot();n.clear(`keep`);try{let o=await e.compare.call({session:t.id,parts:[...a.parts],variants:[...r],client:i});return t.messages.value=Je(t.messages.value,o.message),n.uploads.clear(),{ok:!0,value:o.turn}}catch(e){return n.restore(o),{ok:!1,problem:X(e,`Couldn’t start the compare. Your message is back in the box.`)}}}function Kd(e,t){let n=setTimeout(e,t);return()=>{clearTimeout(n)}}var qd=class{view=new W;streamed=L(new Map);choosing=new U;deciding=new U;turn;#e;#t;#n=new Map;#r;constructor(e,t,n){this.#t=e,this.#e=t,this.turn=n}async open(){this.#i(this.#e),await this.view.load(()=>this.#t.api.compareView.call({turn:this.turn}),`Couldn’t load the compare.`);for(let e of this.view.value.value?.variants??[])this.#i(e.session)}close(){for(let e of this.#n.values())e();this.#n.clear(),this.#r?.(),this.#r=void 0}async choose(e,t){let n=await this.choosing.run(()=>this.#t.api.chooseVariant.call({turn:this.turn,variant:e,adopt:t}),`Couldn’t use that answer.`);return n.ok&&this.view.set(n.value),n}async decide(e,t,n,r,i){let a=await this.deciding.run(()=>this.#t.api.approve.call({approval:e,approve:t,remember:n,...r===``?{}:{reason:r},...i===void 0?{}:{answer:i}}),`Couldn’t answer that.`);return a.ok&&this.#o(),a.ok}#i(e){this.#n.has(e)||this.#n.set(e,this.#t.events(e,t=>{this.#a(e,t)}))}#a(e,t){switch(t.type){case`compare`:t.turn===this.turn&&this.#o();return;case`token`:case`reasoning`:{if(e===this.#e)return;let n=new Map(this.streamed.value),r=n.get(t.message)??{text:``,reasoning:``};n.set(t.message,t.type===`token`?{...r,text:r.text+t.text}:{...r,reasoning:r.reasoning+t.text}),this.streamed.value=n;return}case`message`:case`approval`:case`run`:e!==this.#e&&this.#o();return;case`controls`:case`state`:case`delivery`:case`handler`:case`budget`:case`presence`:case`session`:case`cite`:return}}#o(){this.#r?.(),this.#r=(this.#t.later??Kd)(()=>{this.#r=void 0,this.view.load(()=>this.#t.api.compareView.call({turn:this.turn}),`Couldn’t load the compare.`,!0).then(()=>{this.streamed.value=new Map})},300)}},Jd=e=>`harness.draft.${e}`,Yd=K({text:q(),mentions:Yn(Gn).transform(e=>e.filter(e=>e.type===`mention`)),replyTo:Fn.optional(),replyAll:En()}),Xd={delay:120,perProvider:6,max:24},Zd=(e,t)=>e.provider===t.provider&&JSON.stringify(e.target)===JSON.stringify(t.target),Qd=(e,...t)=>{let n=e.toLowerCase();return n===``||t.some(e=>e.toLowerCase().includes(n))},$d=class{session;uploads;#e;#t;#n;#r;#i=0;#a;text=I(``);caret=I(0);mentions=L([]);replyTo=I(void 0);replyAll=I(!1);editing=I(void 0);invoking=L(void 0);caretRequest=I(void 0);pickerItems=L([]);pickerActive=I(0);pickerLoading=I(!1);#o=I(void 0);trigger=k(()=>{let e=Ge(this.text.value,this.caret.value),t=this.#e.capabilities();if(e!==void 0&&t!==void 0)return(e.kind===`mention`?t.mentions.length>0:e.kind===`command`?t.commands.length>0:t.invocations.length>0)?e:void 0});pickerOpen=k(()=>{let e=this.trigger.value;return e!==void 0&&this.#o.value!==`${e.kind}:${e.start}`});hint=k(()=>st(this.text.value,this.#e.capabilities()?.commands??[]));canSend=k(()=>!this.uploads.busy.value&&(this.text.value.trim()!==``||this.uploads.parts.value.length>0));constructor(e,t=Xd){this.session=e.session,this.uploads=e.uploads,this.#e=e,this.#t=t,this.#n=Ur(e.store,Jd(e.session),Yd.optional(),void 0);let n=this.#n.value;n!==void 0&&(this.text.value=n.text,this.caret.value=n.text.length,this.mentions.value=n.mentions,this.replyTo.value=n.replyTo,this.replyAll.value=n.replyAll),S([this.text,this.mentions,this.replyTo,this.replyAll],()=>{this.#c()}),S(()=>[this.trigger.value?.kind,this.trigger.value?.query,this.trigger.value?.start],()=>{this.#l()})}input(e,t){this.text.value=e,this.caret.value=t,this.mentions.value=He(e,this.mentions.value)}moveCaret(e){this.caret.value=e}movePicker(e){let t=this.pickerItems.value.length;t!==0&&(this.pickerActive.value=(this.pickerActive.value+e+t)%t)}dismissPicker(){let e=this.trigger.value;e!==void 0&&(this.#o.value=`${e.kind}:${e.start}`)}pick(e=this.pickerItems.value[this.pickerActive.value]){let t=this.trigger.value;if(e!==void 0&&t!==void 0){if(e.kind===`mention`){let n={type:`mention`,provider:e.provider,label:e.option.label,target:e.option.target},r=this.mentions.value.find(e=>Zd(e,n)),i=r??n;this.#s(t,`${Ve(i)} `),r===void 0&&(this.mentions.value=[...this.mentions.value,i])}else if(e.kind===`command`){if(e.command.unavailable!==void 0)return;this.#s(t,`/${e.command.name} `)}else this.#s(t,``),this.invoking.value=e.invocation}}openInvocation(e,t){this.invoking.value=e,this.#a=t}closeInvocation(){this.invoking.value=void 0,this.#a=void 0}invocationArgs(e){return this.#a===void 0?e:at(e,this.#a)}insert(e){let t=this.caret.value,n=this.text.value.slice(0,t),r=n===``||/\s$/.test(n)?e:` ${e}`,i=Ue(this.text.value,t,t,r);this.text.value=i.text,this.caret.value=i.caret,this.caretRequest.value=i.caret}replace(e){this.text.value=e,this.caret.value=e.length,this.caretRequest.value=e.length,this.mentions.value=He(e,this.mentions.value)}setReply(e){this.replyTo.value=e}outgoing(){if(!this.canSend.value)return;let e=[...ot(this.text.value,this.mentions.value,this.#e.capabilities()?.commands??[]),...this.uploads.parts.value];if(e.length!==0)return{parts:e,replyTo:this.replyTo.value,replyAll:this.replyAll.value}}startEdit(e,t,n){this.editing.value=e,this.replyTo.value=void 0,this.mentions.value=n,this.replace(t)}cancelEdit(){this.editing.value=void 0,this.clear()}snapshot(){return{editing:this.editing.value,text:this.text.value,mentions:this.mentions.value,replyTo:this.replyTo.value,replyAll:this.replyAll.value}}restore(e){this.editing.value=e.editing,this.text.value=e.text,this.caret.value=e.text.length,this.mentions.value=e.mentions,this.replyTo.value=e.replyTo,this.replyAll.value=e.replyAll}clear(e=`clear`){this.text.value=``,this.caret.value=0,this.caretRequest.value=0,this.mentions.value=[],this.replyTo.value=void 0,this.editing.value=void 0,e===`clear`&&this.uploads.clear()}dispose(){clearTimeout(this.#r),this.uploads.clear()}#s(e,t){let n=Ue(this.text.value,e.start,e.end,t);this.text.value=n.text,this.caret.value=n.caret,this.caretRequest.value=n.caret}#c(){let e=this.text.value===``&&this.replyTo.value===void 0&&!this.replyAll.value;this.#n.value=e?void 0:{text:this.text.value,mentions:[...this.mentions.value],replyAll:this.replyAll.value,...this.replyTo.value===void 0?{}:{replyTo:this.replyTo.value}}}#l(){clearTimeout(this.#r);let e=++this.#i;this.pickerActive.value=0;let t=this.trigger.value,n=this.#e.capabilities();t===void 0||n===void 0?(this.pickerItems.value=[],this.pickerLoading.value=!1):t.kind===`command`?this.pickerItems.value=n.commands.filter(e=>Qd(t.query,e.name,e.description)).slice(0,this.#t.max).map(e=>({kind:`command`,key:`c:${e.context}:${e.name}`,command:e})):t.kind===`invoke`?this.pickerItems.value=n.invocations.filter(e=>Qd(t.query,e.fn,J(e.fn),e.description)).slice(0,this.#t.max).map(e=>({kind:`invoke`,key:`i:${e.fn}`,invocation:e})):(this.pickerLoading.value=!0,this.#r=setTimeout(()=>{this.#u(t.query,n.mentions,e)},this.#t.delay))}async#u(e,t,n){let r=await Promise.all(t.map(async t=>{try{return(await this.#e.api.mentions.call({session:this.session,provider:t.provider,query:e})).slice(0,this.#t.perProvider).map((e,n)=>({kind:`mention`,key:`m:${t.provider}:${n}:${e.label}`,provider:t.provider,group:t.title,option:e}))}catch{return[]}}));n===this.#i&&(this.pickerItems.value=r.flat().slice(0,this.#t.max),this.pickerLoading.value=!1)}},ef=class{#e;run=new W;tree=new W;treeTurn=I(void 0);resource=new W;calls=L(new Map);callProblems=L(new Map);constructor(e){this.#e=e}async openRun(e){this.run.value.value?.id!==e&&this.run.reset(),await this.run.load(()=>this.#e.run.call({run:e}),`Couldn't load this run.`,this.run.value.value?.id===e)}async openResource(e){this.resource.value.value?.stat.uri!==e&&this.resource.reset(),await this.resource.load(()=>this.#e.resource.call({uri:e,want:[`text`,`links`]}),`Couldn't open this.`)}async openTree(e){this.treeTurn.value!==e&&this.tree.reset(),this.treeTurn.value=e,await this.tree.load(()=>this.#e.tree.call({turn:e}),`Couldn't load this turn's tree.`)}refreshTree(){let e=this.treeTurn.value;e!==void 0&&this.tree.load(()=>this.#e.treeRefresh.call({turn:e}),`Couldn't refresh this turn's tree.`,!0)}closeTree(){this.#e.treeRefresh.cancel(),this.treeTurn.value=void 0,this.tree.reset()}async loadCalls(e){let t=[...new Set(e)].filter(e=>!this.calls.value.has(e));await Promise.all(t.map(async e=>{try{let t=await this.#e.llmCall.call({id:e}),n=new Map(this.calls.value);n.set(e,t),this.calls.value=n}catch(t){let n=new Map(this.callProblems.value);n.set(e,X(t,`Couldn't load this LLM call.`)),this.callProblems.value=n}}))}async loadTurn(e){await this.openTree(e);let t=this.tree.value.value;if(t===void 0)return[];let n=se(t);return await this.loadCalls(n),n.flatMap(e=>{let t=this.calls.value.get(e);return t===void 0?[]:[t]})}dispose(){this.#e.treeRefresh.cancel()}},tf=(e,t)=>`${e}:${JSON.stringify(t)}`,nf=class{#e;cards=L(new Map);constructor(e){this.#e=e}card(e,t){return this.cards.value.get(tf(e,t))??{loading:!0,hover:void 0,problem:``}}async load(e,t,n){let r=tf(t,n),i=this.cards.value.get(r);if(i===void 0||!i.loading&&i.problem!==``){this.#t(r,{loading:!0,hover:void 0,problem:``});try{let{hover:i}=await this.#e.mentionHover.call({session:e,provider:t,target:n});this.#t(r,{loading:!1,hover:i,problem:``})}catch(e){this.#t(r,{loading:!1,hover:void 0,problem:X(e,`Not available right now.`)})}}}#t(e,t){let n=new Map(this.cards.value);n.set(e,t),this.cards.value=n}},rf=Symbol.for(`harness.shared`);function af(e){Reflect.set(globalThis,rf,{vue:e.vue,"@harness/sdk":e.sdk})}function of(e){return typeof e==`object`&&!!e&&`system`in e&&typeof e.system==`string`&&`renderers`in e&&typeof e.renderers==`object`&&e.renderers!==null&&`contract`in e&&typeof e.contract==`object`&&e.contract!==null}function sf(e){return typeof e==`object`&&`component`in e&&`mode`in e}function cf(e,t){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n)]))}function lf(e){let t=e.indexOf(`/`);return{system:e.slice(0,t),local:e.slice(t+1)}}function uf(t,n){if(t===void 0)return{};if(!(t instanceof tr)){let r=e(t,n);return typeof r==`object`&&r?{...r}:{}}let r=t.fields;return Object.fromEntries(Object.entries(n).flatMap(([t,n])=>{let i=r[t];return i===void 0?[]:[[t,e(i.type,n)]]}))}function df(e){let t=e.renderers;return{renderers:{fns:t.fns??{},kinds:t.kinds??{},attachments:t.attachments??{},inputs:t.inputs??{},mentions:t.mentions??{},resultFns:t.results?.fns??{},resultKinds:t.results?.kinds??{}},config:ff(e),pages:pf(e),resultItems:Object.values(t.resultItems??{}),actions:e.contract.defs.actions,fns:e.contract.defs.fns,forms:Object.fromEntries(Object.entries(e.contract.defs.fns).map(([e,t])=>[e,t.form])),attachments:cf(e.contract.defs.attachments,e=>e.data),types:cf(e.contract.defs.types,e=>e.shape),mentions:cf(e.contract.defs.mentions,e=>e.target)}}function ff(e){let t=e.contract.configComponent,n=t===void 0?void 0:e.renderers.configs?.[t.component];return t===void 0||n===void 0?void 0:{component:n,mode:t.mode,type:e.contract.defs.config}}function pf(e){let t=e.renderers.pages??{};return new Map(e.contract.pages.flatMap(e=>{let n=t[e.component];return n===void 0?[]:[[e.segment,{decl:e,component:n}]]}))}var mf=class{#e=new Map;#t;#n=new Map;#r=new Map;#i=new Map;constructor(e){this.#t=e}register(e){this.#n.set(e.system,df(e));for(let t of this.#i.keys())(t===e.system||t.startsWith(`${e.system} `))&&this.#i.delete(t);for(let[t,n]of this.#r)this.#r.set(t,n.filter(t=>t.system!==e.system));for(let[t,n]of this.#e)this.#e.set(t,n.filter(t=>t.system!==e.system));for(let[t,n]of Object.entries(e.renderers.visuals??{})){let r=$n.parse(t),i=Object.entries(n).flatMap(([t,n])=>{let i=e.contract.contributes.find(e=>e.registry===r&&e.name===t);return i?.shape===void 0?[]:[{system:e.system,name:t,label:i.label,icon:i.icon,shape:i.shape,veto:(e,t)=>n.veto?.(e,t),component:n.component}]});this.#e.set(r,[...this.#e.get(r)??[],...i])}let t=e.renderers.resources??{};for(let[n,r]of Object.entries(t)){let t=sf(r)?{component:r.component,system:e.system,mode:r.mode,label:r.label??e.system}:{component:r,system:e.system,mode:`replace`,label:e.system};this.#r.set(n,[...this.#r.get(n)??[],t])}}async load(e){let t=await import(e),n=typeof t==`object`&&t&&`default`in t?t.default:void 0;if(!of(n))throw Error(`${e} is not a system client module (its default export should be client(contract, renderers)).`);return this.register(n),n}visuals(e,t,n){return(this.#e.get(e)??[]).flatMap(r=>{let i;try{i=r.veto(t,n)}catch(t){return console.warn(`client.visual.veto-failed`,{registry:e,system:r.system,name:r.name,error:t}),[]}return i===void 0?[{system:r.system,name:r.name,label:r.label,...r.icon===void 0?{}:{icon:r.icon},shape:r.shape,component:r.component,client:this.systemClient(r.system)}]:[]})}resultItems(e){return[...this.#n.entries()].flatMap(([t,n])=>n.resultItems.filter(n=>{try{return n.offered(e)}catch(e){return console.warn(`client.result-item.offered-failed`,{system:t,label:n.label,error:e}),!1}}))}systems(){return[...this.#n.keys()]}fnRenderer(e,t){return this.#s(e,`fns`)??(t===void 0?void 0:this.#s(t,`kinds`))}attachmentRenderer(e){return this.#s(e,`attachments`)}inputRenderer(e){return this.#s(e,`inputs`)}mentionRenderer(e){return this.#s(e,`mentions`)}resourceViewers(e){return this.#r.get(e)??[]}resourceViewer(e){return this.#a(e)?.component}viewerSystem(e){return this.#a(e)?.system}#a(e){return this.resourceViewers(e).find(e=>e.mode===`replace`)}systemClient(t,n){let r=n===void 0?t:`${t} ${n}`,i=this.#i.get(r);if(i!==void 0)return i;let a=this.#n.get(t),o=this.#t,s=n===void 0?{}:{run:n},l={get online(){return o.online(t)},send:Object.fromEntries(Object.entries(a?.actions??{}).map(([n,r])=>[n,i=>this.#c(t=>e(r.returns,t),()=>o.act({system:t,action:n,input:c(r.input,i),...s}))])),run:Object.fromEntries(Object.entries(a?.fns??{}).map(([e,n])=>[e,r=>Promise.resolve().then(()=>o.invoke({fn:nr(t,e),args:c(n.args,r)}))]))};return this.#i.set(r,l),l}submit(e,t,n){let r=c(t,n);return this.#c(()=>void 0,()=>this.#t.submit({run:e,value:r}))}formSubmit(e,t){let{system:n,local:r}=lf(e),i=this.#n.get(n)?.forms[r];return i===void 0?void 0:e=>this.submit(t,i,e)}fnView(t){let{fn:n,kind:r,args:i,result:a,state:o,...s}=t,c=this.#s(n,`fns`),l={...s,submit:this.formSubmit(n,t.run)};if(c!==void 0){let{system:r,local:s}=lf(n),u=this.#n.get(r)?.fns[s];if(u===void 0)return;let d=this.#o(n,()=>({args:e(u.args,i),state:uf(u.state,o),...a===void 0?{}:{result:e(u.returns,a)}}));return d===void 0?void 0:{component:c,props:{...l,...d,system:this.systemClient(r,t.run)}}}let u=r===void 0?void 0:this.#s(r,`kinds`);if(r!==void 0&&u!==void 0)return{component:u,props:{...l,args:i,state:o,...a===void 0?{}:{result:a},system:this.systemClient(lf(r).system,t.run)}}}drawsKind(e){return this.#s(e,`resultKinds`)!==void 0}resultView(t){let{kind:n,args:r,result:i,...a}=t,o=this.#s(t.fn,`resultFns`);if(o!==void 0){let{system:n,local:s}=lf(t.fn),c=this.#n.get(n)?.fns[s];if(c===void 0)return;let l=this.#o(t.fn,()=>({args:e(c.args,r),result:e(c.returns,i)}));return l===void 0?void 0:{component:o,props:{...a,...l,system:this.systemClient(n,t.run)}}}let s=n===void 0?void 0:this.#s(n,`resultKinds`);if(n!==void 0&&s!==void 0)return{component:s,props:{...a,args:r,result:i,system:this.systemClient(lf(n).system,t.run)}}}attachmentView(t){let n=this.#s(t.attachment,`attachments`),{system:r,local:i}=lf(t.attachment),a=this.#n.get(r)?.attachments[i];if(n===void 0||a===void 0)return;let o=this.#o(t.attachment,()=>e(a,t.data));return o===void 0?void 0:{component:n,props:{data:o,title:t.title,system:this.systemClient(r)}}}mentionView(t){let n=this.#s(t.provider,`mentions`),{system:r,local:i}=lf(t.provider),a=this.#n.get(r)?.mentions[i];if(n===void 0||a===void 0)return;let o=this.#o(t.provider,()=>e(a,t.target));return o===void 0?void 0:{component:n,props:{label:t.label,target:o,hover:t.hover,system:this.systemClient(r)}}}inputView(t){let n=this.#s(t,`inputs`),{system:r,local:i}=lf(t),a=this.#n.get(r)?.types[i];if(n!==void 0&&a!==void 0)return{component:n,props:{system:this.systemClient(r)},decode:n=>n===void 0?void 0:this.#o(t,()=>e(a,n)),encode:e=>e===void 0?void 0:this.#o(t,()=>c(a,e))}}configView(t,n){let r=this.#n.get(t)?.config;if(r===void 0)return;let i=nr(t,`config`),a=r.type;return{component:r.component,mode:r.mode,props:{config:n.config===void 0?void 0:this.#o(i,()=>e(a,n.config)),type:a,validate:e=>Promise.resolve().then(()=>n.validate(c(a,e))),change:e=>{n.change(c(a,e))},system:this.systemClient(t)}}}pages(e){return[...this.#n.get(e)?.pages.values()??[]].map(e=>e.decl)}pageView(e,t,n){let r=this.#n.get(e)?.pages.get(t);return r===void 0?void 0:{component:r.component,props:{...n,page:t,system:this.systemClient(e)}}}#o(e,t){try{return t()}catch(t){console.warn(`client.view.unfit`,{name:e,error:t});return}}#s(e,t){let{system:n,local:r}=lf(e);return this.#n.get(n)?.renderers[t][r]}#c(e,t){let n=this.#t,r=Te({id:void 0,status:jn.enum.queued}),i=t().then(async t=>(r.id=t,e(await n.follow(t,e=>{r.status=e}))));return i.catch(()=>void 0),{get id(){return r.id},get status(){return r.status},result:i}}},hf=class{runtime;#e;#t=new Map;#n;status=L(new Map);version=L(0);constructor(e){this.#e=e;let t={online:t=>e.online(t),act:({system:e,action:t,input:n,run:r})=>Promise.resolve().then(()=>this.#i().act(Un.parse(e),t,n,r)),submit:async({run:e,value:t})=>{let n=await this.#i().submit(e,t);if(n===void 0)throw Error(`Couldn't submit that.`);return n},invoke:async({fn:e,args:t})=>{let n=await this.#i().invoke(e,t);if(n===void 0)throw Error(`Couldn't run that.`);return n},follow:(e,t)=>Promise.resolve().then(()=>this.#i().follow(e,t))};this.runtime=new mf(t)}async sync(e){let t=e.filter(e=>this.#t.get(e.system)!==e.hash);t.length!==0&&(this.#n??=this.#e.share?.()??Promise.resolve(),await this.#n,await Promise.all(t.map(async e=>{this.#t.set(e.system,e.hash),this.#a(e.system,`loading`);try{await(this.#e.load??((e,t)=>e.load(t).then(()=>void 0)))(this.runtime,e.url),this.#a(e.system,`ready`),this.version.value++}catch(t){console.error(`chat.renderer.load-failed`,{system:e.system,url:e.url,error:t}),this.#a(e.system,`failed`)}})))}fnView(e,t){if(this.#r(),e.args===void 0)return;let n=cr(e),r=sr(e);return this.runtime.fnView({fn:e.fn,kind:e.kind===void 0||e.kind===`native`?void 0:e.kind,run:e.id,status:or(e),args:e.args,state:t,...n===void 0?{}:{result:n},...r===void 0?{}:{error:r},...e.progress===void 0?{}:{progress:e.progress}})}resultView(e,t){this.#r();let n=cr(e);if(e.status===`done`&&e.args!==void 0&&n!==void 0)return this.runtime.resultView({fn:e.fn,kind:e.kind===void 0||e.kind===`native`?void 0:e.kind,run:e.id,args:e.args,result:n,title:t})}drawsKind(e){return this.#r(),this.runtime.drawsKind(e)}storedResultView(e,t){if(this.#r(),e.outcome?.status===`done`)return this.runtime.resultView({fn:e.fn,kind:e.kind===`native`?void 0:e.kind,run:e.id,args:e.args,result:e.outcome.result??null,title:t})}pageView(e,t,n){return this.#r(),this.runtime.pageView(e,t,n)}attachmentView(e){return this.#r(),this.runtime.attachmentView({attachment:e.attachment,data:e.data,title:e.title})}inputView(e){this.#r();let t=$n.safeParse(e);return t.success?this.runtime.inputView(t.data):void 0}mentionView(e,t){return this.#r(),this.runtime.mentionView({provider:e.provider,label:e.label,target:e.target,hover:t})}contributedVisuals(e,t,n){return this.#r(),this.runtime.visuals(e,t,n)}resultItems(e){return this.#r(),this.runtime.resultItems(e)}#r(){return this.version.value}#i(){let e=this.#e.thread();if(e===void 0)throw Error(`No chat is open.`);return e}#a(e,t){let n=new Map(this.status.value);n.set(e,t),this.status.value=n}},gf=(e,t)=>t.updatedAt-e.updatedAt;function _f(e){return e.updatedAt===e.createdAt}function vf(e){return Qn.parse(e)}var yf=class{#e;#t;#n;#r;items=L([]);search=I(``);archived=I(!1);loading=I(!1);loadingMore=I(!1);loaded=I(!1);problem=I(``);creating=I(!1);partial=I(!1);#i=I(!1);hasMore=k(()=>this.#i.value);constructor(e,t){this.#e=e,this.#t=t}start(){this.#n===void 0&&(this.#n=this.#t(e=>{this.#u(e)}))}stop(){this.#n?.(),this.#n=void 0,this.#e.searchSessions.cancel()}load(){return this.#e.searchSessions.cancel(),this.#a(e=>this.#e.sessions.call(e))}async#a(e){this.loading.value=!0,this.problem.value=``;try{let t=await e(this.#s());this.items.value=t.items,this.#r=t.cursor,this.#i.value=t.cursor!==void 0,this.partial.value=pe(t),this.loaded.value=!0,this.loading.value=!1}catch(e){if(Fr(e))return;this.problem.value=X(e,`Couldn't load your chats.`),this.loading.value=!1}}async loadMore(){let e=this.#r;if(!(e===void 0||this.loadingMore.value)){this.loadingMore.value=!0;try{let t=await this.#e.sessions.call(this.#s(e)),n=new Set(this.items.value.map(e=>e.id));this.items.value=[...this.items.value,...t.items.filter(e=>!n.has(e.id))],this.#r=t.cursor,this.#i.value=t.cursor!==void 0}catch(e){this.problem.value=X(e,`Couldn't load more chats.`)}finally{this.loadingMore.value=!1}}}setSearch(e){this.search.value=e,this.#e.sessions.cancel(),this.#a(e=>this.#e.searchSessions.call(e))}async showArchived(e){this.archived.value=e,await this.load()}listed(e){return this.items.value.filter(t=>!_f(t)||t.id===e)}async create(e={}){if(this.creating.value)return;let t=e.agent===void 0&&e.title===void 0&&!this.archived.value?this.items.value.find(_f):void 0;if(t!==void 0)return t.id;this.creating.value=!0;try{let t=await this.#e.createSession.call(e);return this.#c(vf(t)),t.id}catch(e){this.problem.value=X(e,`Couldn't start a new chat.`);return}finally{this.creating.value=!1}}async rename(e,t){return this.#o(e,{title:t},e=>({...e,title:t}))}async archive(e,t){return this.#o(e,{archived:t},e=>({...e,archived:t}))}async remove(e){let t=this.items.value;this.items.value=t.filter(t=>t.id!==e);try{return await this.#e.deleteSession.call({session:e}),!0}catch(e){return this.items.value=t,this.problem.value=X(e,`Couldn't delete that chat.`),!1}}find(e){return this.items.value.find(t=>t.id===e)}remember(e){this.#c(e)}async#o(e,t,n){let r=this.items.value,i=r.find(t=>t.id===e);i!==void 0&&this.#c(n(i));try{let n=await this.#e.updateSession.call({session:e,...t});return this.#c(vf(n)),!0}catch(e){return this.items.value=r,this.problem.value=X(e,`Couldn't change that chat.`),!1}}#s(e){let t=te(ee(`sessions`,this.search.value)),n=t.filters??[],r={field:`archived`,op:`is`,value:this.archived.value};return h({query:n.some(e=>e.field===`archived`)?t:{...t,filters:[...n,r]}},40,e)}#c(e){let t=this.items.value.filter(t=>t.id!==e.id);if(!(e.archived===this.archived.value&&this.#l(e))){this.items.value=t;return}if((ee(`sessions`,this.search.value).sort??[]).length===0){this.items.value=[e,...t].sort(gf);return}let n=this.items.value.findIndex(t=>t.id===e.id);this.items.value=n<0?[e,...t]:this.items.value.map(t=>t.id===e.id?e:t)}#l(e){let t=(ee(`sessions`,this.search.value).text??``).toLowerCase();return t===``||e.title.toLowerCase().includes(t)}#u(e){e.type===`session-deleted`?this.items.value=this.items.value.filter(t=>t.id!==e.session):e.type===`session`&&(this.items.value.some(t=>t.id===e.session.id)||this.loaded.value)&&this.#c(e.session)}},bf=class{#e;#t;report=new W;text=I(``);constructor(e,t){this.#e=e,this.#t=t}async preview(e){let t=e.trim();t!==``&&(this.text.value=t,await this.report.load(()=>this.#e.previewSelection.call({session:this.#t,text:t}),`Couldn't preview this message.`))}clear(){this.text.value=``,this.report.reset()}},xf={minLength:12,limit:6},Sf=class{#e;#t;#n;#r=``;items=L([]);loading=I(!1);constructor(e,t,n=xf){this.#e=e,this.#t=t,this.#n=n}update(e){let t=e.trim();t.length<this.#n.minLength||t.startsWith(`/`)||t.startsWith(`!`)?this.clear():t!==this.#r&&this.#i(t)}clear(){this.#e.suggest.cancel(),this.items.value=[],this.loading.value=!1,this.#r=``}async#i(e){this.#r=e,this.loading.value=!0;try{let t=await this.#e.suggest.call({session:this.#t,text:e,limit:this.#n.limit});this.items.value=[...t].sort((e,t)=>t.score-e.score),this.loading.value=!1}catch(e){if(Fr(e))return;this.#r=``,this.items.value=[],this.loading.value=!1}}},Cf={delays:[500,1e3,2e3,4e3,8e3,15e3],sleep:e=>new Promise(t=>{setTimeout(t,e)})};async function wf(e,t,n,r=()=>void 0){for(let i=0;n();i++)try{return await e(),!0}catch(e){if(r(e),!n())return!1;await t.sleep(t.delays[Math.min(i,t.delays.length-1)]??1e3)}return!1}var Tf={now:()=>typeof document>`u`||document.visibilityState===`visible`,watch:e=>typeof document>`u`?()=>void 0:(document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)})},Ef={page:50,runsOnOpen:60,typingFor:6e3,presenceEvery:3e3};function Df(e){return{reports:e,undone:e.reduce((e,t)=>e+t.undone.length,0),failed:e.reduce((e,t)=>e+t.failed.length,0),notUndoable:e.reduce((e,t)=>e+t.notUndoable.length,0),kept:e.reduce((e,t)=>e+Of(t),0)}}function Of(e){return(e.kept??[]).reduce((e,t)=>e+t.effects.length,0)}function kf(e,t){return Dn(e,t.name,t.type)}var Af=class{id;#e;#t;#n;#r;#i=new Set;#a=new Map;#o=new Map;#s=new Map;#c=new Set;#l=new Set;#u=0;#d=!1;#f=!1;#p;session=L(void 0);messages=L([]);live=L(new Map);liveCites=L(new Map);runs=L(new Map);approvals=L([]);handlers=L([]);budgets=L([]);deliveries=L(new Map);presence=L([]);controls=L(void 0);state=L(new Map);#m=L(new Map);limits=L(void 0);status=I(`loading`);problem=I(``);stale=I(!1);#h=0;loadingOlder=I(!1);sending=I(!1);pending=L(void 0);stopping=I(!1);awaiting=I(void 0);#g=I(!1);#_=I(0);hasOlder=k(()=>this.#g.value);beginning=k(()=>this.status.value===`ready`&&!this.#g.value);running=k(()=>this.session.value?.status===`running`||this.awaiting.value!==void 0);paused=k(()=>this.session.value?.status===`paused`);spent=k(()=>[...this.runs.value.values()].reduce((e,t)=>e+t.cost,0));spentSince=k(()=>Math.max(0,this.spent.value-this.#_.value));background=k(()=>[...this.runs.value.values()].filter(e=>e.background&&!Kn(e.status)));failures=k(()=>{let e=0;for(let t of[...this.messages.value].reverse())if(!(t.role===`note`||this.undone.value.has(t.turn))){if(t.role===`assistant`&&t.status===`failed`)e++;else break}return e});typing=k(()=>this.presence.value.filter(e=>e.typing&&e.user!==this.#e.me()));notify=k(()=>this.session.value?.participants.find(e=>e.actor===this.#e.me())?.notify??`all`);undone=k(()=>Ye(this.messages.value));lastTurn=k(()=>[...this.messages.value].reverse().find(e=>e.role!==`note`&&!this.undone.value.has(e.turn))?.turn);canUndo=k(()=>this.controls.value?.undoLastTurn??(this.lastTurn.value!==void 0&&!this.running.value));canContinue=k(()=>!this.running.value&&this.controls.value?.continueLastTurn===!0);constructor(e,t,n=Ef){this.id=e,this.#e=t,this.#t=n}async open(){this.#n??=this.#e.events(this.id,e=>{this.#D(e)});let e=this.#e.looking??Tf;this.#p??=e.watch(()=>{this.reportPresence({typing:this.#d&&e.now()})}),this.reportPresence({typing:this.#d}),this.status.value=this.messages.value.length>0?`ready`:`loading`,this.problem.value=``;try{let e=await this.#v();this.loadLimits(),this.loadWaiting(),this.loadControls(),this.#w(e.flatMap(e=>e.runs).slice(-this.#t.runsOnOpen))}catch(e){let t=this.session.value!==void 0;this.status.value=t?`ready`:`error`,this.problem.value=X(e,t?`Couldn't catch up with this chat.`:`Couldn't open this chat.`)}}async#v(){let[e,t]=await Promise.all([this.#e.api.session.call({session:this.id}),this.#e.api.messages.call({session:this.id,limit:this.#t.page})]);this.session.value=e,this.#e.changed(vf(e));let n=[...t.items].reverse();for(let e of this.messages.value)n=Je(n,e);return this.messages.value=n,this.#r=t.cursor,this.#g.value=t.cursor!==void 0,this.status.value=`ready`,n}close(){this.#n?.(),this.#n=void 0;for(let e of this.#o.values())clearTimeout(e);this.#o.clear(),this.#p?.(),this.#p=void 0,(this.#d||this.#f)&&this.#S(!1,!1)}async refresh(){let e=++this.#h;this.stale.value=!0,this.#n??=this.#e.events(this.id,e=>{this.#D(e)}),await wf(()=>this.#y(),this.#e.retry??Cf,()=>e===this.#h&&this.#n!==void 0,e=>{this.problem.value=X(e,`Couldn't catch up with this chat.`),this.session.value===void 0&&(this.status.value=`error`)})&&e===this.#h&&(this.stale.value=!1,this.problem.value=``,this.status.value===`error`&&(this.status.value=`ready`),this.loadLimits())}async#y(){let e=await this.#v(),t=[...this.runs.value.values()].filter(e=>!Kn(e.status)).map(e=>e.id);await Promise.all([this.#b(),this.#w(e.flatMap(e=>e.runs).slice(-this.#t.runsOnOpen),!1,!0),this.#w(t,!0,!0),...[...this.#m.value.keys()].map(e=>this.loadState(e))])}stateOf(e){let t=this.#m.value.get(e);if(t===void 0)return this.loadState(e),{};let n={};for(let e of t.fields){let r=this.state.value.get(kf(t.system,e));r!==void 0&&(n[e.name]=r)}return n}async loadState(e){if(!this.#c.has(e)){this.#c.add(e);try{let{system:t,fields:n}=await this.#e.api.state.call({run:e});this.#O(t,n);let r=new Map(this.#m.value);r.set(e,{system:t,fields:n.map(({name:e,type:t})=>({name:e,type:t}))}),this.#m.value=r}catch{}finally{this.#c.delete(e)}}}async loadOlder(){let e=this.#r;if(!(e===void 0||this.loadingOlder.value)){this.loadingOlder.value=!0;try{let t=await this.#e.api.messages.call({session:this.id,limit:this.#t.page,cursor:e});this.messages.value=it(this.messages.value,t.items),this.#r=t.cursor,this.#g.value=t.cursor!==void 0,this.#w(t.items.flatMap(e=>e.runs))}catch(e){this.problem.value=X(e,`Couldn't load older messages.`)}finally{this.loadingOlder.value=!1}}}async loadWaiting(){try{await this.#b()}catch{}}async#b(){let e=await this.#e.api.waiting.call({session:this.id});this.approvals.value=[...e.approvals].sort((e,t)=>e.createdAt-t.createdAt);let t=this.#e.me();this.handlers.value=this.#x(e.handlers.filter(e=>`user`in e.answerer&&e.answerer.user===t)),this.#w([...e.approvals.map(e=>e.run),...e.handlers.map(e=>e.run)])}async loadLimits(){try{this.limits.value=await this.#e.api.limits.call({session:this.id}),this.#_.value=this.spent.value}catch{}}async send(e){if(this.sending.value||e.parts.length===0)return!1;this.sending.value=!0,this.pending.value={parts:e.parts,at:this.#e.clock()},this.problem.value=``;try{let t=await this.#e.api.send.call({session:this.id,parts:[...e.parts],client:this.#e.client(),...e.replyTo===void 0?{}:{replyTo:e.replyTo},...e.replyAll===!0?{replyAll:!0}:{}});return this.messages.value=Je(this.messages.value,t.message),this.awaiting.value=t.turn,this.#k(),this.reportPresence({typing:!1}),!0}catch(e){return this.problem.value=X(e,`Couldn't send that. Your message is back in the box.`),!1}finally{this.sending.value=!1,this.pending.value=void 0}}async invoke(e,t,n){try{let r=await this.#e.api.invoke.call({session:this.id,fn:e,args:t,...n===void 0?{}:{on:n},client:this.#e.client()});return this.#T(this.runs.value.get(r.run)??pr(r.run,e)),this.awaiting.value=r.turn,this.#k(),this.#w([r.run],!0),r.run}catch(e){this.problem.value=X(e,`Couldn't run that.`);return}}async control(e,t){this.stopping.value=e!==`resume`;try{return this.controls.value=await this.#e.api.control.call({session:this.id,action:e,...t===void 0||t.length===0?{}:{runs:[...t]}}),e===`cancel`&&(this.awaiting.value=void 0,this.loadWaiting()),!0}catch(e){return this.stopping.value=!1,this.problem.value=X(e,`Couldn't stop the turn.`),!1}}async toBackground(e){try{let{accepted:t}=await this.#e.api.background.call({run:e}),n=this.runs.value.get(e);return t&&n!==void 0&&this.#T({...n,background:!0}),t}catch(e){return this.problem.value=X(e,`Couldn't move that to the background.`),!1}}async undoTurn(e){try{let t=await this.#e.api.undoTurn.call({turn:e});for(let e of[...t.undone.map(e=>e.run)]){let t=this.runs.value.get(e);t!==void 0&&this.#T({...t,status:`undone`})}return t}catch(e){this.problem.value=X(e,`Couldn't undo that.`);return}}async loadControls(){try{this.controls.value=await this.#e.api.controls.call({session:this.id})}catch{}}async continueTurn(e){try{return await this.#e.api.continueTurn.call({turn:e}),!0}catch(e){return this.problem.value=X(e,`Couldn't continue that.`),!1}}async continueLast(){let e=this.lastTurn.value;return e!==void 0&&this.continueTurn(e)}async undoLast(){let e=this.lastTurn.value;return e===void 0?void 0:this.undoTurn(e)}turnMessage(e){return this.messages.value.find(t=>t.turn===e&&t.role===`user`)}async retry(e){let t=this.turnMessage(e);return t===void 0||await this.undoTurn(e)===void 0?!1:(await this.#C(),this.send({parts:Ke(t.parts),replyTo:t.replyTo,replyAll:t.replyAll}))}turnsFrom(e){let t=this.messages.value.findIndex(t=>t.id===e);if(t===-1)return[];let n=[];for(let e of this.messages.value.slice(t))e.role!==`note`&&!this.undone.value.has(e.turn)&&!n.includes(e.turn)&&n.push(e.turn);return n.reverse()}async editResend(e,t){let n=this.messages.value.find(t=>t.id===e);if(n===void 0)return;let r=[];for(let t of this.turnsFrom(e)){let e=await this.undoTurn(t);if(e===void 0)return;r.push(e)}return await this.#C(),await this.send({parts:t,replyTo:n.replyTo,replyAll:n.replyAll})?Df(r):void 0}async approve(e,t,n,r,i){let a=this.approvals.value,o=a.find(t=>t.id===e)?.run;this.approvals.value=a.filter(t=>t.id!==e);try{return t&&o!==void 0&&this.#l.add(o),await this.#e.api.approve.call({approval:e,approve:t,remember:n,...r===void 0||r===``?{}:{reason:r},...i===void 0?{}:{answer:i}}),!0}catch(e){return o!==void 0&&this.#l.delete(o),this.approvals.value=a,this.problem.value=X(e,`Couldn't send your answer.`),!1}}#x(e){let t=[];for(let n of e)this.#l.has(n.run)&&ut(n)?this.answer(n.id,!0):t.push(n);return t}async approveAll(e,t,n){let r=this.approvals.value.filter(t=>e.includes(t.id));return(await Promise.all(r.map(e=>this.approve(e.id,t,Qe(e)?n:`once`)))).every(Boolean)}async raiseBudget(e,t){let{setBy:n,...r}=e.budget;try{return await this.#e.api.setBudget.call({...r,maxCost:r.maxCost+t}),this.leaveBudget(e),!0}catch(e){return this.problem.value=X(e,`Couldn't raise the budget.`),!1}}leaveBudget(e){this.budgets.value=this.budgets.value.filter(t=>t.budget.id!==e.budget.id)}async answer(e,t){let n=this.handlers.value;this.handlers.value=n.filter(t=>t.id!==e);try{return await this.#e.api.answer.call({call:e,value:t}),!0}catch(e){return this.handlers.value=n,this.problem.value=X(e,`Couldn't send your answer.`),!1}}async submit(e,t){try{return(await this.#e.api.submit.call({run:e,value:t})).delivery}catch(e){this.problem.value=X(e,`Couldn't submit that.`);return}}async act(e,t,n,r){let{delivery:i}=await this.#e.api.act.call({session:this.id,system:e,action:t,input:n,client:this.#e.client(),...r===void 0?{}:{run:r}});return i}follow(e,t){return new Promise((n,r)=>{let i={status:t,resolve:n,reject:r},a=this.deliveries.value.get(e);a!==void 0&&this.#E(a,i)||this.#s.set(e,[...this.#s.get(e)??[],i])})}async update(e){try{let t=await this.#e.api.updateSession.call({session:this.id,...e});return this.session.value=t,this.#e.changed(vf(t)),e.priority!==void 0&&this.loadLimits(),!0}catch(e){return this.problem.value=X(e,`Couldn't change this chat.`),!1}}reportPresence(e){let t=(this.#e.looking??Tf).now();e.typing===this.#d&&t===this.#f&&(!e.typing||this.#e.clock()-this.#u<this.#t.presenceEvery)||this.#S(e.typing,t)}#S(e,t){this.#d=e,this.#f=t,this.#u=this.#e.clock(),this.#e.api.presence.call({session:this.id,typing:e,focused:t}).catch(()=>void 0)}citesOf(e){return e.citations??this.liveCites.value.get(e.id)??[]}liveOf(e){return this.live.value.get(e.id)}runsOf(e){let t=e.runs.filter(e=>!this.runs.value.has(e));return t.length>0&&this.#w(t),e.runs.flatMap(e=>{let t=this.runs.value.get(e);return t===void 0?[]:[this.shown(t)]})}shown(e){let t=this.handlers.value.some(t=>t.run===e.id);return t===(e.asking===!0)?e:{...e,asking:t}}async ensureRun(e,t=!1){await this.#w([e],t)}async#C(){try{let e=await this.#e.api.messages.call({session:this.id,limit:this.#t.page});this.messages.value=[...e.items].reverse(),this.#r=e.cursor,this.#g.value=e.cursor!==void 0}catch{}}async#w(e,t=!1,n=!1){let r=[...new Set(e)].filter(e=>!this.#i.has(e)&&(t||this.runs.value.get(e)?.createdAt===void 0)),i=[];if(await Promise.all(r.map(async e=>{this.#i.add(e);try{let t=await this.#e.api.run.call({run:e});this.#T(dr(this.runs.value.get(e),t))}catch(e){i.push(e)}finally{this.#i.delete(e)}})),n&&i.length>0)throw i[0]}#T(e){let t=new Map(this.runs.value);t.set(e.id,e),this.runs.value=t}#E(e,t){return t.status(e.status),e.status===`done`?(t.resolve(e.result??null),!0):e.status===`failed`||e.status===`expired`?(t.reject(Error(e.error?.message??(e.status===`expired`?`It expired before the system came online.`:`It failed.`))),!0):!1}#D(e){switch(e.type){case`message`:{let t=this.#a.get(e.message.id);this.#a.delete(e.message.id);let n=t!==void 0&&e.message.status===`streaming`?nt(e.message,t):e.message;this.#M(n),this.messages.value=Je(this.messages.value,n),n.role===`assistant`&&n.turn===this.awaiting.value&&(this.awaiting.value=void 0),this.#w(n.runs);return}case`token`:{let t=this.messages.value.findIndex(t=>t.id===e.message),n=this.messages.value[t];if(this.#j(e.message,{kind:`text`,text:e.text}),n===void 0){this.#a.set(e.message,(this.#a.get(e.message)??``)+e.text);return}let r=[...this.messages.value];r[t]=nt(n,e.text),this.messages.value=r,n.turn===this.awaiting.value&&(this.awaiting.value=void 0);return}case`reasoning`:this.#j(e.message,{kind:`reasoning`,text:e.text});return;case`cite`:{let t=new Map(this.liveCites.value);t.set(e.message,[...(t.get(e.message)??[]).filter(t=>t.index!==e.cite.index),e.cite]),this.liveCites.value=t;return}case`run`:{let t=this.runs.value.get(e.run)??pr(e.run,e.fn);this.#T(lr(t,e.update,this.#e.clock()));let n=e.update.type===`status`&&Kn(e.update.status),r=e.update.type===`result`;(t.createdAt===void 0||n||r)&&this.#w([e.run],n||r),(n||e.update.type===`cost`)&&this.#A(e.run),e.update.type===`status`&&ur(e.update.status)&&(this.awaiting.value=void 0);return}case`controls`:this.controls.value=e.controls,this.stopping.value=!1;return;case`approval`:{let t=this.approvals.value.filter(t=>t.id!==e.approval.id);this.approvals.value=e.approval.status===`pending`?[...t,e.approval].sort((e,t)=>e.createdAt-t.createdAt):t;return}case`handler`:{let t=this.handlers.value.filter(t=>t.id!==e.call.id),n=`user`in e.call.answerer&&e.call.answerer.user===this.#e.me();this.handlers.value=e.call.status===`pending`&&n?[...t,...this.#x([e.call])]:t;return}case`delivery`:{let t=new Map(this.deliveries.value);t.set(e.delivery.id,e.delivery),this.deliveries.value=t;let n=(this.#s.get(e.delivery.id)??[]).filter(t=>!this.#E(e.delivery,t));n.length===0?this.#s.delete(e.delivery.id):this.#s.set(e.delivery.id,n);return}case`budget`:{let{type:t,...n}=e;this.budgets.value=[...this.budgets.value.filter(e=>e.budget.id!==n.budget.id),n];return}case`presence`:this.#N(e.presence);return;case`compare`:return;case`state`:this.#O(e.system,e.fields);return;case`session`:{let t=this.session.value;t!==void 0&&(this.session.value={...t,...e.session}),e.session.status===`idle`&&(this.awaiting.value=void 0,this.stopping.value=!1,this.loadLimits()),this.#e.changed(e.session);return}}}#O(e,t){let n=new Map(this.state.value);for(let r of t){let t=kf(e,r);r.value===void 0?n.delete(t):n.set(t,r.value)}this.state.value=n}#k(){this.controls.value=void 0,this.stopping.value=!1}#A(e){this.approvals.value.some(t=>t.run===e)&&(this.approvals.value=this.approvals.value.filter(t=>t.run!==e)),this.handlers.value.some(t=>t.run===e)&&(this.handlers.value=this.handlers.value.filter(t=>t.run!==e)),this.budgets.value.some(t=>t.run===e)&&(this.budgets.value=this.budgets.value.filter(t=>t.run!==e))}#j(e,t){let n=this.messages.value.find(t=>t.id===e),r=this.live.value.get(e)??(n===void 0?[]:et(n)),i=new Map(this.live.value);i.set(e,$e(r,t)),this.live.value=i}#M(e){let t=this.live.value.get(e.id);if(t===void 0||e.role!==`assistant`)return;if(e.status!==`streaming`){let n=new Map(this.live.value);n.set(e.id,qe(t,e)),this.live.value=n;return}let n=new Set(t.flatMap(e=>e.kind===`runs`?e.runs:[])),r=e.runs.filter(e=>!n.has(e));r.length>0&&this.#j(e.id,{kind:`runs`,runs:r})}#N(e){this.presence.value=[...this.presence.value.filter(t=>t.user!==e.user),e],clearTimeout(this.#o.get(e.user)),e.typing&&this.#o.set(e.user,setTimeout(()=>{this.presence.value=this.presence.value.map(t=>t.user===e.user?{...t,typing:!1}:t)},this.#t.typingFor))}},jf=class{#e;#t=L(new Map);#n=new Map;source={visuals:(e,t,n)=>(this.prepare(e),this.#e.renderers.contributedVisuals(e,t,n))};constructor(e){this.#e=e}visuals(e,t,n){let r=this.#e.renderers.contributedVisuals(e,t,n).map(e=>({name:e.name,label:e.label,icon:Zr(e.icon)?e.icon:`layers`,system:e.system,shape:e.shape,component:O(e.component),props:{system:e.client}}));return Qr(Pe,r,t,n)}prepare(e){let t=this.#n.get(e);if(t!==void 0)return t;let n=(async()=>{try{(await this.#e.api.contributions.call({registry:e})).length>0&&await this.#e.prepare()}catch(t){this.#n.delete(e),console.error(`chat.visuals.contributions-failed`,{registry:e,error:t})}})();return this.#n.set(e,n),n}choice(e){return this.#t.value.get(e)}choose(e,t){this.#t.value=new Map([...this.#t.value,[e,t]])}},Mf=class{#e;#t=[];static available(){return typeof navigator<`u`&&`mediaDevices`in navigator&&typeof navigator.mediaDevices.getUserMedia==`function`&&typeof MediaRecorder<`u`}async start(){let e=await navigator.mediaDevices.getUserMedia({audio:!0});this.#t=[];let t=new MediaRecorder(e);t.ondataavailable=e=>{e.data.size>0&&this.#t.push(e.data)},t.start(),this.#e=t}stop(){let e=this.#e;return e===void 0?Promise.reject(Error(`Not recording.`)):new Promise(t=>{e.onstop=()=>{for(let t of e.stream.getTracks())t.stop();t(new Blob(this.#t,{type:e.mimeType===``?`audio/webm`:e.mimeType}))},e.stop(),this.#e=void 0})}cancel(){let e=this.#e;e!==void 0&&(e.onstop=()=>{for(let t of e.stream.getTracks())t.stop()},e.stop(),this.#e=void 0)}},Nf=class{#e;#t;#n;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}start(){return this.#e.start()}async stop(){let e=await this.#e.stop(),t=await this.#t(e);return(await this.#n.transcribe.call({audio:t})).text}cancel(){this.#e.cancel()}};function Pf(e){let t=Reflect.get(e,`SpeechRecognition`)??Reflect.get(e,`webkitSpeechRecognition`);if(typeof t==`function`)return()=>{let e=Reflect.construct(t,[]);if(!Ff(e))throw Error(`This browser’s speech recognition is not usable.`);return e}}function Ff(e){return typeof e==`object`&&!!e&&typeof Reflect.get(e,`start`)==`function`&&typeof Reflect.get(e,`stop`)==`function`}var If=new Set([`not-allowed`,`service-not-allowed`]),Lf=class{#e;#t;#n=[];#r;#i;constructor(e){this.#e=e}start(e){let t=this.#e();return this.#n=[],this.#r=void 0,t.lang=e??``,t.continuous=!0,t.interimResults=!1,t.onresult=e=>{this.#n=Array.from(e.results).filter(e=>e.isFinal).map(e=>e[0]?.transcript.trim()??``)},t.onend=()=>{this.#i?.()},new Promise((e,n)=>{t.onerror=e=>{this.#r=e.error,If.has(e.error)&&n(new DOMException(`The microphone is blocked.`,`NotAllowedError`))},t.start(),this.#t=t,e()})}stop(){let e=this.#t;return e===void 0?Promise.reject(Error(`Not listening.`)):(this.#t=void 0,new Promise((t,n)=>{this.#i=()=>{this.#i=void 0,this.#r!==void 0&&this.#r!==`no-speech`&&this.#n.length===0?n(Error(`Speech recognition failed (${this.#r}).`)):t(this.#n.filter(e=>e!==``).join(` `))},e.stop()}))}cancel(){this.#i=void 0,this.#t?.abort(),this.#t=void 0}},Rf=class{#e;#t;#n;state=I(`idle`);startedAt=I(0);problem=I(``);constructor(e,t=Date.now){this.#e=e,this.#t=t}can(e){return this.#e[e]!==void 0}async start(e,t){if(this.state.value===`recording`||this.state.value===`transcribing`)return;this.problem.value=``;let n=this.#e[e];if(n===void 0)this.state.value=`failed`,this.problem.value=e===`browser`?`This browser can’t recognise speech. An admin can switch dictation to a model.`:`This browser can’t record audio.`;else try{await n.start(t),this.#n=n,this.startedAt.value=this.#t(),this.state.value=`recording`}catch(e){let t=e instanceof DOMException&&(e.name===`NotAllowedError`||e.name===`SecurityError`);this.state.value=t?`denied`:`failed`,this.problem.value=t?`The microphone is blocked. Allow it in your browser’s site settings to dictate.`:`Couldn't start the microphone.`}}async stop(){let e=this.#n;if(this.state.value===`recording`&&e!==void 0){this.#n=void 0,this.state.value=`transcribing`;try{let t=await e.stop();return this.state.value=`idle`,t}catch(e){this.state.value=`failed`,this.problem.value=X(e,`Couldn't transcribe that.`);return}}}cancel(){this.state.value===`recording`&&this.#n?.cancel(),this.#n=void 0,this.state.value=`idle`}dismiss(){this.problem.value=``,(this.state.value===`denied`||this.state.value===`failed`)&&(this.state.value=`idle`)}};function zf(e=Date.now){return{timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,locale:navigator.language,now:e()}}var Bf=class{listValues;pickers;access;connections;sessions;capabilities;inspector;types;collapse;renderers;mentions;visuals;approvals;#e=L(new Map);#t=new Set;current=I(void 0);#n;#r=new Map;#i=new Map;#a=new Map;#o=new Map;#s;constructor(e){this.#n=e,this.listValues=e.api.listValues,this.pickers=new Ld(e.api),this.access=new bd(e.api),this.connections=new Id(e.api),this.sessions=new yf(e.api,e.userEvents),this.capabilities=new zd(e.api,e.userEvents),this.inspector=new ef(e.api),this.types=new en(t=>e.api.types.call({names:[...t]})),this.collapse=new Wd(e.store),this.mentions=new nf(e.api),this.renderers=new hf({thread:()=>this.current.value===void 0?void 0:this.#r.get(this.current.value),online:e=>this.capabilities.online(e),...e.renderers}),this.visuals=new jf({api:e.api,renderers:this.renderers,prepare:()=>this.prepareRenderers()}),this.approvals=new Os(e.api)}start(){this.sessions.start(),this.capabilities.start()}stop(){this.sessions.stop(),this.capabilities.stop();for(let e of this.#r.values())e.close()}titleOf(e){let t=this.sessions.items.value.find(t=>t.id===e);if(t!==void 0)return t.title===``?void 0:t.title;let n=this.#e.value.get(e);if(n!==void 0)return n===``?void 0:n;let r=Bn.safeParse(e);r.success&&!this.#t.has(e)&&(this.#t.add(e),this.#n.api.session.call({session:r.data}).then(t=>{this.#e.value=new Map([...this.#e.value,[e,t.title]])},()=>void 0))}thread(e){let t=this.#r.get(e);if(t!==void 0)return this.#r.delete(e),this.#r.set(e,t),t;let n=new Af(e,{api:this.#n.api,events:this.#n.sessionEvents,clock:this.#n.clock,client:this.#n.client,me:this.#n.me,changed:e=>{this.sessions.remember(e)},...this.#n.retry===void 0?{}:{retry:this.#n.retry}},this.#n.thread??Ef);this.#r.set(e,n);for(let[t,n]of this.#r){if(this.#r.size<=5)break;t!==e&&t!==this.current.value&&(n.close(),this.#r.delete(t))}return n}async sessionOfRun(e){return(await this.#n.api.run.call({run:e})).session}composer(e){let t=this.#i.get(e);if(t!==void 0)return t;let n=new $d({session:e,store:this.#n.store,api:this.#n.api,capabilities:()=>this.capabilities.value.value,uploads:new Zs(this.#n.api,this.#n.sender,this.#n.previews)});return this.#i.set(e,n),n}suggestions(e){let t=this.#a.get(e);if(t!==void 0)return t;let n=new Sf(this.#n.api,e);return this.#a.set(e,n),n}preview(e){let t=this.#o.get(e);if(t!==void 0)return t;let n=new bf(this.#n.api,e);return this.#o.set(e,n),n}startCompare(e,t){return Gd(this.#n.api,this.thread(e),this.composer(e),t,this.#n.client())}compare(e,t){return new qd({api:this.#n.api,events:this.#n.sessionEvents},e,t)}voice(){if(this.#s===void 0){let e=this.#n.recorder(),t=this.#n.speech?.(),n={...e===void 0?{}:{model:new Nf(e,e=>this.#l(e),this.#n.api)},...t===void 0?{}:{browser:new Lf(t)}};this.#s=Object.keys(n).length===0?null:new Rf(n,this.#n.clock)}return this.#s??void 0}async open(e){let t=this.current.value;t!==void 0&&t!==e&&this.#r.get(t)?.close(),this.current.value=e;let n=this.thread(e);return await Promise.all([n.open(),this.#c(e)]),n}leave(){let e=this.current.value;e!==void 0&&this.#r.get(e)?.close(),this.current.value=void 0}async refresh(){let e=this.current.value;await Promise.all([this.sessions.loaded.value?this.sessions.load():Promise.resolve(),this.#c(e),e===void 0?Promise.resolve():this.thread(e).refresh()])}async prepareRenderers(){this.capabilities.value.value===void 0&&await this.#c(this.current.value)}async#c(e){await this.capabilities.load(e);let t=this.capabilities.value.value;t!==void 0&&this.renderers.sync(t.clients)}#l(e){let t=e.type.includes(`ogg`)?`ogg`:e.type.includes(`mp4`)?`m4a`:`webm`;return Ys(this.#n.api,this.#n.sender,e,`dictation.${t}`,()=>void 0,new AbortController().signal)}},Vf={endpoints:{setup:{method:`GET`,path:`/setup`,ws:`setup`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},createAdmin:{method:`POST`,path:`/createAdmin`,ws:`createAdmin`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`email`,`name`,`password`,`setup`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},signIn:{method:`POST`,path:`/signIn`,ws:`signIn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`email`,`password`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},refresh:{method:`POST`,path:`/refresh`,ws:`refresh`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`refresh`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},redeemSso:{method:`POST`,path:`/redeemSso`,ws:`redeemSso`,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`code`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},signOut:{method:`POST`,path:`/signOut`,ws:`signOut`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},me:{method:`GET`,path:`/me`,ws:`me`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},account:{method:`GET`,path:`/account`,ws:`account`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},capabilities:{method:`POST`,path:`/capabilities`,ws:`capabilities`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},types:{method:`POST`,path:`/types`,ws:`types`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},sessions:{method:`POST`,path:`/sessions`,ws:`sessions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},session:{method:`POST`,path:`/session`,ws:`session`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},createSession:{method:`POST`,path:`/createSession`,ws:`createSession`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`agent`,`systems`,`title`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateSession:{method:`POST`,path:`/updateSession`,ws:`updateSession`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`title`,`systems`,`agent`,`archived`,`priority`,`notify`,`model`,`mode`,`contextor`,`fnMode`,`instructions`,`citations`,`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},deleteSession:{method:`POST`,path:`/deleteSession`,ws:`deleteSession`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},limits:{method:`POST`,path:`/limits`,ws:`limits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},messages:{method:`POST`,path:`/messages`,ws:`messages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},send:{method:`POST`,path:`/send`,ws:`send`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`parts`,`replyTo`,`replyAll`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},compare:{method:`POST`,path:`/compare`,ws:`compare`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`parts`,`variants`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},compareView:{method:`POST`,path:`/compareView`,ws:`compareView`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},chooseVariant:{method:`POST`,path:`/chooseVariant`,ws:`chooseVariant`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`,`variant`,`adopt`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},invoke:{method:`POST`,path:`/invoke`,ws:`invoke`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`fn`,`args`,`on`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},control:{method:`POST`,path:`/control`,ws:`control`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`action`,`runs`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},controls:{method:`POST`,path:`/controls`,ws:`controls`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},presence:{method:`POST`,path:`/presence`,ws:`presence`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`focused`,`typing`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},background:{method:`POST`,path:`/background`,ws:`background`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},undoTurn:{method:`POST`,path:`/undoTurn`,ws:`undoTurn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},continueTurn:{method:`POST`,path:`/continueTurn`,ws:`continueTurn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},tree:{method:`POST`,path:`/tree`,ws:`tree`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},run:{method:`POST`,path:`/run`,ws:`run`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},llmCall:{method:`POST`,path:`/llmCall`,ws:`llmCall`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},waiting:{method:`POST`,path:`/waiting`,ws:`waiting`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approve:{method:`POST`,path:`/approve`,ws:`approve`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`approval`,`approve`,`remember`,`reason`,`answer`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},answer:{method:`POST`,path:`/answer`,ws:`answer`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`call`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},act:{method:`POST`,path:`/act`,ws:`act`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`system`,`action`,`input`,`run`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},submit:{method:`POST`,path:`/submit`,ws:`submit`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},state:{method:`POST`,path:`/state`,ws:`state`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},suggest:{method:`POST`,path:`/suggest`,ws:`suggest`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mentions:{method:`POST`,path:`/mentions`,ws:`mentions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`provider`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mentionHover:{method:`POST`,path:`/mentionHover`,ws:`mentionHover`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`provider`,`target`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resource:{method:`POST`,path:`/resource`,ws:`resource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`want`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},notifications:{method:`POST`,path:`/notifications`,ws:`notifications`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`unread`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},readNotifications:{method:`POST`,path:`/readNotifications`,ws:`readNotifications`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`ids`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pushKey:{method:`GET`,path:`/pushKey`,ws:`pushKey`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},subscribePush:{method:`POST`,path:`/subscribePush`,ws:`subscribePush`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`endpoint`,`keys`,`device`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},upload:{method:`POST`,path:`/upload`,ws:`upload`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`mime`,`size`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},uploaded:{method:`POST`,path:`/uploaded`,ws:`uploaded`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`upload`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},transcribe:{method:`POST`,path:`/transcribe`,ws:`transcribe`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`audio`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systems:{method:`POST`,path:`/systems`,ws:`systems`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},system:{method:`POST`,path:`/system`,ws:`system`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pairings:{method:`POST`,path:`/pairings`,ws:`pairings`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`status`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approvePairing:{method:`POST`,path:`/approvePairing`,ws:`approvePairing`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`pairing`,`approve`,`instance`,`config`,`autoPair`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},createPairingToken:{method:`POST`,path:`/createPairingToken`,ws:`createPairingToken`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`expiresIn`,`autoPair`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},configureSystem:{method:`POST`,path:`/configureSystem`,ws:`configureSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`config`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},enableSystem:{method:`POST`,path:`/enableSystem`,ws:`enableSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`functions`,`renderers`,`context`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},switchItem:{method:`POST`,path:`/switchItem`,ws:`switchItem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`section`,`name`,`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},switchPart:{method:`POST`,path:`/switchPart`,ws:`switchPart`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`section`,`name`,`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeSystem:{method:`POST`,path:`/removeSystem`,ws:`removeSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`keepStore`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},installSystem:{method:`POST`,path:`/installSystem`,ws:`installSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`source`,`config`,`autoStart`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStore:{method:`POST`,path:`/systemStore`,ws:`systemStore`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreMove:{method:`POST`,path:`/systemStoreMove`,ws:`systemStoreMove`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`to`,`runs`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreMoveState:{method:`POST`,path:`/systemStoreMoveState`,ws:`systemStoreMoveState`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreMoveAnswer:{method:`POST`,path:`/systemStoreMoveAnswer`,ws:`systemStoreMoveAnswer`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`answer`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreBackups:{method:`POST`,path:`/systemStoreBackups`,ws:`systemStoreBackups`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreBackupDelete:{method:`POST`,path:`/systemStoreBackupDelete`,ws:`systemStoreBackupDelete`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`backup`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},startSystem:{method:`POST`,path:`/startSystem`,ws:`startSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},stopSystem:{method:`POST`,path:`/stopSystem`,ws:`stopSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},restartSystem:{method:`POST`,path:`/restartSystem`,ws:`restartSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`reason`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},upgradeSystem:{method:`POST`,path:`/upgradeSystem`,ws:`upgradeSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`version`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},reimport:{method:`POST`,path:`/reimport`,ws:`reimport`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},configureProvider:{method:`POST`,path:`/configureProvider`,ws:`configureProvider`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},providers:{method:`POST`,path:`/providers`,ws:`providers`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setModelCategory:{method:`POST`,path:`/setModelCategory`,ws:`setModelCategory`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`name`,`description`,`models`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setBudget:{method:`POST`,path:`/setBudget`,ws:`setBudget`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`target`,`period`,`maxCost`,`maxTokens`,`maxCalls`,`maxTime`,`share`,`onLimit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setPriority:{method:`POST`,path:`/setPriority`,ws:`setPriority`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`target`,`default`,`max`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setPolicy:{method:`POST`,path:`/setPolicy`,ws:`setPolicy`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`description`,`subject`,`target`,`decision`,`priority`,`expiresAt`,`yields`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setActorSetting:{method:`POST`,path:`/setActorSetting`,ws:`setActorSetting`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`setting`,`actor`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},addUser:{method:`POST`,path:`/addUser`,ws:`addUser`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`email`,`name`,`role`,`groups`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},addGroup:{method:`POST`,path:`/addGroup`,ws:`addGroup`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`about`,`members`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateUser:{method:`POST`,path:`/updateUser`,ws:`updateUser`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`user`,`name`,`role`,`disabled`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setMembership:{method:`POST`,path:`/setMembership`,ws:`setMembership`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`group`,`user`,`member`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSignInPolicy:{method:`POST`,path:`/setSignInPolicy`,ws:`setSignInPolicy`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSignInLimits:{method:`POST`,path:`/setSignInLimits`,ws:`setSignInLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`account`,`address`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setProxyTrust:{method:`POST`,path:`/setProxyTrust`,ws:`setProxyTrust`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`proxies`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemFns:{method:`POST`,path:`/systemFns`,ws:`systemFns`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemParts:{method:`POST`,path:`/systemParts`,ws:`systemParts`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemLogs:{method:`POST`,path:`/systemLogs`,ws:`systemLogs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},models:{method:`POST`,path:`/models`,ws:`models`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`provider`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelCategories:{method:`POST`,path:`/modelCategories`,ws:`modelCategories`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},budgets:{method:`POST`,path:`/budgets`,ws:`budgets`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},priorityRules:{method:`POST`,path:`/priorityRules`,ws:`priorityRules`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resolveLimits:{method:`POST`,path:`/resolveLimits`,ws:`resolveLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`user`,`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},policies:{method:`POST`,path:`/policies`,ws:`policies`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},actors:{method:`POST`,path:`/actors`,ws:`actors`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`kind`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},actorSettings:{method:`POST`,path:`/actorSettings`,ws:`actorSettings`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},runs:{method:`POST`,path:`/runs`,ws:`runs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},llmCalls:{method:`POST`,path:`/llmCalls`,ws:`llmCalls`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resources:{method:`POST`,path:`/resources`,ws:`resources`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeRule:{method:`POST`,path:`/removeRule`,ws:`removeRule`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},indexStatus:{method:`POST`,path:`/indexStatus`,ws:`indexStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},browseResources:{method:`POST`,path:`/browseResources`,ws:`browseResources`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`search`,`system`,`family`,`source`,`under`,`form`,`missing`,`group`,`in`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resourceForms:{method:`POST`,path:`/resourceForms`,ws:`resourceForms`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},readResource:{method:`POST`,path:`/readResource`,ws:`readResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`form`,`section`,`offset`,`maxChars`,`rows`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},convertResource:{method:`POST`,path:`/convertResource`,ws:`convertResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`kind`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},downloadResource:{method:`POST`,path:`/downloadResource`,ws:`downloadResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`form`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},importResource:{method:`POST`,path:`/importResource`,ws:`importResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},renameResource:{method:`POST`,path:`/renameResource`,ws:`renameResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},deleteResource:{method:`POST`,path:`/deleteResource`,ws:`deleteResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextFromResource:{method:`POST`,path:`/contextFromResource`,ws:`contextFromResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`sections`,`copy`,`weight`,`tags`,`fns`,`suggestFns`,`inject`,`command`,`visible`,`suggest`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contexts:{method:`POST`,path:`/contexts`,ws:`contexts`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextItem:{method:`POST`,path:`/contextItem`,ws:`contextItem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},remember:{method:`POST`,path:`/remember`,ws:`remember`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`title`,`scope`,`about`,`question`,`when`,`weight`,`summary`,`tags`,`fns`,`suggestFns`,`inject`,`command`,`visible`,`suggest`,`parent`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateMemory:{method:`POST`,path:`/updateMemory`,ws:`updateMemory`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`title`,`about`,`question`,`when`,`weight`,`summary`,`tags`,`fns`,`suggestFns`,`inject`,`command`,`visible`,`suggest`,`parent`,`name`,`clear`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},forget:{method:`POST`,path:`/forget`,ws:`forget`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},linkContext:{method:`POST`,path:`/linkContext`,ws:`linkContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`from`,`to`,`relation`,`weight`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},unlinkContext:{method:`POST`,path:`/unlinkContext`,ws:`unlinkContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`from`,`toKey`,`relation`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextMetadata:{method:`POST`,path:`/contextMetadata`,ws:`contextMetadata`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setContextStatus:{method:`POST`,path:`/setContextStatus`,ws:`setContextStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`,`action`,`reason`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextReview:{method:`POST`,path:`/contextReview`,ws:`contextReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`kinds`,`systems`,`limit`,`cursor`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mergeContext:{method:`POST`,path:`/mergeContext`,ws:`mergeContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`keep`,`drop`,`reason`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},notDuplicate:{method:`POST`,path:`/notDuplicate`,ws:`notDuplicate`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`of`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},reextractContext:{method:`POST`,path:`/reextractContext`,ws:`reextractContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},newContextStatus:{method:`POST`,path:`/newContextStatus`,ws:`newContextStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setNewContextStatus:{method:`POST`,path:`/setNewContextStatus`,ws:`setNewContextStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextPlans:{method:`POST`,path:`/contextPlans`,ws:`contextPlans`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextPlan:{method:`POST`,path:`/contextPlan`,ws:`contextPlan`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`,`format`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},answerPlan:{method:`POST`,path:`/answerPlan`,ws:`answerPlan`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`,`answers`,`reasons`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelLimits:{method:`POST`,path:`/modelLimits`,ws:`modelLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`model`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewSelection:{method:`POST`,path:`/previewSelection`,ws:`previewSelection`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setModelLimits:{method:`POST`,path:`/setModelLimits`,ws:`setModelLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`model`,`limits`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewPrompt:{method:`POST`,path:`/previewPrompt`,ws:`previewPrompt`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`,`model`,`count`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelRoles:{method:`POST`,path:`/modelRoles`,ws:`modelRoles`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setModelRole:{method:`POST`,path:`/setModelRole`,ws:`setModelRole`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},clearModelRole:{method:`POST`,path:`/clearModelRole`,ws:`clearModelRole`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`role`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelCalls:{method:`POST`,path:`/modelCalls`,ws:`modelCalls`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`run`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelCall:{method:`POST`,path:`/modelCall`,ws:`modelCall`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnMetrics:{method:`POST`,path:`/fnMetrics`,ws:`fnMetrics`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`system`,`days`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnMetricsDays:{method:`POST`,path:`/fnMetricsDays`,ws:`fnMetricsDays`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`days`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mcps:{method:`POST`,path:`/mcps`,ws:`mcps`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mcp:{method:`POST`,path:`/mcp`,ws:`mcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},createMcp:{method:`POST`,path:`/createMcp`,ws:`createMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`slug`,`name`,`instructions`,`rules`,`toolMode`,`user`,`grantees`,`origins`,`enabled`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateMcp:{method:`POST`,path:`/updateMcp`,ws:`updateMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`slug`,`name`,`instructions`,`rules`,`toolMode`,`user`,`grantees`,`origins`,`enabled`,`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},rotateMcpSecret:{method:`POST`,path:`/rotateMcpSecret`,ws:`rotateMcpSecret`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},deleteMcp:{method:`POST`,path:`/deleteMcp`,ws:`deleteMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewMcp:{method:`POST`,path:`/previewMcp`,ws:`previewMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`rules`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mcpSessions:{method:`POST`,path:`/mcpSessions`,ws:`mcpSessions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pairing:{method:`POST`,path:`/pairing`,ws:`pairing`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`pairing`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},instances:{method:`POST`,path:`/instances`,ws:`instances`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},installPackage:{method:`POST`,path:`/installPackage`,ws:`installPackage`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`zip`,`instance`,`config`,`data`,`autoStart`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeInstance:{method:`POST`,path:`/removeInstance`,ws:`removeInstance`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`keepStore`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},addInstance:{method:`POST`,path:`/addInstance`,ws:`addInstance`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`description`,`config`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exportSystemData:{method:`POST`,path:`/exportSystemData`,ws:`exportSystemData`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`withSecrets`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},query:{method:`POST`,path:`/query`,ws:`query`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`list`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},listValues:{method:`POST`,path:`/listValues`,ws:`listValues`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`list`,`field`,`prefix`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fns:{method:`POST`,path:`/fns`,ws:`fns`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`filters`,`sort`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},suggestDecision:{method:`POST`,path:`/suggestDecision`,ws:`suggestDecision`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSuggestDecision:{method:`POST`,path:`/setSuggestDecision`,ws:`setSuggestDecision`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},searchDecisions:{method:`POST`,path:`/searchDecisions`,ws:`searchDecisions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSearchDecision:{method:`POST`,path:`/setSearchDecision`,ws:`setSearchDecision`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`item`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewSuggestions:{method:`POST`,path:`/previewSuggestions`,ws:`previewSuggestions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},autoPairs:{method:`POST`,path:`/autoPairs`,ws:`autoPairs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},revokeAutoPair:{method:`POST`,path:`/revokeAutoPair`,ws:`revokeAutoPair`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},imageEmbedding:{method:`POST`,path:`/imageEmbedding`,ws:`imageEmbedding`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setImageEmbedding:{method:`POST`,path:`/setImageEmbedding`,ws:`setImageEmbedding`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},outsideImages:{method:`POST`,path:`/outsideImages`,ws:`outsideImages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setOutsideImages:{method:`POST`,path:`/setOutsideImages`,ws:`setOutsideImages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},https:{method:`POST`,path:`/https`,ws:`https`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setHttps:{method:`POST`,path:`/setHttps`,ws:`setHttps`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},accessInfo:{method:`POST`,path:`/accessInfo`,ws:`accessInfo`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},access:{method:`POST`,path:`/access`,ws:`access`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`targets`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setAccess:{method:`POST`,path:`/setAccess`,ws:`setAccess`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`target`,`sharing`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},connectPages:{method:`POST`,path:`/connectPages`,ws:`connectPages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},connect:{method:`POST`,path:`/connect`,ws:`connect`,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`key`,`form`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateConnection:{method:`POST`,path:`/updateConnection`,ws:`updateConnection`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`connection`,`settings`,`fns`,`share`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},disconnect:{method:`POST`,path:`/disconnect`,ws:`disconnect`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`connection`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pick:{method:`POST`,path:`/pick`,ws:`pick`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`source`,`text`,`values`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approvals:{method:`POST`,path:`/approvals`,ws:`approvals`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`runs`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contributions:{method:`POST`,path:`/contributions`,ws:`contributions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`registry`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemPages:{method:`POST`,path:`/systemPages`,ws:`systemPages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemInstances:{method:`POST`,path:`/systemInstances`,ws:`systemInstances`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},searchFns:{method:`POST`,path:`/searchFns`,ws:`searchFns`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`match`,`items`,`kinds`,`systems`,`instance`,`visibility`,`types`,`modes`,`effects`,`names`,`filters`,`off`,`statuses`,`returnNotApplicable`,`semanticOver`,`scopes`,`available`,`niches`,`order`,`offset`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnExamples:{method:`POST`,path:`/fnExamples`,ws:`fnExamples`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`query`,`offset`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnFacts:{method:`POST`,path:`/fnFacts`,ws:`fnFacts`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`args`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnsOfModelNames:{method:`POST`,path:`/fnsOfModelNames`,ws:`fnsOfModelNames`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},clientLogs:{method:`POST`,path:`/clientLogs`,ws:`clientLogs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`entries`,`page`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},autoClassifier:{method:`POST`,path:`/autoClassifier`,ws:`autoClassifier`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setAutoClassifier:{method:`POST`,path:`/setAutoClassifier`,ws:`setAutoClassifier`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`model`,`messages`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exploreRoots:{method:`POST`,path:`/exploreRoots`,ws:`exploreRoots`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exploreList:{method:`POST`,path:`/exploreList`,ws:`exploreList`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`cursor`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exploreRead:{method:`POST`,path:`/exploreRead`,ws:`exploreRead`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`want`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemReview:{method:`POST`,path:`/systemReview`,ws:`systemReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},goLive:{method:`POST`,path:`/goLive`,ws:`goLive`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`,`off`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approveReview:{method:`POST`,path:`/approveReview`,ws:`approveReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`,`off`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},rejectReview:{method:`POST`,path:`/rejectReview`,ws:`rejectReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},decideReview:{method:`POST`,path:`/decideReview`,ws:`decideReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`,`approve`,`decline`,`off`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},testCall:{method:`POST`,path:`/testCall`,ws:`testCall`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`args`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},refusals:{method:`POST`,path:`/refusals`,ws:`refusals`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`rule`,`cursor`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},graph:{method:`POST`,path:`/graph`,ws:`graph`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`filters`,`systems`,`external`,`focus`,`collapse`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},injections:{method:`POST`,path:`/injections`,ws:`injections`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`agent`,`context`,`mode`,`fnMode`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setInjection:{method:`POST`,path:`/setInjection`,ws:`setInjection`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`agent`,`context`,`on`,`order`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},identity:{method:`GET`,path:`/identity`,ws:`identity`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},setHubName:{method:`POST`,path:`/setHubName`,ws:`setHubName`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},itemVersions:{method:`POST`,path:`/itemVersions`,ws:`itemVersions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`system`,`section`,`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},dataSets:{method:`POST`,path:`/dataSets`,ws:`dataSets`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},records:{method:`POST`,path:`/records`,ws:`records`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`query`,`search`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},record:{method:`POST`,path:`/record`,ws:`record`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},recordTable:{method:`POST`,path:`/recordTable`,ws:`recordTable`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`query`,`search`,`run`,`offset`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},saveRecord:{method:`POST`,path:`/saveRecord`,ws:`saveRecord`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`value`,`expect`,`run`,`owner`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateRecord:{method:`POST`,path:`/updateRecord`,ws:`updateRecord`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`set`,`expect`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeRecord:{method:`POST`,path:`/removeRecord`,ws:`removeRecord`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},recordVersions:{method:`POST`,path:`/recordVersions`,ws:`recordVersions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`type`,`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},rowActions:{method:`POST`,path:`/rowActions`,ws:`rowActions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`types`,`narrow`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},readFn:{method:`POST`,path:`/readFn`,ws:`readFn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`args`,`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},export:{method:`GET`,path:`/export`,ws:null,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:`text/csv`,items:!1,p:[],q:[`fn`,`args`,`offset`,`limit`,`format`],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},people:{method:`POST`,path:`/people`,ws:`people`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`filters`,`sort`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},groups:{method:`POST`,path:`/groups`,ws:`groups`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`filters`,`sort`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},groupMembers:{method:`POST`,path:`/groupMembers`,ws:`groupMembers`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`group`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},signInSettings:{method:`POST`,path:`/signInSettings`,ws:`signInSettings`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},checkSsoProvider:{method:`POST`,path:`/checkSsoProvider`,ws:`checkSsoProvider`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`provider`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},testSsoSignIn:{method:`POST`,path:`/testSsoSignIn`,ws:`testSsoSignIn`,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`provider`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},ssoTestResult:{method:`POST`,path:`/ssoTestResult`,ws:`ssoTestResult`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`test`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`}},events:{systemLog:{ws:`on.systemLog`,hasParams:!0},session:{ws:`on.session`,hasParams:!0},user:{ws:`on.user`,hasParams:!0}}},Hf={whileDisconnected:`queue`,heartbeat:{interval:3e4,timeout:1e4},backoff:{initial:500,max:15e3}};async function Uf(e,t){let n=await e();return n&&t.reconnect(),n}function Wf(e){let t=wn(()=>{let t=e.token();return`${e.origin.replace(/^http/,`ws`)}/ws${t===``?``:`?access_token=${encodeURIComponent(t)}`}`},Hf),n=e.unauthorized;return{hub:yn({baseUrl:`${e.origin}/api`,manifest:Vf,headers:()=>{let t=e.token();return t===``?{}:{authorization:`Bearer ${t}`}},ws:t,prefer:`ws`,...n===void 0?{}:{unauthorized:()=>Uf(n,t)}}),socket:t}}function Gf(e){return e instanceof hn?e.status:0}function Kf(e){let t=Vf.endpoints[e];return{method:t.method,endpoint:t.path}}function qf(e,t,n=Date.now){let r=(r,i)=>{let a=Kf(r),o=new WeakMap,s=(e,t)=>{let n=typeof e==`object`&&e?o.get(e):void 0;n!==void 0&&(n.status=t)};return e.caller(r,{...i,onStart:e=>{typeof e==`object`&&e&&o.set(e,{at:n(),status:0}),i?.onStart?.(e)},onSuccess:(e,t)=>{s(t,200),i?.onSuccess?.(e,t)},onError:(e,t)=>{s(t,Gf(e)),i?.onError?.(e,t)},onSettled:e=>{let r=typeof e==`object`&&e?e:void 0,s=r===void 0?void 0:o.get(r);r!==void 0&&s!==void 0&&(o.delete(r),t({at:s.at,...a,status:s.status,duration:Math.max(0,Math.round(n()-s.at))})),i?.onSettled?.(e)}})};return{...e,caller:r}}var Jf={wait:5e3,maxWait:3e4,max:500},Yf=4e3,Xf=3e3,Zf=1e3,Qf=`[hidden]`,$f=/token|password|passwd|secret|authorization|cookie|api[-_]?key|private[-_]?key|credential/i,ep=[/(bearer\s+)[\w.~+/=-]+/gi,/\beyJ[\w-]+\.[\w-]+\.[\w-]+/g],tp={log:`info`,info:`info`,warn:`warn`,error:`error`};function np(e){return ep.reduce((e,t)=>e.replace(t,(e,t)=>typeof t==`string`?`${t}${Qf}`:Qf),e)}function rp(e){if(typeof e==`string`)return np(e).slice(0,Zf);if(e instanceof Error)return np(`${e.name}: ${e.message}`).slice(0,Zf);if(e===void 0||typeof e==`function`||typeof e==`symbol`)return String(e);try{return np(JSON.stringify(e,(e,t)=>e!==``&&$f.test(e)?Qf:t)).slice(0,Zf)}catch{return Object.prototype.toString.call(e)}}function ip(e){return e.map(rp).join(` `).slice(0,Yf)}function ap(e){return e.caller(`clientLogs`,{debounce:{wait:Jf.wait,maxWait:Jf.maxWait,accumulate:e=>{let t=e.at(-1);return{entries:e.flatMap(e=>e.entries).slice(-Jf.max),...t?.page===void 0?{}:{page:t.page}}}},retry:{attempts:3}})}function op(e){return e instanceof Error?{message:`${e.name}: ${e.message}`.slice(0,Yf),fields:e.stack===void 0?{}:{stack:e.stack.slice(0,Xf)}}:{message:String(e).slice(0,Yf),fields:{}}}var sp=class{#e;#t;constructor(e){this.#e=e,this.#t=e.clock??Date.now}log(e,t,n={}){let r=Object.fromEntries(Object.entries(n).map(([e,t])=>[e,$f.test(e)?Qf:np(t)]));this.#r({type:`log`,at:this.#t(),level:e,message:np(t).slice(0,Yf),...Object.keys(r).length===0?{}:{fields:r}})}error(e,t){let{message:n,fields:r}=op(e);this.log(`error`,n,{source:t,...r})}traffic(e){this.#r({type:`traffic`,at:e.at,method:e.method.slice(0,16),endpoint:e.endpoint.slice(0,300),status:e.status,duration:e.duration})}watch(e,t=console){let n=e=>{this.error(e.error??e.message,`window`)},r=e=>{this.error(e.reason,`promise`)};e.addEventListener(`error`,n),e.addEventListener(`unhandledrejection`,r);let i=this.#n(t);return()=>{e.removeEventListener(`error`,n),e.removeEventListener(`unhandledrejection`,r),i()}}#n(e){let t=Object.keys(tp).filter(e=>e in tp),n=t.map(t=>[t,Object.getOwnPropertyDescriptor(e,t)]),r=!1;for(let n of t){let t=e[n].bind(e);e[n]=(...e)=>{if(t(...e),!r){r=!0;try{this.log(tp[n],ip(e),{source:`console`})}finally{r=!1}}}}return()=>{for(let[t,r]of n)r===void 0?Reflect.deleteProperty(e,t):Object.defineProperty(e,t,r)}}#r(e){if(!this.#e.signedIn())return;let t={entries:[e],page:this.#e.page().slice(0,300)};this.#e.send.call(t).catch(()=>void 0)}},cp=An.endpoints.createAdmin.cfg.body,lp=An.endpoints.signIn.cfg.body,up=`harness.sign-in`,dp=K({remember:En(),email:q().optional()}),fp=class{#e;#t;#n;remembered;setup=L();loading=I(!0);busy=I(!1);problem=I(``);fields=L({});constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.remembered=(n===void 0?void 0:Br(n,`harness.sign-in`,dp))??{remember:!0}}get needsAdmin(){return this.setup.value?.needsAdmin===!0}get providers(){return this.setup.value?.sso??[]}async finishSso(e){this.busy.value=!0,this.problem.value=``;try{return this.#t.keep(await this.#e.redeemSso.call({code:e},Al),this.remembered.remember),!0}catch(e){return this.problem.value=X(e,`That sign-in didn’t finish. Sign in again.`),!1}finally{this.busy.value=!1}}async load(){this.loading.value=!0,this.problem.value=``;try{this.setup.value=await this.#e.setup.call(Al)}catch(e){this.problem.value=X(e)}finally{this.loading.value=!1}}async submit(e){let t=this.needsAdmin?Z(cp,e):Z(lp,e);if(this.fields.value=t.ok?{}:t.problems,this.problem.value=``,!t.ok)return!1;this.busy.value=!0;try{let t=this.needsAdmin?await this.#e.createAdmin.call({email:e.email,name:e.name,password:e.password,setup:e.setup??``},Al):await this.#e.signIn.call({email:e.email,password:e.password},Al),n=e.remember??!0;return this.#t.keep(t,n),this.#n?.setItem(up,JSON.stringify(n?{remember:n,email:e.email}:{remember:n})),!0}catch(e){return this.problem.value=X(e,`Couldn't sign in. Try again.`),!1}finally{this.busy.value=!1}}},pp=6e4,mp=`harness.refresh`,hp=class{#e=new Map;run(e,t){let n=(this.#e.get(e)??Promise.resolve()).catch(()=>void 0).then(t);return this.#e.set(e,n),n}},gp=class{#e;#t=new hp;constructor(e){this.#e=e?.locks}run(e,t){return this.#e===void 0?this.#t.run(e,t):this.#e.request(e,t).then(e=>e)}},_p=class{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n=Date.now,r=new hp){this.#e=e,this.#t=t,this.#n=n,this.#r=r}start(){this.#a??=S(this.#t.expiresAt,e=>{this.#c(e)},{immediate:!0})}stop(){this.#a?.(),this.#a=void 0,clearTimeout(this.#i)}refresh(e=`due`){let t=this.#t.refreshToken.value;return this.#r.run(mp,async()=>{this.#t.reload();let n=this.#t.refreshToken.value;if(n===``)return!1;if(n!==t||e===`due`&&!this.#s())return!0;try{return this.#t.keep(await this.#e.refresh.call({refresh:n},Al)),!0}catch{return this.#t.forget(),!1}})}recover(){return this.#o??=this.refresh(`refused`).finally(()=>{this.#o=void 0}),this.#o}async signOut(){try{await this.#e.signOut.call()}catch{}this.#t.forget()}#s(){let e=this.#t.expiresAt.value;return e!==void 0&&e-6e4<=this.#n()}#c(e){clearTimeout(this.#i),e!==void 0&&(this.#i=setTimeout(()=>{this.refresh()},Math.max(0,e-pp-this.#n())))}},vp=class{#e;view=new W;constructor(e){this.#e=e}load(){return this.view.load(()=>this.#e.account.call(),`Couldn’t load your account.`,this.view.value.value!==void 0)}},yp=1500,bp=2500,xp=class{state=I(`online`);#e=new Set;#t;#n;#r=!1;constructor(e){this.#t=e.subscribe(e=>{this.#i(e)}),e.status===`offline`&&this.#i(`offline`)}onReconnect(e){return this.#e.add(e),()=>{this.#e.delete(e)}}dispose(){this.#t(),clearTimeout(this.#n)}#i(e){if(e===`offline`){if(this.#r)return;this.#r=!0,clearTimeout(this.#n),this.#n=setTimeout(()=>{this.state.value=`offline`},yp)}else if(this.#r){this.#r=!1,clearTimeout(this.#n);for(let e of this.#e)e();this.state.value===`offline`&&(this.state.value=`back`,this.#n=setTimeout(()=>{this.state.value=`online`},bp))}}},Sp=class{#e;#t;#n;state=I(`off`);busy=I(!1);problem=I(``);constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}async check(){this.#t.supported()?this.#t.permission()===`denied`?this.state.value=`blocked`:this.state.value=await this.#t.current().catch(()=>void 0)===void 0?`off`:`on`:this.state.value=`unsupported`}async enable(){if(this.state.value===`unsupported`)return!1;this.busy.value=!0,this.problem.value=``;try{let{publicKey:e}=await this.#e.pushKey.call(),t=await this.#t.subscribe(e);return t===void 0?(this.state.value=this.#t.permission()===`denied`?`blocked`:`off`,!1):(await this.#e.subscribePush.call({endpoint:t.endpoint,keys:{p256dh:t.keys.p256dh,auth:t.keys.auth},device:this.#n()}),this.state.value=`on`,!0)}catch(e){return this.problem.value=X(e,`Couldn't turn on notifications.`),!1}finally{this.busy.value=!1}}async disable(){this.busy.value=!0;try{await this.#t.unsubscribe(),this.state.value=`off`}finally{this.busy.value=!1}}},Cp={built:`/sw.js`,source:`/sw/sw.ts`};function wp(e){let t=`${e}${`=`.repeat((4-e.length%4)%4)}`.replace(/-/g,`+`).replace(/_/g,`/`),n=atob(t),r=new Uint8Array(new ArrayBuffer(n.length));for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}var Tp=K({endpoint:q(),keys:K({p256dh:q(),auth:q()})}),Ep=class{#e;#t;constructor(e,t){this.#t=t,this.#e=e}supported(){return this.#e.isSecureContext&&`serviceWorker`in this.#e.navigator&&`PushManager`in this.#e&&`Notification`in this.#e}permission(){return Notification.permission}async current(){let e=await(await this.#e.navigator.serviceWorker.getRegistration(this.#t))?.pushManager.getSubscription();return e==null?void 0:Tp.parse(e.toJSON())}async subscribe(e){if(await Notification.requestPermission()!==`granted`)return;let t=await this.#e.navigator.serviceWorker.register(this.#t,{type:`module`,scope:`/`});await this.#e.navigator.serviceWorker.ready;let n=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:wp(e)});return Tp.parse(n.toJSON())}async unsubscribe(){await(await(await this.#e.navigator.serviceWorker.getRegistration(this.#t))?.pushManager.getSubscription())?.unsubscribe()}},Dp=class{#e;view=L(void 0);loading=new U;saving=new U;authority=k(()=>this.view.value?.on===!0&&this.view.value.source===`own`?ln.der:void 0);constructor(e){this.#e=e}async load(){let e=await this.loading.run(()=>this.#e.https.call({}),`Couldn't read the hub's secure connection.`);e.ok&&(this.view.value=e.value)}async set(e){let t=await this.saving.run(()=>this.#e.setHttps.call({on:e}),`Couldn't save the setting.`);return t.ok&&(this.view.value=t.value),t}};function Op(e,t){let n=new URL(t,e);return n.protocol=`http:`,n.toString()}var kp=class{#e;#t;#n=[];state=I(`browser`);sheetOpen=I(!1);secure;constructor(e){this.#e=e,this.secure=e.secure(),this.#r(),this.#n.push(e.onPrompt(e=>{this.#t=e,this.#r()}),e.onChange(()=>{this.#t=void 0,this.#r()}))}get offered(){return this.state.value===`ready`||this.state.value===`ios`}#r(){let e=this.#e;this.state.value=e.standalone()?`installed`:e.secure()?this.#t===void 0?e.ios()?`ios`:`browser`:`ready`:`insecure`}async install(){if(this.state.value===`ios`)return this.sheetOpen.value=!0,`sheet`;let e=this.#t;if(this.state.value!==`ready`||e===void 0)return`unavailable`;this.#t=void 0,await e.prompt();let{outcome:t}=await e.userChoice;return this.#r(),t}stop(){for(let e of this.#n.splice(0))e()}},Ap=[`standalone`,`window-controls-overlay`,`minimal-ui`,`fullscreen`],jp=class{#e;constructor(e){this.#e=e}standalone(){return this.#e.navigator.standalone===!0||Ap.some(e=>this.#e.matchMedia(`(display-mode: ${e})`).matches)}secure(){return this.#e.isSecureContext}ios(){let e=this.#e.navigator;return/iPhone|iPad|iPod/.test(e.userAgent)||/Macintosh/.test(e.userAgent)&&e.maxTouchPoints>1}onPrompt(e){let t=t=>{Mp(t)&&(t.preventDefault(),e(t))};return this.#e.addEventListener(`beforeinstallprompt`,t),()=>{this.#e.removeEventListener(`beforeinstallprompt`,t)}}onChange(e){let t=Ap.map(e=>this.#e.matchMedia(`(display-mode: ${e})`));for(let n of t)n.addEventListener(`change`,e);return this.#e.addEventListener(`appinstalled`,e),()=>{for(let n of t)n.removeEventListener(`change`,e);this.#e.removeEventListener(`appinstalled`,e)}}};function Mp(e){return`prompt`in e&&typeof e.prompt==`function`&&`userChoice`in e}async function Np(e,t){if(e.isSecureContext&&`serviceWorker`in e.navigator)try{await e.navigator.serviceWorker.register(t,{type:`module`,scope:`/`})}catch{}}var Pp=`harness.session`,Fp=ir.pick({access:!0,refresh:!0,user:!0}).extend({expiresAt:On,remember:En().optional()}),Ip=`harness.alive`;function Lp(e){return{alive:()=>e.cookie.split(`;`).some(e=>e.trim()===`${Ip}=1`),set:()=>{e.cookie=`${Ip}=1; Path=/; SameSite=Lax`},clear:()=>{e.cookie=`${Ip}=; Path=/; Max-Age=0; SameSite=Lax`}}}var Rp=class{#e;#t;#n;#r;constructor(e,t=Date.now,n,r){this.#e=e,this.#t=t,this.#r=r,this.#n=Ur(e,Pp,Fp.optional(),void 0),this.#n.value?.remember===!1&&r!==void 0&&!r.alive()&&(this.#n.value=void 0),n?.(e=>{(e===null||e===`harness.session`)&&this.reload()})}accessToken=k(()=>this.#n.value?.access??``);refreshToken=k(()=>this.#n.value?.refresh??``);user=k(()=>this.#n.value?.user);signedIn=k(()=>this.#n.value!==void 0);expiresAt=k(()=>this.#n.value?.expiresAt);remembered=k(()=>this.#n.value?.remember!==!1);keep(e,t){let n=t??this.#n.value?.remember??!0;t===!1&&this.#r?.set(),this.#n.value={access:e.access,refresh:e.refresh,user:e.user,expiresAt:this.#t()+e.expiresIn,...n?{}:{remember:!1}}}forget(){this.#n.value=void 0}reload(){let e=Br(this.#e,Pp,Fp);(e?.access!==this.#n.value?.access||e?.refresh!==this.#n.value?.refresh)&&(this.#n.value=e)}},zp=class{#e;query=L({});facets=L([]);list;groups=L(new Map);folders=L(new Map);selected=L(new Set);uploads=L([]);acting=new U;importing=new U;selectedCount=k(()=>this.selected.value.size);#t=0;#n;#r;#i=new Map;#a=new Map;#o=0;constructor(e){this.#e=e,this.list=new f({fetch:async(t,n,r)=>{let i=await e.api.browse.call(h(t,r,n));return this.facets.value=n===void 0?i.facets:d(this.facets.value,i.facets),i},key:e=>e.uri,failure:`Couldn't load resources.`,limit:60},{})}start(){return this.#n??=this.#e.events(()=>{clearTimeout(this.#r),this.#r=setTimeout(()=>{this.refresh()},500)}),()=>{this.stop()}}stop(){this.#n?.(),this.#n=void 0,clearTimeout(this.#r)}async show(e){this.query.value=e,this.#o++,this.selected.value=new Set,await this.list.load(_(e)),e.view===`groups`&&e.in===void 0&&await this.#s(e)}async refresh(){let e=this.query.value;await Promise.all([this.list.refresh(),...e.view===`groups`&&e.in===void 0?[this.#s(e,!0)]:[]])}async#s(e,t=!1){let n=this.#o,r=new Map;await Promise.all(this.facets.value.map(async n=>{let i=(t?this.groups.value.get(n.value):void 0)??new W;r.set(n.value,i),await i.load(()=>this.#e.api.browseGroup.call(me(e,n)),`Couldn't load this group.`,t)})),n===this.#o&&(this.groups.value=r)}async openFolder(e,t=!1){let n=this.folders.value.get(e);if(n!==void 0&&!t)return;let r=n??new W;n===void 0&&(this.folders.value=new Map([...this.folders.value,[e,r]])),await r.load(async()=>(await this.#e.api.browseGroup.call(p(this.query.value,e))).facets,`Couldn't load the folders.`)}peek(e){let t=`${e.uri}@${e.stat.version}`,n=this.#a.get(t);if(n!==void 0)return n;let r=new W;return this.#a.set(t,r),r.load(()=>this.#c(e),``,!0),r}async#c(e){let t=$r(e.stat);if(e.forms?.includes(`thumbnail`)===!0)return{kind:`image`,url:(await this.#e.api.download.call({uri:e.uri,form:`thumbnail`})).url};if(t===`image`)return{kind:`image`,url:(await this.#e.api.download.call({uri:e.uri})).url};if(t===`code`||t===`document`||t===`data`||t===`table`||t===`web`){let t=await this.#e.api.read.call({uri:e.uri,maxChars:400});return t.text.trim()===``?{kind:`none`}:{kind:`text`,text:t.text}}return{kind:`none`}}toggle(e){let t=new Set(this.selected.value);t.has(e)?t.delete(e):t.add(e),this.selected.value=t}toggleAll(){let e=this.list.items.value.map(e=>e.uri);this.selected.value=e.every(e=>this.selected.value.has(e))?new Set:new Set(e)}clearSelection(){this.selected.value=new Set}async importUrl(e){let t=await this.importing.run(()=>this.#e.api.importResource.call({url:e}),`Couldn't import that address.`);return t.ok&&this.list.refresh(),t}async refetch(e){let t=e.flatMap(e=>{let t=mt(e);return t===void 0?[]:[{url:t,name:e.stat.name}]}),n=await this.acting.run(()=>Promise.all(t.map(e=>this.#e.api.importResource.call(e))),`Couldn't fetch that again.`);if(n.ok)return this.list.refresh(),n.value.length}async upload(e){await Promise.all(e.map(e=>this.#l(e))),this.list.refresh()}async#l(e){let t=++this.#t,n=new AbortController;this.#i.set(t,n),this.#u({id:t,name:e.name,size:e.size,status:`uploading`,progress:0});try{let r=e.type===``?`application/octet-stream`:e.type,{url:i,upload:a}=await this.#e.api.upload.call({name:e.name,mime:r,size:e.size});await this.#e.sender.put(i,e,e=>{this.#d(t,{progress:e})},n.signal),this.#d(t,{status:`importing`,progress:1});let o=await this.#e.api.uploaded.call({upload:a}),s=await this.#e.api.importResource.call({content:o,name:e.name});this.#d(t,{status:`done`,uri:s.uri})}catch(n){this.#d(t,{status:`failed`,problem:X(n,`Couldn't upload ${e.name}.`)})}finally{this.#i.delete(t)}}dismissUpload(e){this.#i.get(e)?.abort(),this.uploads.value=this.uploads.value.filter(t=>t.id!==e)}#u(e){this.uploads.value=[...this.uploads.value,e]}#d(e,t){this.uploads.value=this.uploads.value.map(n=>n.id===e?{...n,...t}:n)}async rename(e,t){let n=await this.acting.run(()=>this.#e.api.rename.call({uri:e,name:t}),`Couldn't rename it.`);return n.ok&&this.list.refresh(),n.ok}async remove(e){let t=await this.acting.run(async()=>{let t=await Promise.all(e.map(e=>this.#e.api.remove.call({uri:e})));return{deleted:t.filter(e=>e.deleted).length,kept:t.filter(e=>!e.deleted).length}},`Couldn't delete that.`);if(t.ok)return this.selected.value=new Set([...this.selected.value].filter(t=>!e.includes(t))),await this.list.load(),t.value}async makeContext(e){let t=await this.acting.run(async()=>(await Promise.all(e.map(e=>this.#e.api.contextFrom.call({uri:e,copy:`live`})))).flatMap(e=>[...e.created,...e.updated]),`Couldn't make context from that.`);return t.ok?t.value:void 0}async downloadUrl(e){let t=await this.acting.run(()=>this.#e.api.download.call({uri:e}),`Couldn't start the download.`);return t.ok?t.value.url:void 0}async make(e,t){let n=await this.acting.run(()=>Promise.all(e.map(e=>this.#e.api.convert.call({uri:e,kind:t}))),`Couldn't make that.`);return n.ok&&this.list.refresh(),n.ok}},Bp=class{#e;#t=new Map;at=L(``);roots=new W;file=new W;constructor(e){this.#e=e}async open(e,t){let n=`${e}/${t}`;(this.at.value!==n||this.roots.value.value===void 0)&&(this.at.value=n,this.#t.clear(),this.file.reset(),await this.roots.load(()=>this.#e.exploreRoots.call({system:e,instance:t}),`Couldn't list ${n}'s folders.`))}folder(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=new f({fetch:(e,t)=>this.#e.exploreList.call({uri:e,...t===void 0?{}:{cursor:t}}),key:e=>e.uri,failure:`Couldn't list this folder.`,limit:200},e);return this.#t.set(e,n),n.load(),n}peek(e){let t=ar.safeParse(e);return t.success?this.#t.get(t.data):void 0}async read(e){e===void 0?this.file.reset():this.file.value.value?.stat.uri!==e&&await this.file.load(()=>this.#e.exploreRead.call({uri:e,want:[`text`]}),`Couldn't read this file.`)}refresh(e){this.#t.get(e)?.load()}},Vp=class{#e;found=new W;constructor(e){this.#e=e}async search(e){let t=e.trim();t===``?this.found.reset():await this.found.load(async()=>(await this.#e.find.call({search:t,limit:8})).items,`Couldn't search resources.`)}},Hp={as:`text`,form:`raw`},Up={as:`url`},$={as:`none`},Wp={svg:{preview:{draws:`svg`,reads:Up},source:`code`},mermaid:{preview:{draws:`diagram`,reads:Hp},source:`code`},markdown:{preview:{draws:`markdown`,reads:Hp},source:`code`},html:{preview:{draws:`html`,reads:Hp},source:`code`},csv:{preview:{draws:`table`,reads:Hp},source:`code`},tsv:{preview:{draws:`table`,reads:Hp},source:`code`},excel:{preview:{draws:`table`,reads:{as:`version`,form:`table`}}},ods:{preview:{draws:`table`,reads:{as:`version`,form:`table`}}},pdf:{preview:{draws:`pdf`,reads:Up}},docx:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},pptx:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},odt:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},rtf:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},notebook:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}},source:`code`},json:{preview:{draws:`json`,reads:Hp},source:`code`},jsonl:{preview:{draws:`json`,reads:Hp},source:`code`},text:{source:`text`}},Gp={document:{source:`text`},code:{source:`code`},image:{preview:{draws:`image`,reads:Up}},table:{preview:{draws:`table`,reads:{as:`version`,form:`table`}}},audio:{preview:{draws:`audio`,reads:Up}},video:{preview:{draws:`video`,reads:Up}},web:{preview:{draws:`html`,reads:Hp},source:`code`},data:{source:`code`},archive:{preview:{draws:`folder`,reads:$}},folder:{preview:{draws:`folder`,reads:$}},other:{preview:{draws:`binary`,reads:$}}},Kp=[`markdown`,`table`,`pages`,`code`,`text`,`description`,`ocr`,`transcript`],qp={markdown:{draws:`markdown`,reads:{as:`text`,form:`markdown`}},text:{draws:`text`,reads:{as:`text`,form:`text`}},code:{draws:`code`,reads:{as:`text`,form:`code`}},pages:{draws:`pages`,reads:{as:`version`,form:`pages`}},table:{draws:`table`,reads:{as:`version`,form:`table`}},description:{draws:`markdown`,reads:{as:`text`,form:`description`}},ocr:{draws:`text`,reads:{as:`text`,form:`ocr`}},transcript:{draws:`text`,reads:{as:`text`,form:`transcript`}},thumbnail:{draws:`image`,reads:{as:`url`}}};function Jp(e){return e.as===`text`?e.form===`raw`?void 0:e.form:e.as===`version`?e.form:void 0}function Yp(e,t){let n=t.preview;return e===`thumbnail`||n===void 0?e===`thumbnail`:Jp(n.reads)===e||n.reads.as===`text`&&n.reads.form===`raw`&&qp[e].draws===n.draws}function Xp(e,t,n=[],r=[]){let i=$r(e),a=e.mime?.startsWith(`image/svg`)===!0?Wp.svg:void 0,o=(e.format===void 0?void 0:Wp[e.format])??a??Gp[i],s=ti(e.format)||`text`,c=new Set(t),l=[],u=r.find(e=>e.mode===`replace`);if(u!==void 0)l.push({id:`preview`,label:`Preview`,draws:`system`,reads:$,system:u.system});else if(o.preview!==void 0){let e=Jp(o.preview.reads),t=e===void 0?void 0:n.find(t=>t.kind===e);e===void 0||c.has(e)?l.push({id:`preview`,label:`Preview`,...o.preview,...e===void 0?{}:{form:e}}):l.push(t===void 0?{id:`preview`,label:`Preview`,draws:`binary`,reads:$}:{id:`preview`,label:`Preview`,draws:`offer`,reads:$,form:t.kind,offer:t})}o.source!==void 0&&l.push({id:`source`,label:l.length===0?`Text`:`Source`,draws:o.source,reads:Hp,...o.source===`code`?{language:s}:{}});for(let e of r.filter(e=>e.mode===`tab`))l.push({id:`system:${e.system}`,label:e.label,draws:`system`,reads:$,system:e.system});let d=[...Kp,...t.filter(e=>!Kp.includes(e))];for(let e of d){if(Yp(e,o))continue;if(c.has(e)){l.push({id:e,label:ei[e],...qp[e],form:e,...e===`code`?{language:s}:{}});continue}let t=n.find(t=>t.kind===e);t!==void 0&&l.push({id:e,label:ei[e],draws:`offer`,reads:$,form:e,offer:t})}return l.push({id:`info`,label:`Info`,draws:`info`,reads:$}),{family:i,modes:l,initial:l[0]?.id??`info`}}function Zp(e,t){let n={id:`info`,label:`Info`,draws:`info`,reads:$};return e.modes.find(e=>e.id===t)??e.modes.find(t=>t.id===e.initial)??n}function Qp(e){switch(e.as){case`text`:return`text:${e.form}`;case`url`:return`url`;case`version`:return`version:${e.form}`;case`none`:return`none`}}function $p(e){return e.value}var em=2e5;I(0);var tm=class{#e;uri=L(void 0);section=L(void 0);opened=new W;asked=I(void 0);#t=new Map;#n=I(0);making=new U;contexting=new U;plan;mode;systemViewers;constructor(e){this.#e=e,this.systemViewers=k(()=>{$p(e.systems.version);let t=this.opened.value.value?.stat.format;return t===void 0?[]:e.systems.viewers(t)}),this.plan=k(()=>{let e=this.opened.value.value;if(e===void 0)return;let t=this.systemViewers.value.map(e=>({system:e.system,mode:e.mode,label:e.label}));return Xp(e.stat,e.forms.map(e=>e.kind),e.offers,t)}),this.mode=k(()=>this.plan.value===void 0?void 0:Zp(this.plan.value,this.asked.value))}async open(e,t){let n=this.uri.value===e;n||(this.#t.clear(),this.#n.value++),this.uri.value=e,this.section.value=t,await this.opened.load(()=>this.#r(e),`Couldn't open this resource.`,n&&this.opened.value.value!==void 0)}close(){this.uri.value=void 0,this.opened.reset(),this.#t.clear(),this.#n.value++}async#r(e){try{let t=await this.#e.api.forms.call({uri:e});return{stat:t.record.stat,record:t.record,forms:t.forms,offers:t.offers,links:t.record.links,from:`library`,text:void 0}}catch(t){try{let t=await this.#e.api.systemRead.call({uri:e,want:[`text`,`links`]}),n=t.text!==void 0&&`inline`in t.text?t.text.inline:void 0;return{stat:t.stat,record:void 0,forms:[],offers:[],links:t.links??[],from:`system`,text:n}}catch{throw t}}}load(e){$p(this.#n);let t=this.uri.value,n=this.opened.value.value;if(e.as===`none`||t===void 0||n===void 0)return;let r=Qp(e),i=this.#t.get(r);if(i!==void 0)return i;let a=new W;return this.#t.set(r,a),a.load(()=>this.#i(t,n,e),e.as===`url`?`Couldn't load this file.`:`Couldn't read this.`),a}async#i(e,t,n){switch(n.as){case`text`:if(t.from===`system`){let n=t.text??``;return{as:`text`,result:{uri:e,form:`raw`,text:n,offset:0,total:n.length,truncated:!1,forms:[],offers:[]}}}return{as:`text`,result:await this.#e.api.read.call({uri:e,form:n.form,maxChars:em})};case`url`:if(t.from===`system`)throw Error(`This system resource has no download.`);return{as:`url`,download:await this.#e.api.download.call({uri:e})};case`version`:{let t=await this.#e.api.download.call({uri:e,form:n.form}),r=await this.#e.fetch(t.url);if(!r.ok)throw Error(`The download answered ${r.status}.`);return{as:`version`,version:kn.parse(await r.json())}}}}retry(e){this.#t.delete(Qp(e)),this.#n.value++}text(e){let t=this.load(e)?.value.value;return t?.as===`text`?t.result:void 0}download(e){let t=this.load(e)?.value.value;return t?.as===`url`?t.download:void 0}version(e){let t=this.load(e)?.value.value;return t?.as===`version`?t.version:void 0}async downloadUrl(e){let t=this.uri.value;if(t===void 0)return;let n=await this.making.run(()=>this.#e.api.download.call({uri:t,...e===void 0?{}:{form:e}}),`Couldn't start the download.`);return n.ok?n.value:void 0}async make(e){let t=this.uri.value;if(t===void 0)return!1;let n=await this.making.run(()=>this.#e.api.convert.call({uri:t,kind:e}),`Couldn't make that.`);return n.ok&&await this.open(t,this.section.value),n.ok}async makeContext(){let e=this.uri.value;if(e===void 0)return;let t=await this.contexting.run(()=>this.#e.api.contextFrom.call({uri:e,copy:`live`}),`Couldn't make context from this.`);return t.ok?t.value:void 0}changed(e){e.uri===this.uri.value&&(this.#t.clear(),this.#n.value++,this.open(e.uri,this.section.value))}systemView(e){let t=this.opened.value.value,n=this.uri.value;if(t===void 0||n===void 0)return;let r=this.#e;return{stat:t.stat,...this.section.value===void 0?{}:{section:this.section.value},forms:t.forms.map(e=>e.kind),text:async e=>t.from===`system`?t.text??``:(await r.api.read.call({uri:n,form:e??`raw`,maxChars:em})).text,bytes:async()=>{if(t.from===`system`)return new Uint8Array;let e=await r.api.download.call({uri:n});return new Uint8Array(await(await r.fetch(e.url)).arrayBuffer())},system:r.systems.client(e)}}},nm=class{#e;browser;explorer;constructor(e){this.#e=e,this.browser=new zp({api:e.api,events:e.events,sender:e.sender}),this.explorer=new Bp(e.api)}search(){return new Vp(this.#e.api)}viewer(){let e=new tm({api:this.#e.api,fetch:this.#e.fetch,systems:this.#e.systems}),t=this.#e.events(t=>{e.changed(t)});return this.#e.prepare(),xe()!==void 0&&Oe(t),{store:e,stop:t}}},rm=[`active`,`hidden`,`not_applicable`,`pending_approval`,`pending_removal`],im={active:`ok`,hidden:`neutral`,not_applicable:`neutral`,pending_approval:`warn`,pending_removal:`danger`,pending_plan:`accent`},am={person:`A person`,system:`A system`,research:`Research`};function om(e,t){let n=(e.filters??[]).filter(e=>e.field===t),[r]=n;return n.length===1&&r!==void 0&&r.op===`is`&&typeof r.value==`string`?r.value:void 0}function sm(e,t,n){let r=(e.filters??[]).filter(e=>e.field!==t),i=n===void 0?r:[...r,{field:t,op:`is`,value:n}],{filters:a,...o}=e;return i.length===0?o:{...o,filters:i}}function cm(e){return new Map(e.map(e=>[String(e.value),e.count]))}function lm(e){return e.sort?.[0]?.field===`lastModified`}var um={approve:{label:`Approve`,icon:`check`,from:[`pending_approval`],danger:!1,done:`Approved`},hide:{label:`Hide`,icon:`eye-off`,from:[`active`,`not_applicable`,`pending_approval`,`pending_removal`,`pending_plan`],danger:!1,done:`Hidden`},restore:{label:`Restore`,icon:`undo`,from:[`hidden`,`not_applicable`,`pending_removal`],danger:!1,done:`Restored`},confirm_removal:{label:`Confirm removal`,icon:`trash`,from:[`pending_removal`],danger:!0,done:`Removed`}};function dm(e,t){return e.origin?.type===`memory`&&t.me!==void 0&&e.origin.author===t.me}function fm(e,t){return t.admin||dm(e,t)}function pm(e,t,n){return um[t].from.includes(e.status)?n.admin||dm(e,n)&&(t===`hide`||t===`restore`):!1}function mm(e,t){return Wn.flatMap(n=>{let r=e.filter(e=>pm(e,n,t)).map(e=>e.name),i=um[n];return r.length===0?[]:[{action:n,label:i.label,icon:i.icon,danger:i.danger,names:r}]})}function hm(e,t,n){let r=`${um[e].done} ${t.toLocaleString()}`;return n===0?r:`${r} · ${n.toLocaleString()} left as ${n===1?`it was`:`they were`}`}function gm(e){return e===void 0?``:`${Math.round(Math.min(1,Math.max(0,e))*100)}% alike`}function _m(e){let t=[];if(e.duplicate!==void 0){let n=gm(e.duplicate.similarity);t.push({key:`duplicate`,label:`Possible duplicate`,tone:`warn`,icon:`copy`,title:`May say the same as ${e.duplicate.of}${n===``?``:` (${n})`}: ${e.duplicate.reason}`})}if(e.contradiction!==void 0&&t.push({key:`contradiction`,label:`Contradiction`,tone:`danger`,icon:`warning`,title:`Its answer may disagree with ${e.contradiction.of}: ${e.contradiction.reason}`}),e.metadataStale===!0&&t.push({key:`stale`,label:`Metadata out of date`,tone:`neutral`,icon:`clock`,title:`Its text changed since its question was written; it is filled in again in the background.`}),e.split?.from!==void 0)t.push({key:`split`,label:`Split out`,tone:`accent`,icon:`tree`,title:`Made from ${e.split.from}, which answered several questions.`});else if(e.split?.into!==void 0&&e.split.into.length>0){let n=e.split.into.length;t.push({key:`split`,label:`Split into ${n}`,tone:`accent`,icon:`tree`,title:`It answered several questions, so it was split into ${n} items, one per question.`})}return t}function vm(e){return e.statusReason??ym[e.status]}var ym={active:`In use: searched, suggested and loaded.`,hidden:`Switched off: left out of every selection and search.`,not_applicable:`Ruled out by a plan’s answer; a model sees it only when it has an answer and asks for it.`,pending_approval:`New from a system or a resource; not searched or loaded until an admin approves it.`,pending_removal:`Its source dropped it; it keeps working until an admin confirms the removal.`,pending_plan:`An open question in a plan, with no answer yet.`},bm={duplicate:{label:`Duplicates`,about:`Items that may answer the same question as a newer one. Merge them, keep both, or hide the older.`},contradiction:{label:`Contradictions`,about:`Items whose answers to the same question may disagree. Hide the one that is wrong, or edit it.`},pending_approval:{label:`Waiting for approval`,about:`New context from systems and resources. It is not searched or loaded until it is approved.`},pending_removal:{label:`Waiting for removal`,about:`Items their source dropped. They keep working until the removal is confirmed.`}};function xm(e){let t=new Set;return e.filter(e=>{if(e.kind!==`contradiction`||e.other===void 0)return!0;let n=[e.item.name,e.other.name].sort().join(`|`);return!t.has(n)&&(t.add(n),!0)})}function Sm(e){if(e===void 0)return 0;let{duplicate:t,contradiction:n,pending_approval:r,pending_removal:i}=e.counts;return t+n+r+i-(e.items.length-xm(e.items).length)}var Cm={active:{label:`Active`,about:`New context from systems and resources is in use at once.`},pending_approval:{label:`Pending approval`,about:`An admin approves each new item in Review before it is used.`},hidden:{label:`Hidden`,about:`New items start switched off; an admin restores the ones to use.`}},wm={question:`Question`,when:`When`,askedBy:`Asked by`,validUntil:`Valid until`};function Tm(e,t){return e!==void 0&&e<=t}function Em(e){return new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}function Dm(e){return[...e].sort((e,t)=>t.at-e.at)}function Om(e,t){return e.from===void 0?t[e.status]:`${t[e.from]} → ${t[e.status]}`}var km=class{#e;statusCounts=new W;askerCounts=new W;queue=new W;setting=new W;acting=new U;saving=new U;busyKey=I(``);#t=!1;constructor(e){this.#e=e}async load(e){this.#t=e,await Promise.all([this.loadCounts(!1),...e?[this.loadQueue(!1),this.setting.load(()=>this.#e.newStatus.call({}),`Couldn't load the setting.`)]:[]])}async loadCounts(e=!0){await Promise.all([this.statusCounts.load(async()=>cm(await this.#e.values.call({list:`contexts`,field:`status`,limit:20})),`Couldn't count the statuses.`,e),this.askerCounts.load(async()=>cm(await this.#e.values.call({list:`contexts`,field:`askedBy`,limit:20})),`Couldn't count who asked.`,e)])}async loadQueue(e=!0){await this.queue.load(()=>this.#e.review.call({limit:100}),`Couldn't load Review.`,e)}changed(){this.loadCounts(),this.#t&&this.loadQueue()}async setStatus(e,t=``){return this.#n(t,()=>this.#e.setStatus.call(e),`Couldn't change those items.`)}async merge(e,t=``){return this.#n(t,()=>this.#e.merge.call(e),`Couldn't merge them.`)}async notDuplicate(e,t=``){return this.#n(t,async()=>(await this.#e.notDuplicate.call(e)).ok,`Couldn't clear that flag.`)}async saveSetting(e){let t=await this.saving.run(()=>this.#e.setNewStatus.call({value:e}),`Couldn't change the setting.`);return t.ok&&this.setting.set(t.value),t}async#n(e,t,n){this.busyKey.value=e;let r=await this.acting.run(t,n);return this.busyKey.value=``,r.ok&&await Promise.all([this.loadCounts(),...this.#t?[this.loadQueue()]:[]]),r}},Am=class{#e;list=new W;open=new W;answering=new U;busyQuestion=I(``);deeper=I([]);#t=!1;constructor(e){this.#e=e}async loadList(e=!1){this.#t=!0,await this.list.load(()=>this.#e.plans.call({}),`Couldn't load the plans.`,e)}async show(e){let t=this.open.value.value?.run===e;t||(this.open.reset(),this.deeper.value=[]),await this.open.load(()=>this.#e.plan.call({run:e}),`Couldn't load the plan.`,t)}close(){this.open.reset(),this.deeper.value=[]}async markdown(e){try{return(await this.#e.plan.call({run:e,format:`markdown`})).markdown}catch{return}}async answer(e,t){let n={run:e,...t.answer===void 0?{}:{answers:[t.answer]},...t.reason===void 0?{}:{reasons:[t.reason]}};this.busyQuestion.value=t.answer?.question??t.reason?.question??``;let r=await this.answering.run(()=>this.#e.answerPlan.call(n),`Couldn't save that answer.`);return this.busyQuestion.value=``,r.ok&&(this.open.value.value?.run===e&&this.open.set({run:e,plan:r.value.plan}),this.deeper.value=r.value.deeper,this.#t&&this.loadList(!0)),r}changed(){this.#t&&this.loadList(!0);let e=this.open.value.value?.run;e!==void 0&&!this.answering.busy.value&&this.show(e)}},jm=class{#e;name=I(void 0);view=new W;metadata=new W;reextracting=new U;choiceTargets=I(new Map);linking=new U;unlinking=new U;forgetting=new U;saving=new U;constructor(e){this.#e=e}async open(e){let t=this.name.value===e&&this.view.value.value!==void 0;t||(this.view.reset(),this.metadata.reset(),this.choiceTargets.value=new Map),this.name.value=e,await Promise.all([this.view.load(()=>this.#e.item.call({name:e}),`Couldn't load this context item.`,t),this.metadata.load(()=>this.#e.metadata.call({name:e}),`Couldn't load its metadata.`,t)]),await this.#t(e)}async#t(e){let t=[...new Set(this.view.value.value?.record.decl.choices?.map(e=>e.to)??[])];if(t.length===0)this.choiceTargets.value=new Map;else try{let n=await this.#e.list.call({query:{filters:[{field:`name`,op:`in`,values:t}]},limit:Math.min(t.length,200)});this.name.value===e&&(this.choiceTargets.value=new Map(n.items.map(e=>[e.name,e])))}catch{}}close(){this.name.value=void 0,this.view.reset(),this.metadata.reset(),this.choiceTargets.value=new Map}touches(e){let t=this.view.value.value;return this.name.value===void 0||t===void 0?!1:this.name.value===e||t.backlinks.some(t=>t.from===e)||t.links.some(t=>t.to.kind===`context`&&t.to.name===e)}async reload(){let e=this.name.value;e!==void 0&&await this.open(e)}async addLink(e){let t=this.name.value;if(t===void 0)return{ok:!1,problem:`No context item is open.`};let n=ue(e,t);if(!n.ok)return this.linking.problem.value=n.problem,n;let r=await this.linking.run(()=>this.#e.link.call({from:t,to:n.value.to,relation:n.value.relation,weight:n.value.weight}),`Couldn't add that link.`);return r.ok&&await this.reload(),r}async removeLink(e){let t=await this.unlinking.run(async()=>(await this.#e.unlink.call({from:e.from,toKey:e.toKey,relation:e.relation})).ok,`Couldn't remove that link.`);return t.ok&&await this.reload(),t}async forget(){let e=this.name.value;if(e===void 0)return{ok:!1,problem:`No context item is open.`};let t=await this.forgetting.run(async()=>(await this.#e.forget.call({name:e})).ok,`Couldn't forget this memory.`);return t.ok&&await this.reload(),t}async reextract(){let e=this.name.value;if(e===void 0)return{ok:!1,problem:`No context item is open.`};let t=await this.reextracting.run(()=>this.#e.reextract.call({names:[e]}),`Couldn't fill its metadata again.`);return t.ok&&await this.reload(),t}async edit(e){let t=this.view.value.value;if(t?.record.origin?.type!==`memory`)return{ok:!1,problem:`Only a memory can be edited.`};let n=ce(t.record.name,e);if(!n.ok)return this.saving.problem.value=n.problem,n;let r=await this.saving.run(async()=>(await this.#e.updateMemory.call(n.value)).name,`Couldn't save this memory.`);return r.ok&&await this.open(r.value),r}},Mm=class{#e;list;item;review;plans;remembering=new U;making=new U;#t=0;#n;constructor(e){this.#e=e,this.list=new f({fetch:(t,n,r)=>e.api.list.call({...t,limit:r,...n===void 0?{}:{cursor:n}}),key:e=>e.name,failure:`Couldn't load the context.`,limit:50},{}),this.item=new jm(e.api),this.review=new km(e.api),this.plans=new Am(e.api)}async show(e){this.list.loaded.value&&JSON.stringify(e)===JSON.stringify(this.list.filter.value)?await this.list.refresh():await this.list.load(e)}follow(){this.#t++,this.#n??=this.#e.events(e=>{this.changed(e)});let e=!1,t=()=>{e||(e=!0,this.#t--,this.#t===0&&(this.#n?.(),this.#n=void 0))};return xe()!==void 0&&Oe(t),t}changed(e){this.list.refresh(),this.review.changed(),this.plans.changed(),this.item.touches(e)&&this.item.reload()}async remember(e){let t=ne(e);if(!t.ok)return this.remembering.problem.value=t.problem,t;let n=await this.remembering.run(async()=>(await this.#e.api.remember.call(t.value)).name,`Couldn't remember that.`);return n.ok&&this.list.refresh(),n}async fromResource(e){let t=await this.making.run(()=>this.#e.api.fromResource.call(e),`Couldn't make context from that resource.`);return t.ok&&this.list.refresh(),t}},Nm=class{#e;#t;#n;name=I(void 0);about=new W;facts=new W;examples=L([]);examplesTotal=I(0);examplesNext=I(void 0);examplesLoading=I(!1);examplesProblem=I(``);#r=0;constructor(e,t){this.#e=e,this.#t=t}async open(e){let t=this.name.value===e;t||this.close(),this.name.value=e,this.#n??=this.#t(e=>{this.#o(e)}),await Promise.all([this.#i(e,t),this.#a(e,t),t?Promise.resolve():this.moreExamples()])}close(){this.#n?.(),this.#n=void 0,this.name.value=void 0,this.about.reset(),this.facts.reset(),this.#r++,this.examples.value=[],this.examplesTotal.value=0,this.examplesNext.value=void 0,this.examplesLoading.value=!1,this.examplesProblem.value=``}async moreExamples(){let e=this.name.value,t=this.examples.value.length===0?0:this.examplesNext.value;if(e===void 0||t===void 0||this.examplesLoading.value)return;let n=++this.#r;this.examplesLoading.value=!0,this.examplesProblem.value=``;try{let r=await this.#e.fnExamples.call({fn:e,offset:t,limit:5});if(n!==this.#r)return;this.examples.value=[...this.examples.value,...r.items],this.examplesTotal.value=r.total,this.examplesNext.value=r.next}catch(e){n===this.#r&&(this.examplesProblem.value=X(e,`Couldn't load its examples.`))}finally{n===this.#r&&(this.examplesLoading.value=!1)}}async#i(e,t){await this.about.load(async()=>(await this.#e.searchFns.call({names:[e],items:[`fn`],available:!1,limit:1})).items.find(t=>t.name===e),`Couldn't load this fn.`,t)}async#a(e,t){await this.facts.load(()=>this.#e.fnFacts.call({fn:e}),`Couldn't load this fn's facts.`,t)}#o(e){let t=this.name.value;e.type===`fn`&&t!==void 0&&e.fn===t&&this.#a(t,!0)}},Pm=class{#e;known=L(new Map);#t=new Set;constructor(e){this.#e=e}fnOf(e){return fn(e,e=>this.known.value.get(e))}async resolve(e){let t=[...new Set(e)].filter(e=>un(e)&&!this.#t.has(e));if(t.length!==0){for(let e of t)this.#t.add(e);try{let e=await this.#e.fnsOfModelNames.call({names:t});this.known.value=new Map([...this.known.value,...Object.entries(e)])}catch{for(let e of t)this.#t.delete(e)}}}},Fm=`harness.hubName`,Im=class{#e;#t;#n;#r;#i;identity=L(void 0);name=k(()=>this.identity.value?.name??this.#r??`fnloom`);source=k(()=>this.identity.value?.source);version=k(()=>this.identity.value?.version??``);saving=new U;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=n===void 0?void 0:Br(n,Fm,dn)}async load(){try{this.#o(await this.#e.identity.call(Al))}catch{}}start(){this.#i??=this.#t(e=>{this.#a(e)})}stop(){this.#i?.(),this.#i=void 0}async rename(e){let t=await this.saving.run(()=>this.#e.setHubName.call({name:e}),`Couldn't save the name.`);return t.ok&&this.#o(t.value),t}#a(e){e.type===`identity`&&this.#o(e.identity)}#o(e){this.identity.value=e;try{this.#n?.setItem(Fm,JSON.stringify(e.name))}catch{}}},Lm={setting:`Set here.`,env:`From the hub’s FNLOOM_NAME setting.`,default:`The default name.`};function Rm(e){let t=dn.safeParse(e);return t.success?{ok:!0,name:t.data}:{ok:!1,problem:e.trim()===``?`Give the hub a name.`:`Keep it to one line of at most 40 characters.`}}var zm=class{#e;view=L(void 0);value=k(()=>this.view.value?.value??`ask`);saving=new U;constructor(e){this.#e=e}async load(){try{this.view.value=await this.#e.outsideImages.call({})}catch{}}async set(e){let t=await this.saving.run(()=>this.#e.setOutsideImages.call({value:e}),`Couldn't save the setting.`);return t.ok&&(this.view.value=t.value),t}clear(){this.view.value=void 0}},Bm=class{#e;page=new W;#t;constructor(e){this.#e=e}async show(e){let t=this.#t!==void 0&&JSON.stringify(e)===JSON.stringify(this.#t)&&this.page.value.value!==void 0;this.#t=e,await this.page.load(()=>this.#e.graph.call(e),`Couldn't load the graph.`,t)}async refresh(){this.#t!==void 0&&await this.show(this.#t)}},Vm=class{#e;run=new W;tree=new W;approval=L(void 0);acting=new U;id=L(void 0);branch=k(()=>this.id.value===void 0?void 0:re(this.tree.value.value,this.id.value));constructor(e){this.#e=e}async open(e){this.id.value!==e&&(this.id.value=e,this.run.reset(),this.tree.reset(),this.approval.value=void 0),await this.#t(e,!1)}async refresh(){let e=this.id.value;e!==void 0&&await this.#t(e,!0)}async decide(e,t,n){let r=this.approval.value;if(r===void 0)return!1;let i=await this.acting.run(()=>this.#e.approve.call({approval:r.id,approve:e,remember:`once`,...t===``?{}:{reason:t},...n===void 0?{}:{answer:n}}),`Couldn't send your answer.`);return i.ok&&(this.approval.value=void 0,this.refresh()),i.ok}async undo(){let e=this.run.value.value;if(e===void 0)return{ok:!1,problem:`The run has not loaded yet.`};let t=await this.acting.run(()=>this.#e.undoTurn.call({turn:e.turn}),`Couldn't undo it.`);return t.ok&&await this.refresh(),t}async background(){let e=this.run.value.value;if(e===void 0)return{ok:!1,problem:`The run has not loaded yet.`};let t=await this.acting.run(async()=>(await this.#e.background.call({run:e.id})).accepted,`Couldn't move it to the background.`);return t.ok&&this.refresh(),t}async#t(e,t){await this.run.load(()=>this.#e.run.call({run:e}),`Couldn't load this run.`,t);let n=this.run.value.value;n!==void 0&&n.id===e&&this.id.value===e&&await Promise.all([this.tree.load(()=>this.#e.tree.call({turn:n.turn}),`Couldn't load what it called.`,t||this.tree.value.value!==void 0),this.#n(n)])}async#n(e){if(e.status!==`awaiting-approval`)this.approval.value=void 0;else try{let t=await this.#e.approvals.call({runs:[e.id]});this.id.value===e.id&&(this.approval.value=t.find(t=>t.run===e.id&&t.status===`pending`))}catch{this.id.value===e.id&&(this.approval.value=void 0)}}},Hm=class{#e;sets;constructor(e){this.#e=e,this.sets=new f({fetch:async(e,t,n)=>this.#e.dataSets.call({limit:n,...t===void 0?{}:{cursor:t},...e.text===``?{}:{text:e.text},...e.system===void 0?{}:{system:e.system}}),key:e=>e.type,failure:`Couldn't load the stored data.`,limit:50},{text:``,system:void 0})}async rowActions(e){return this.#e.rowActions.call(e)}async findRecords(e){return this.#e.records.call(e)}async readFn(e,t){return this.#e.readFn.call({fn:e,args:{...t}})}async exportCsv(e){let t=await this.#e.exportCsv.call(e);return new Response(t).blob()}records(){return new Um(this.#e)}},Um=class{#e;table=new W;shown=L(void 0);#t;record=new W;versions=L([]);versionsNext=I(void 0);versionsLoading=I(!1);versionsProblem=I(``);saving=new U;constructor(e){this.#e=e}async show(e){let t=this.#t!==void 0&&JSON.stringify(this.#t)===JSON.stringify(e)&&this.table.value.value!==void 0;this.#t!==void 0&&this.#t.type!==e.type&&(this.table.reset(),this.shown.value=void 0),this.#t=e,await this.table.load(()=>this.#e.recordTable.call(e),`Couldn't load these records.`,t),this.#t===e&&this.table.problem.value===``&&(this.shown.value=e)}async open(e,t){let n=this.record.value.value?.id===t;await Promise.all([this.record.load(async()=>(await this.#e.record.call({type:e,id:t})).record,`Couldn't load this record.`,n),this.#r(e,t,!0)])}close(){this.record.reset(),this.versions.value=[],this.versionsNext.value=void 0,this.versionsProblem.value=``}async moreVersions(){let e=this.record.value.value;e!==void 0&&this.versionsNext.value!==void 0&&await this.#r(e.type,e.id,!1)}async save(e,t,n,r){let i=await this.saving.run(()=>this.#e.saveRecord.call({type:e,value:t,...n===void 0?{}:{id:n},...r===void 0?{}:{expect:r}}),`Couldn't save this record.`);if(i.ok)return this.record.value.value?.id===i.value.id&&(this.record.set(i.value),this.#r(e,i.value.id,!0)),await this.#n(),i.value}async window(e){return this.#e.recordTable.call(e)}follow(e){this.record.value.value?.id===e.id&&(this.record.set(e),this.#r(e.type,e.id,!0))}async remove(e,t){let n=await this.saving.run(()=>this.#e.removeRecord.call({type:e,id:t}),`Couldn't remove this record.`);return!n.ok||!n.value.removed?!1:(this.close(),await this.#n(),!0)}async#n(){let e=this.#t;e!==void 0&&await this.table.load(()=>this.#e.recordTable.call(e),`Couldn't load these records.`,!0)}async#r(e,t,n){this.versionsLoading.value=!0,this.versionsProblem.value=``;try{let r=n?void 0:this.versionsNext.value,i=await this.#e.recordVersions.call({type:e,id:t,limit:20,...r===void 0?{}:{cursor:r}});this.versions.value=n?i.items:[...this.versions.value,...i.items],this.versionsNext.value=i.cursor}catch{this.versionsProblem.value=`Couldn't load this record's history.`}finally{this.versionsLoading.value=!1}}},Wm=class{#e;#t;list=new W;nav=k(()=>ki(this.list.value.value??[]));constructor(e){this.#e=e}get hub(){return this.#e.hub}async load(e=!1){await this.list.load(()=>this.#e.api.systemPages.call({}),`Couldn’t load the systems’ pages.`,e)}async refresh(){this.#e.api.systemPages.invalidate(),await this.load(!0)}start(){this.#t===void 0&&(this.#t=this.#e.events(e=>{this.#n(e)}))}stop(){this.#t?.(),this.#t=void 0}clear(){this.stop(),this.list.reset()}page(e,t){return this.list.value.value?.find(n=>n.system===e&&n.segment===t)}#n(e){e.type===`capabilities`&&this.refresh()}},Gm=`harness.theme`,Km=Xn([`system`,`light`,`dark`]),qm=`(prefers-color-scheme: dark)`,Jm=class{choice;#e=I(!1);#t;constructor(e){this.choice=Ur(e.store,Gm,Km,`system`);let t=e.media(qm);this.#e.value=t.matches;let n=e=>{this.#e.value=e.matches};t.addEventListener(`change`,n);let r=S(this.theme,t=>{e.root.dataset.theme=t},{immediate:!0,flush:`sync`});this.#t=()=>{t.removeEventListener(`change`,n),r()}}theme=k(()=>this.choice.value===`system`?this.#e.value?`dark`:`light`:this.choice.value);dispose(){this.#t()}},Ym={duration:5e3,max:4},Xm=class{#e;#t=new Map;#n=L([]);#r=1;constructor(e=Ym){this.#e=e}get items(){return this.#n.value}push(e){let t=this.#r++,n={view:{id:t,tone:e.tone??`neutral`,title:e.title,...e.body===void 0?{}:{body:e.body},...e.action===void 0?{}:{action:e.action.label}},run:e.action?.run,duration:e.duration??this.#e.duration,timer:void 0};for(this.#t.set(t,n),this.#i(n);this.#t.size>this.#e.max;){let e=this.#t.keys().next();if(e.done===!0)break;this.dismiss(e.value)}return this.#a(),t}ok(e,t){return this.push({tone:`ok`,title:e,...t===void 0?{}:{body:t}})}error(e,t){return this.push({tone:`danger`,title:e,...t===void 0?{}:{body:t}})}dismiss(e){let t=this.#t.get(e);t!==void 0&&(clearTimeout(t.timer),this.#t.delete(e),this.#a())}act(e){let t=this.#t.get(e);this.dismiss(e),t?.run?.()}hold(e){let t=this.#t.get(e);t!==void 0&&(clearTimeout(t.timer),t.timer=void 0)}release(e){let t=this.#t.get(e);t!==void 0&&t.timer===void 0&&this.#i(t)}#i(e){e.duration>0&&(e.timer=setTimeout(()=>{this.dismiss(e.view.id)},e.duration))}#a(){this.#n.value=Array.from(this.#t.values(),e=>e.view)}};function Zm(e){return e.connection.onReconnect(()=>{e.session.signedIn.value&&(e.inbox.refresh(),e.chat.refresh(),e.pages.refresh(),e.admin.systems.list.value.value!==void 0&&e.admin.systems.load(!0))})}function Qm(e){let t=new Rp(e.localStorage,Date.now,Vr(e),Lp(e.document)),{hub:n}=Wf({origin:e.location.origin,token:()=>t.accessToken.value,unauthorized:()=>o.recover()}),r=new sp({send:ap(n),signedIn:()=>t.signedIn.value,page:()=>e.location.pathname});r.watch(e);let i=qf(n,e=>{r.traffic(e)}),a=Kl(i,()=>t.user.value?.id),o=new _p(a.auth,t,Date.now,new gp(e.navigator)),s=new xp(a.connection),c=new he(a.notifications,a.userEvents),l=new Bf({api:a.chat,userEvents:a.userEvents,sessionEvents:a.sessionEvents,store:e.localStorage,sender:new Ol,clock:Date.now,client:()=>zf(),me:()=>t.user.value?.id,recorder:()=>Mf.available()?new Mf:void 0,speech:()=>Pf(e),renderers:{share:async()=>{(await ni(async()=>{let{shareChatModules:e}=await import(`./shared-Bxhw_9et.js`);return{shareChatModules:e}},__vite__mapDeps([0,1,2,3,4]))).shareChatModules()}}}),u=new _l({api:a.admin,chat:a.chat,userEvents:a.userEvents,systemLogs:a.systemLogs,sender:new Ol,probe:new Ss((t,n)=>e.fetch(t,n))}),d=l.renderers.runtime;d.register(yd);let f=new nm({api:a.resources,events:a.resourceEvents,sender:new Ol,fetch:(t,n)=>e.fetch(t,n),systems:{viewers:e=>d.resourceViewers(e),client:e=>d.systemClient(e),version:l.renderers.version},prepare:()=>l.prepareRenderers()}),p=new Wm({api:a.pages,events:a.userEvents,hub:i});return Zm({session:t,connection:s,inbox:c,chat:l,admin:u,pages:p}),{session:t,identity:new Im(a.identity,a.userEvents,e.localStorage),outsideImages:new zm(a.outsideImages),keeper:o,theme:new Jm({store:e.localStorage,media:t=>e.matchMedia(t),root:e.document.documentElement}),layout:new Hr(e.localStorage),toasts:new Xm,inbox:c,connection:s,chat:l,admin:u,signInForm:()=>new fp(a.auth,t,e.localStorage),account:new vp(a.auth),resources:f,context:new Mm({api:a.context,events:a.contextEvents}),fns:new Nm(a.fns,a.userEvents),fnNotices:new Zt(a.fns),modelNames:new Pm(a.fns),graph:()=>new Bm(a.graph),runPage:()=>new Vm(a.chat),data:new Hm(a.data),pages:p,itemVersions:e=>a.data.itemVersions.call(e),logs:r,push:new Sp(a.notifications,new Ep(e,Cp.built),()=>e.navigator.userAgent),install:new kp(new jp(e)),https:new Dp(a.https)}}var $m={name:`harness-scopes`,type:`light`,fg:`#000000`,bg:`#ffffff`,settings:[]},eh=[[`comment`,`comment`],[`punctuation.definition.comment`,`comment`],[`string`,`string`],[`punctuation.definition.string`,`string`],[`constant.numeric`,`number`],[`constant.language`,`literal`],[`support.constant`,`literal`],[`constant.character`,`literal`],[`keyword.operator`,`plain`],[`keyword`,`keyword`],[`storage`,`keyword`]];function th(e){for(let t of[...e].reverse()){let e=eh.find(([e])=>t===e||t.startsWith(`${e}.`));if(e!==void 0)return e[1]}return`plain`}function nh(e){let t=[],n=(e,n)=>{let r=t.at(-1);r?.kind===e?t[t.length-1]={kind:e,text:r.text+n}:n!==``&&t.push({kind:e,text:n})};return e.forEach((e,t)=>{t>0&&n(`plain`,`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/shared-Bc4GJbiE.js","assets/rolldown-runtime-COiEfhsA.js","assets/runtime-core.esm-bundler-wlpNGAAZ.js","assets/src-ClMFVauH.js","assets/push-payload-C1ppI5V2.js","assets/core-DdF778CY.js","assets/langs-CVIiVMBh.js","assets/preload-helper-7y9sWmk5.js","assets/mermaid.core-BNF3dRf5.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/chunk-DUW6YSOI-Dgx8z5s3.js","assets/chunk-M57EVK23-qYz6TUV4.js","assets/chunk-LEVMRMFU-paszafIt.js","assets/chunk-AXFCVDMN-CI0arS1F.js","assets/chunk-X4PVCEUW-YYhMSieL.js","assets/chunk-BG4553SI-DGn4S0JL.js","assets/d3-selection-COWvaQNI.js","assets/chunk-STOXU5M4-D5Gd-wq9.js","assets/chunk-R3KSYZAL-DW0WB_9q.js","assets/chunk-6MUBBAK2-BHXbrulB.js","assets/dist-DdXDFcej.js","assets/chunk-J5ZVWO5B-oDCd-gWO.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-DQASFODM-ClbbgMVy.js"])))=>i.map(i=>d[i]);
2
+ import{C as e,E as t,O as n,c as r,h as i,i as a,l as o,q as s,x as c,y as l}from"./src-ClMFVauH.js";import{Ar as u,At as d,Cr as f,Ct as p,Dr as m,Kt as h,Or as g,Tt as _,Ut as ee,Vt as te,ct as ne,f as re,i as v,jr as ie,kr as ae,l as oe,lr as se,lt as ce,mr as le,o as y,ot as ue,s as de,u as fe,wr as pe,wt as me,y as he}from"./routes-oIISbS5Z.js";import{$ as ge,D as b,E as x,Ft as _e,Ht as S,Lt as ve,On as C,St as ye,T as be,Zn as w,_ as T,an as xe,b as E,bt as D,ct as Se,er as Ce,et as we,fn as O,g as k,gn as Te,gt as Ee,it as De,k as A,mt as j,o as M,pn as Oe,qt as N,tr as P,tt as ke,v as F,vn as I,w as Ae,wt as je,xn as L,xt as Me,y as R}from"./runtime-core.esm-bundler-wlpNGAAZ.js";import{n as Ne}from"./RunCard-BMyRkKxJ.js";import{a as Pe,o as Fe}from"./TableView-BK_95qHT.js";import{t as Ie}from"./ConfirmDialog-BtugUGEY.js";import{t as Le}from"./FactList-CeAbKajD.js";import{t as Re}from"./LoadState-8UknKQ6e.js";import{t as ze}from"./AppPage-D_kkUatv.js";import{A as Be,C as Ve,D as He,S as Ue,_ as We,b as Ge,d as Ke,f as qe,g as Je,h as Ye,i as Xe,j as Ze,k as Qe,o as $e,p as et,r as tt,s as nt,t as rt,u as it,w as at,x as ot,y as st}from"./UserMessage-DJH2bXqv.js";import{d as z,i as ct,l as lt,r as ut,u as B}from"./labels-DkV96Md_.js";import{t as dt}from"./FnPill-Dm5mmffj.js";import{t as ft}from"./GinForm-p7UsKQ3s.js";import{t as pt}from"./GinValueView-D6c7E4C_.js";import{l as mt,n as ht,r as gt,t as _t}from"./ResourceViewer-CSAY6xIs.js";import{A as vt,C as yt,D as bt,F as xt,G as St,H as V,I as Ct,L as wt,M as Tt,N as Et,O as Dt,P as Ot,R as kt,S as At,U as jt,V as Mt,W as Nt,X as Pt,Y as Ft,_ as It,a as Lt,b as Rt,f as zt,i as Bt,j as Vt,l as Ht,n as Ut,o as Wt,p as Gt,q as Kt,r as qt,t as Jt,v as Yt,z as H}from"./ui-CjoSgSyZ.js";import{n as U,t as W}from"./loaded-BrwmsuZY.js";import{r as Xt,t as Zt}from"./fn-notices-C8HXeo7m.js";import{G as Qt,H as $t,V as en,z as tn}from"./state-BQlvjJzT.js";import{t as nn}from"./now-40JhSjx0.js";import{n as G,r as rn,t as an}from"./stores-BMEvTe-I.js";import{$a as on,Ao as sn,Br as cn,Ci as ln,Di as un,Dt as dn,Ei as fn,En as pn,Fo as mn,Fr as hn,Ho as gn,Ht as _n,Ia as vn,Ir as yn,Jr as bn,Kn as xn,Kr as Sn,Lo as Cn,Lr as wn,Ma as Tn,Mo as En,Q as Dn,Qa as On,Qn as kn,Ro as K,S as An,Sn as jn,Sr as Mn,Uo as Nn,Ut as Pn,Va as Fn,Vo as q,Vt as In,Wn as Ln,Wo as Rn,Wr as zn,Xa as Bn,Ya as Vn,Yr as Hn,Za as Un,Zr as Wn,at as Gn,dr as Kn,eo as qn,io as Jn,jo as Yn,ko as Xn,l as Zn,ot as Qn,qa as $n,qr as er,ra as tr,ro as nr,tn as rr,u as ir,ui as ar,wr as J}from"./push-payload-C1ppI5V2.js";import{A as or,C as sr,E as cr,a as lr,f as ur,h as dr,r as fr,s as pr,x as mr}from"./runs-BWVBevgu.js";import{t as Y}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{n as hr,r as gr,t as _r}from"./fn-modal-DFtN7Kn-.js";import{b as vr,f as yr,g as br,r as xr,s as Sr,v as Cr}from"./systems-Dt01wDhP.js";import{a as wr,i as Tr,n as Er,r as Dr,t as Or}from"./metrics-BBvD6KSk.js";import{n as kr,t as Ar}from"./ItemHistory-vsyIMjIX.js";import{i as jr,n as Mr,r as Nr,t as Pr}from"./InjectedList-BTGvy8GB.js";import{i as X,n as Z,r as Fr,t as Ir}from"./problems-CI9huk1n.js";import{t as Lr}from"./sources-gONU9kk2.js";import{t as Rr}from"./RendererHost-CmkaVEX0.js";import{t as zr}from"./RunDot-Lfrt5XR3.js";import{c as Br,l as Vr,n as Hr,s as Ur,t as Wr}from"./layout-CTAHAwIH.js";import{C as Gr,T as Kr,d as qr,j as Jr,u as Yr}from"./review-DlP8FQiO.js";import{v as Xr}from"./tables-CkqGZ0Yq.js";import{o as Zr,s as Qr}from"./record-edits-DFJBcNnL.js";import{a as $r,i as ei,o as ti}from"./formats-CHSYhY4X.js";import{t as ni}from"./preload-helper-7y9sWmk5.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ri=A({__name:`PageApproval`,props:{approval:{},inChat:{type:Boolean,default:!1},description:{default:``}},emits:[`decide`],setup(e,{emit:t}){let n=t;return(t,r)=>(j(),F(Xt,{ident:e.approval.id,"data-approval":e.approval.id,fn:e.approval.fn,description:e.description,args:void 0,preview:e.approval.preview,rememberable:e.inChat&&C(Qe)(e.approval),ask:e.approval.ask,onDecide:r[0]||=(e,t,r,i)=>n(`decide`,e,t,r,i)},null,8,[`ident`,`data-approval`,`fn`,`description`,`preview`,`rememberable`,`ask`]))}}),ii=A({__name:`PageComposer`,props:{modelValue:{},placeholder:{default:`Message`},sending:{type:Boolean,default:!1},running:{type:Boolean,default:!1},stopping:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},note:{default:``}},emits:[`update:modelValue`,`send`,`stop`],setup(e,{emit:t}){let n=e,r=t,i=Qt(),a=nn(),o={open:!1,kind:void 0,items:[],active:0,loading:!1},s={available:!1,state:`idle`,startedAt:0,problem:``},c={shown:!1,on:!1};function l(e){e===`cancel`&&r(`stop`)}return(t,u)=>(j(),F(We,{text:e.modelValue,placeholder:e.placeholder,tokens:[],"can-send":!n.disabled&&e.modelValue.trim()!==``,sending:e.sending,running:e.running,paused:!1,stopping:e.stopping,"immediate-stop":``,picker:o,files:[],"reply-all":c,answerers:``,"can-attach":!1,voice:s,now:C(a),touch:C(i),note:e.note,onInput:u[0]||=e=>r(`update:modelValue`,e),onSend:u[1]||=e=>r(`send`),onControl:u[2]||=e=>l(e)},null,8,[`text`,`placeholder`,`can-send`,`sending`,`running`,`stopping`,`now`,`touch`,`note`]))}}),ai=Bn.parse(`ses_page`),oi=Tn.parse(`act_page-agent`);function si(e,t){let n=`${e}/${t.name}`,r={...pr(Vn.parse(`run_${t.key}`),n,t.status),args:t.args};switch(t.status){case`running`:return r;case`done`:return{...r,outcome:{status:`done`,result:t.output??``}};case`failed`:return{...r,outcome:{status:`failed`,error:{class:`fatal`,code:`failed`,message:t.output===void 0||t.output.trim()===``?`It failed.`:t.output}}}}}function ci(e,t,n,r,i,a,o){return{id:Fn.parse(`msg_${e}`),session:ai,turn:on.parse(`trn_${e}`),author:t,role:n,parts:r===``?[]:[{type:`text`,text:r}],runs:[...a],status:o?`streaming`:`done`,replyAll:!1,answerers:[],createdAt:i??0}}function li(e,t){let n=[];return{segments:t.reduce((t,r)=>{if(r.kind!==`call`)return r.text.trim()===``?t:$e(t,{kind:r.kind,text:r.text});let i=si(e,r.call);return n.push(i),$e(t,{kind:`runs`,runs:[i.id]})},[]),runs:n}}function ui(e,t){let n=e.findLastIndex(e=>e.kind===`answer`);return e.map((e,r)=>{switch(e.kind){case`user`:return{kind:`user`,key:e.key,message:ci(e.key,t.me,`user`,e.text,e.at,[],!1)};case`note`:return{kind:`note`,key:e.key,message:ci(e.key,oi,`note`,e.text,void 0,[],!1)};case`answer`:{let{segments:i,runs:a}=li(t.system,e.pieces),o=e.pieces.flatMap(e=>e.kind===`text`?[e.text]:[]).join(``),s=t.streaming&&r===n;return{kind:`answer`,key:e.key,message:ci(e.key,oi,`assistant`,o,e.at,a.map(e=>e.id),s),segments:i,runs:a}}}})}var di={class:`conversation`,"data-testid":`conversation`},fi=Y(A({__name:`PageConversation`,props:{entries:{},agent:{},system:{},streaming:{type:Boolean,default:!1}},setup(e){let t=e,{session:n}=G(),r=nn(),i=k(()=>n.user.value?.id??oi),a=k(()=>ui(t.entries,{system:t.system,me:i.value,streaming:t.streaming})),o={context:[],fns:[]},s=I(new Set),c=e=>!s.value.has(e.id);function l(e){u([e],!s.value.has(e))}function u(e,t){let n=new Set(s.value);for(let r of e)t?n.add(r):n.delete(r);s.value=n}return(t,i)=>(j(),E(`div`,di,[(j(!0),E(M,null,D(a.value,t=>(j(),E(M,{key:t.key},[t.kind===`user`?(j(),F(rt,{key:0,message:t.message,mine:``,"author-name":C(n).user.value?.name??`You`,now:C(r),"command-name":e=>e,suggestions:o,actions:[]},null,8,[`message`,`author-name`,`now`,`command-name`])):t.kind===`note`?(j(),F(tt,{key:1,message:t.message},null,8,[`message`])):(j(),F(Xe,{key:2,messages:[t.message],"author-name":e.agent,now:C(r),streaming:t.message.status===`streaming`,failed:!1,"runs-of":()=>t.runs,"live-of":()=>t.segments,collapsed:c,"view-of":()=>void 0,"attachment-view":()=>void 0,actions:[],onRunOpen:i[0]||=e=>l(e),onRunToggle:i[1]||=(e,t)=>u([e],!t),onCollapseAll:e=>u(t.runs.map(e=>e.id),!e)},null,8,[`messages`,`author-name`,`now`,`streaming`,`runs-of`,`live-of`,`onCollapseAll`]))],64))),128))]))}}),[[`__scopeId`,`data-v-aa0c3db3`]]),pi={class:`fns`,"data-testid":`fns`},mi={key:1,class:`mark`,"aria-hidden":`true`},hi={class:`main`},gi={class:`top`},_i=[`onClick`],vi={class:`name`},yi=[`title`],bi={class:`description`},xi={class:`chips`},Si={class:`runs`},Ci={key:0,class:`dim detail`},wi={key:1,class:`dim`},Ti=Y(A({__name:`FnList`,props:{fns:{},now:{},runsOf:{type:Function},switchable:{type:Boolean}},emits:[`switch`,`switched`],setup(e,{emit:t}){let n=e,r=t,i=gr();i?.within({switched:(e,t)=>{r(`switched`,e,t)}});let a=k(()=>{let[e,...t]=n.fns;return e===void 0||t.length===0?{runtime:!1,tags:new Set}:{runtime:n.fns.every(e=>e.origin===`runtime`),tags:new Set(e.decl.tags.filter(e=>t.every(t=>t.decl.tags.includes(e))))}}),o=e=>xn(e.stats.outcomes);return(t,n)=>{let s=ye(`RouterLink`);return j(),E(`ul`,pi,[(j(!0),E(M,null,D(e.fns,t=>(j(),E(`li`,{key:t.name,class:w([`fn`,{off:t.available!==!0}])},[e.switchable?(j(),F(C(Ht),{key:0,class:`switch`,"model-value":!t.disabled,label:`Use ${C(J)(t.name)}`,"hide-label":``,"data-testid":`fn-switch`,"onUpdate:modelValue":e=>r(`switch`,t.name,e)},null,8,[`model-value`,`label`,`onUpdate:modelValue`])):(j(),E(`span`,mi,[b(C(Ft),{name:`fn`,size:16})])),T(`div`,hi,[T(`p`,gi,[T(`button`,{type:`button`,class:`label`,"data-testid":`fn-page`,onClick:e=>C(i)?.open(t.name)},P(C(J)(t.name)),9,_i),T(`code`,vi,P(t.name),1),T(`code`,{class:`name`,title:`Version ${t.version}`,"data-testid":`fn-version`},`v `+P(C(br)(t.version)),9,yi)]),T(`p`,bi,P(t.decl.description),1),T(`p`,xi,[t.available===!0?R(``,!0):(j(),F(C(V),{key:0,tone:`warn`,title:t.available.detail},{default:N(()=>[x(P(C(Sr)(t.available)),1)]),_:2},1032,[`title`])),t.paused?(j(),F(C(V),{key:1},{default:N(()=>[...n[0]||=[x(`Paused`,-1)]]),_:1})):R(``,!0),C(yr)(t.decl)?(j(),F(C(V),{key:2,tone:`warn`,title:C(xr),"data-testid":`fn-no-examples`},{default:N(()=>[...n[1]||=[x(`No examples`,-1)]]),_:1},8,[`title`])):R(``,!0),t.origin===`runtime`&&!a.value.runtime?(j(),F(C(V),{key:3,tone:`accent`},{default:N(()=>[...n[2]||=[x(`Added while running`,-1)]]),_:1})):R(``,!0),(j(!0),E(M,null,D(t.decl.tags.filter(e=>!a.value.tags.has(e)),e=>(j(),F(C(V),{key:e},{default:N(()=>[x(P(e),1)]),_:2},1024))),128))])]),b(s,{class:`stats`,to:e.runsOf(t.name),title:t.stats.lastRunAt===void 0?`Never run`:`Last run ${C(St)(t.stats.lastRunAt)}`},{default:N(()=>[T(`span`,Si,P(o(t).toLocaleString())+` `+P(o(t)===1?`run`:`runs`),1),o(t)>0?(j(),E(`span`,Ci,[x(P([C(Er)(t.stats.outcomes),C(Tr)(t.stats.outcomes),C(z)(t.stats.averageTime)].filter(e=>e!==``).join(` · `)),1),t.stats.p95===void 0?R(``,!0):(j(),E(M,{key:0},[x(` (p95 `+P(C(z)(t.stats.p95))+`)`,1)],64)),x(` · `+P(C(B)(t.stats.averageCost)),1)])):R(``,!0),t.stats.lastRunAt===void 0?R(``,!0):(j(),E(`span`,wi,`last `+P(C(Kt)(t.stats.lastRunAt,e.now)),1))]),_:2},1032,[`to`,`title`])],2))),128))])}}}),[[`__scopeId`,`data-v-45377503`]]),Ei=A({__name:`PageFnList`,props:{fns:{}},setup(e){let t=nn();return(n,r)=>(j(),F(Ti,{fns:e.fns,now:C(t),"runs-of":C(y).fnRuns},null,8,[`fns`,`now`,`runs-of`]))}}),Di=e=>e in Pt;function Oi(e){return e!==void 0&&Di(e)?e:`layers`}function ki(e){return e.filter(e=>e.nav===`main`&&e.area!==`admin`).map(e=>({system:e.system,segment:e.segment,title:e.title,icon:Oi(e.icon)}))}function Ai(e){let t=Un.safeParse(e.system),n=e.page;if(!t.success||typeof n!=`string`)return;let r=e.path,i=Array.isArray(r)?r:typeof r==`string`&&r!==``?[r]:[];return{system:t.data,page:n,path:i}}function ji(e){return Object.fromEntries(Object.entries(e).flatMap(([e,t])=>{let n=Array.isArray(t)?t[0]:t;return typeof n==`string`?[[e,n]]:[]}))}function Mi(e){return e.area??`app`}function Ni(e){if(`fn`in e)return y.fn(e.fn);if(`instance`in e){let t=Un.parse(e.instance.system);return y.instance(t,vn.parse(e.instance.instance))}return`connect`in e?y.connect(Un.parse(e.connect)):`resources`in e?y.resources({under:e.resources.under}):y.contextItem(e.context)}function Pi(e){let t=t=>{let n=e.here(),r=t.page??n.page,i=t.path??(r===n.page?n.path:[]);return y.systemPage(n.system,r,i,t.query??{},n.area)},n=(t,n)=>{let r=e.here();e.navigate(y.systemPage(r.system,r.page,r.path,{...r.query,...t},r.area),!n)};return{get user(){return e.user()},hub:e.hub,query:{get values(){return e.here().query},get:t=>e.here().query[t],set:(e,t)=>{n(e,t?.push===!0)},bind:(t,r=``)=>({get value(){return e.here().query[t]??r},set value(e){n({[t]:e===r?void 0:e},!1)}})},href:n=>e.resolve(t(n)),chatHref:t=>e.chatHref(t),goChat:t=>{e.goChat(t)},runHref:t=>e.runHref(t),goRun:t=>{e.goRun(t)},go:(n,r)=>{e.navigate(t(n),r?.replace===!0)},openChat:t=>e.openChat(t),components:e.components,runs:t=>e.runs(t),inbox:e.inbox,notify:e.notify,format:e.format,live:(t,n)=>{e.live(t,n)}}}function Fi(e){return{components:e.components,href:t=>e.resolve(Ni(t)),go:t=>{e.navigate(Ni(t),!1)},bytes:e.bytes}}function Ii(e,t){return t.some(t=>t.system===e.system)?{title:`No such page`,body:`${e.system} has no page called “${e.page}”. It may have been renamed in a newer version.`}:{title:`${e.system} isn’t installed`,body:`This page belongs to the ${e.system} system, which isn’t installed and live here, or you can’t use it. The link will work again once it is.`}}var Li=A({__name:`PageIconButton`,props:{icon:{},label:{},size:{default:`md`},disabled:{type:Boolean,default:!1}},emits:[`click`],setup(e){let t=e,n=k(()=>Oi(t.icon));return(t,r)=>(j(),F(C(Ct),{icon:n.value,label:e.label,size:e.size,disabled:e.disabled,onClick:r[0]||=e=>t.$emit(`click`,e)},null,8,[`icon`,`label`,`size`,`disabled`]))}}),Ri=Object.freeze({Frame:O(ze),Input:O(Rt),Markdown:O(Jt),Icon:O(Ft),Empty:O(At),LoadState:O(Re),Reasoning:O(Ze),Typing:O(Be),ResourceViewer:O(_t),ValueEditor:O(pt),Button:O(H),Select:O(zt),Textarea:O(Lt),Dialog:O(yt),Popover:O(Yt),Form:O(ft),Banner:O(Mt),Badge:O(V),Skeleton:O(Dt),FnPill:O(dt),Approval:O(ri),Conversation:O(fi),Composer:O(ii)}),zi=Object.freeze({Tabs:O(Wt),Segmented:O(Gt),Switch:O(Ht),ChipInput:O(wt),IconButton:O(Li),Card:O(kt),FnList:O(Ei),Facts:O(Le),Confirm:O(Ie)}),Bi=Object.freeze({cost:B,relativeTime:(e,t)=>Kt(e,t),fullTime:e=>St(e)}),Vi=e=>lt(e),Hi=[7,30,90];function Ui(e,t){let{system:n,local:r}=Jn(e);return t===0?`${n} has no fns on this hub now (it may be uninstalled or not connected yet), so ${e} can't be shown.`:`${n} has no fn named ${r} now. It may have been removed or renamed since it ran.`}var Wi=class{#e;#t;#n;name=I(void 0);days=I(7);record=new W;metrics=new W;daily=new W;recent=new W;switching=new U;constructor(e,t){this.#e=e,this.#t=t}async open(e,t){let n=this.name.value===e;n||this.close(),this.name.value=e,this.days.value=t,this.#n??=this.#t(e=>{this.#a(e)}),await Promise.all([this.#r(e,n),this.#i(e,t,n&&this.metrics.value.value!==void 0)])}async switchOn(e){let t=this.record.value.value;return t!==void 0&&(this.record.set({...t,disabled:!e}),(await this.switching.run(()=>this.#e.switchItem.call({section:`fns`,name:t.name,on:e}),`Couldn't switch that.`)).ok?!0:(this.record.set(t),!1))}close(){this.#n?.(),this.#n=void 0,this.name.value=void 0,this.record.reset(),this.metrics.reset(),this.daily.reset(),this.recent.reset()}async#r(e,t){let n=Un.parse(Jn(e).system);await this.record.load(async()=>{let t=await this.#e.systemFns.call({system:n}),r=t.find(t=>t.name===e);if(r===void 0)throw new Ir(Ui(e,t.length));return r},`Couldn't load this fn.`,t)}async#i(e,t,n){await Promise.all([this.metrics.load(async()=>(await this.#e.fnMetrics.call({fn:e,days:t})).find(t=>t.fn===e),`Couldn't load this fn's metrics.`,n),this.daily.load(()=>this.#e.fnMetricsDays.call({fn:e,days:t}),`Couldn't load this fn's days.`,n),this.recent.load(async()=>(await this.#e.runs.call({query:{filters:[{field:`fn`,op:`is`,value:e}],limit:8}})).items,`Couldn't load this fn's runs.`,n)])}#a(e){let t=this.name.value;if(e.type!==`fn`||t===void 0||e.fn!==t)return;let n=this.record.value.value;n!==void 0&&this.record.set({...n,stats:e.stats}),this.#i(t,this.days.value,!0)}},Gi=[`data-testid`],Ki={class:`title`},qi=[`aria-label`],Ji={class:`scale top`},Yi={class:`columns`},Xi=[`aria-label`,`data-day`,`onPointerenter`,`onFocus`],Zi={class:`labels`,"aria-hidden":`true`},Qi={class:`table`},$i=Y(A({__name:`DayBars`,props:{title:{},bars:{},format:{},testid:{default:`day-bars`}},setup(e){let t=e,n=k(()=>wr(Math.max(0,...t.bars.map(e=>e.value)))),r=I(void 0),i=k(()=>Math.max(1,Math.ceil(t.bars.length/7))),a=k(()=>r.value===void 0?void 0:t.bars[r.value]);return(t,o)=>(j(),E(`figure`,{class:`day-bars`,"data-testid":e.testid},[T(`figcaption`,Ki,P(e.title),1),T(`div`,{class:`plot`,role:`img`,"aria-label":`${e.title}: ${e.bars.map(t=>`${t.label} ${e.format(t.value)}`).join(`, `)}`,onPointerleave:o[1]||=e=>r.value=void 0},[T(`span`,Ji,P(e.format(n.value)),1),o[2]||=T(`span`,{class:`scale zero`},`0`,-1),o[3]||=T(`div`,{class:`grid`,"aria-hidden":`true`},null,-1),T(`div`,Yi,[(j(!0),E(M,null,D(e.bars,(e,t)=>(j(),E(`button`,{key:e.day,type:`button`,class:w([`column`,{pointed:r.value===t}]),"aria-label":`${e.label}: ${e.lines.join(`, `)}`,"data-day":e.day,onPointerenter:e=>r.value=t,onFocus:e=>r.value=t,onBlur:o[0]||=e=>r.value=void 0},[T(`span`,{class:`bar`,style:Ce({height:`${e.value<=0?0:Math.max(2,e.value/n.value*100)}%`})},null,4)],42,Xi))),128))]),a.value&&r.value!==void 0?(j(),E(`div`,{key:0,class:`tip`,role:`status`,style:Ce({left:`${Math.min(80,Math.max(20,(r.value+.5)/e.bars.length*100))}%`})},[T(`strong`,null,P(a.value.label),1),(j(!0),E(M,null,D(a.value.lines,e=>(j(),E(`span`,{key:e},P(e),1))),128))],4)):R(``,!0)],40,qi),T(`div`,Zi,[(j(!0),E(M,null,D(e.bars,(e,t)=>(j(),E(`span`,{key:e.day,class:`label`},P(t%i.value===0?e.label:``),1))),128))]),T(`details`,Qi,[o[5]||=T(`summary`,null,`As a table`,-1),T(`table`,null,[T(`thead`,null,[T(`tr`,null,[o[4]||=T(`th`,null,`Day`,-1),T(`th`,null,P(e.title),1)])]),T(`tbody`,null,[(j(!0),E(M,null,D(e.bars,e=>(j(),E(`tr`,{key:e.day},[T(`td`,null,P(e.label),1),T(`td`,null,P(e.lines.join(` · `)),1)]))),128))])])])],8,Gi))}}),[[`__scopeId`,`data-v-94fb9c63`]]),ea={class:`stats`,"data-testid":`fn-stats`},ta={class:`period`},na={class:`period-title`},ra={key:0,class:`strip`,"data-testid":`fn-metrics`},ia=[`data-figure`],aa={class:`label`},oa={class:`value`},sa={key:0,class:`detail`},ca=Y(A({__name:`FnStats`,props:ge({metrics:{},daily:{},loading:{type:Boolean},problem:{},now:{},compact:{type:Boolean}},{days:{required:!0},daysModifiers:{}}),emits:ge([`retry`],[`update:days`]),setup(e,{emit:t}){let n=e,r=_e(e,`days`),i=t,a=Hi.map(e=>({value:String(e),label:`${String(e)} days`})),o=k({get:()=>String(r.value),set:e=>{r.value=Hi.find(t=>String(t)===e)??7}}),s=k(()=>n.metrics===void 0?[]:Dr(n.metrics)),c=k(()=>({period:r.value,now:n.now})),l=k(()=>Or(n.daily,`runs`,c.value)),u=k(()=>Or(n.daily,`time`,c.value));return(t,n)=>(j(),E(`section`,ea,[T(`div`,ta,[T(`h2`,na,`Over the last `+P(r.value)+` days`,1),b(C(Gt),{modelValue:o.value,"onUpdate:modelValue":n[0]||=e=>o.value=e,options:C(a),label:`Period`,"data-testid":`fn-period`},null,8,[`modelValue`,`options`])]),b(Re,{loading:e.loading,problem:e.problem,ready:e.metrics!==void 0||!e.loading,empty:!1,onRetry:n[1]||=e=>i(`retry`)},{default:N(()=>[e.metrics?(j(),E(`ul`,ra,[(j(!0),E(M,null,D(s.value,e=>(j(),E(`li`,{key:e.key,class:`figure`,"data-figure":e.key},[T(`span`,aa,P(e.label),1),T(`span`,oa,P(e.value),1),e.detail?(j(),E(`span`,sa,P(e.detail),1)):R(``,!0)],8,ia))),128))])):(j(),F(C(At),{key:1,icon:`fn`,title:`No runs in this period`,body:`Its numbers show here once it runs.`})),l.value.length>0?(j(),E(`div`,{key:2,class:w([`charts`,{compact:e.compact}])},[b(C(kt),null,{default:N(()=>[b($i,{title:`Runs per day`,bars:l.value,format:e=>e.toLocaleString(),testid:`fn-runs-chart`},null,8,[`bars`,`format`])]),_:1}),b(C(kt),null,{default:N(()=>[b($i,{title:`Typical time per day`,bars:u.value,format:C(z),testid:`fn-time-chart`},null,8,[`bars`,`format`])]),_:1})],2)):R(``,!0)]),_:1},8,[`loading`,`problem`,`ready`])]))}}),[[`__scopeId`,`data-v-3e1752f2`]]),la={key:0,class:`problem`},ua={key:2,class:`note`,"data-testid":`access-fixed`},da={key:3,class:`problem`,role:`alert`},fa=Y(A({__name:`AccessControl`,props:{target:{},label:{default:`Who can use it`},title:{default:`Sharing`},compact:{type:Boolean,default:!1},fixed:{default:void 0}},setup(e){let t=e,n=rn(),r=n?.chat.access,i=Lr().people(),a=L(void 0),o=k(()=>r?.multiUser.value===!0);Se(()=>{r?.load()}),S([()=>Ln(t.target),o],([,e])=>{a.value=e&&r!==void 0?r.view(t.target):void 0},{immediate:!0});let s=k(()=>a.value?.value.value?.sharing.owner),c=L(``);S(s,async e=>{if(c.value=``,e===void 0||e===n?.session.user.value?.id)return;let[t]=await i.label([e]).catch(()=>[]);s.value===e&&(c.value=t===void 0||t.missing===!0?`its owner`:t.label)},{immediate:!0});let l=k({get:()=>{if(t.fixed!==void 0)return{visibility:`private`,with:[]};let e=a.value?.value.value?.sharing;return e===void 0?void 0:{visibility:e.visibility,with:e.with}},set:e=>{e!==void 0&&u(e)}});async function u(e){if(r===void 0||a.value===void 0)return;let n=await r.set(t.target,e);n.ok&&a.value.set(n.value)}return(t,n)=>o.value&&a.value!==void 0?(j(),F(kt,{key:0,title:e.title,compact:e.compact,"data-testid":`access-control`},{default:N(()=>[a.value.problem.value===``?l.value===void 0?R(``,!0):(j(),F(qt,{key:1,modelValue:l.value,"onUpdate:modelValue":n[0]||=e=>l.value=e,people:C(i),label:e.label,owner:c.value,readonly:e.fixed!==void 0||a.value.value.value?.editable===!1},null,8,[`modelValue`,`people`,`label`,`owner`,`readonly`])):(j(),E(`p`,la,P(a.value.problem.value),1)),e.fixed===void 0?R(``,!0):(j(),E(`p`,ua,P(e.fixed),1)),C(r)?.saving.problem.value?(j(),E(`p`,da,P(C(r).saving.problem.value),1)):R(``,!0)]),_:1},8,[`title`,`compact`])):R(``,!0)}}),[[`__scopeId`,`data-v-9e92a917`]]);async function pa(e,t){let n=await e.chat.sessions.create({title:t.title});if(n===void 0)throw Error(e.chat.sessions.problem.value||`Couldn't start a chat.`);if(t.run!==void 0){let r=e.chat.thread(n);if(await r.invoke(t.run.fn,t.run.args)===void 0)throw Error(r.problem.value||`Couldn't run that.`)}return await e.push(y.session(n)),n}function ma(){let{chat:e,toasts:t}=G(),n=ie(),r=I(``);async function i(i){r.value=i;try{await pa({chat:e,push:e=>n.push(e)},{title:J(i),run:{fn:i,args:{}}})}catch(e){t.error(`Couldn't open it in a chat`,e instanceof Error?e.message:String(e))}finally{r.value=``}}return{opening:r,open:i}}var ha={read:{label:`Reads`,about:`Only reads: nothing is changed.`},write:{label:`Writes`,about:`Adds or changes things.`},delete:{label:`Deletes`,about:`Can remove things.`}},ga={read:`neutral`,write:`warn`,delete:`danger`},_a={free:`Spends nothing`,history:`From its runs`,payload:`From the call and the model’s price`,unknown:`Spends, never run yet`};function va(e){return e.basis===`free`?`Free`:e.basis===`unknown`?`Unknown`:e.min===e.max?B(e.typical):`${B(e.typical)} (${B(e.min)}–${B(e.max)})`}function ya(e){let t=[{key:`cost`,label:`Cost a call`,value:va(e.cost),detail:_a[e.cost.basis]}],n=e.times;return n!==void 0&&n.runs>0&&t.push({key:`time`,label:`Typical time`,value:z(n.typical),detail:`The median run`},{key:`slow`,label:`Slow runs`,value:z(n.slow),detail:`Longest ${z(n.longest)}`}),t.push({key:`runs`,label:`Runs`,value:(n?.runs??e.cost.runs).toLocaleString(),detail:`Settled, all time`}),t}function ba(e){let t=JSON.stringify(e);return t.length<=80?t:JSON.stringify(e,null,2)}function xa(e,t){return`${e}(${ba(t.args)})`}var Sa=Xn([`readable`,`stored`]);function Ca(e,t,n){return t!==void 0&&n===`readable`?t:e===void 0?void 0:{language:`json`,code:JSON.stringify(e,null,2)}}var wa=[`data-fn`],Ta={class:`about`},Ea={key:0,class:`description`},Da={class:`badges`},Oa={key:1,class:`signature`,"data-testid":`fn-signature`},ka={key:2,class:`dim`},Aa={key:3,class:`strip`,"data-testid":`fn-facts`},ja=[`data-figure`],Ma={class:`label`},Na={class:`value`},Pa={class:`detail`},Fa={key:4,class:`uses`,"data-testid":`fn-uses`},Ia={class:`examples`,"data-testid":`fn-examples`},La={class:`heading`},Ra={key:0,class:`dim`},za={key:0,class:`bad`,role:`alert`},Ba={key:1,class:`dim`},Va={key:3,class:`example-list`},Ha={key:0,class:`note`},Ua={class:`code`},Wa={key:1,class:`code result`},Ga=Y(A({__name:`FnOverview`,props:{name:{},about:{},facts:{},loading:{type:Boolean},problem:{default:``},examples:{},examplesTotal:{},moreExamples:{type:Boolean},examplesLoading:{type:Boolean},examplesProblem:{default:``},describe:{type:Boolean,default:!0}},emits:[`more`,`retry`],setup(e,{emit:t}){let n=e,r=t,i=k(()=>ct(n.name)),a=k(()=>n.facts===void 0?[]:ya(n.facts)),o=k(()=>n.facts?.mode??n.about?.mode),s=k(()=>(n.facts?.uses??[]).filter(e=>e!==n.name)),c=k(()=>{let e=n.facts?.kind;return e!==void 0&&!rr(e)?`its kind (${e}) works one out when the hub describes it.`:"its author adds them to its declaration (`examples`)."});return(t,n)=>(j(),E(`div`,{class:`fn-overview`,"data-testid":`fn-overview`,"data-fn":e.name},[e.problem===``?e.loading&&e.facts===void 0?(j(),F(C(Dt),{key:1,lines:4})):R(``,!0):(j(),F(C(Mt),{key:0,tone:`danger`},{actions:N(()=>[b(C(H),{size:`sm`,variant:`ghost`,onClick:n[0]||=e=>r(`retry`)},{default:N(()=>[...n[2]||=[x(`Retry`,-1)]]),_:1})]),default:N(()=>[x(P(e.problem)+` `,1)]),_:1})),T(`section`,Ta,[e.describe&&e.about?.description?(j(),E(`p`,Ea,P(e.about.description),1)):R(``,!0),T(`div`,Da,[o.value?(j(),F(C(V),{key:0,tone:C(ga)[o.value],title:C(ha)[o.value].about,"data-testid":`fn-mode`},{default:N(()=>[x(P(C(ha)[o.value].label),1)]),_:1},8,[`tone`,`title`])):R(``,!0),e.facts?.free?(j(),F(C(V),{key:1,tone:`ok`},{default:N(()=>[...n[3]||=[x(`Free`,-1)]]),_:1})):R(``,!0),e.facts?.kind&&e.facts.kind!==`native`?(j(),F(C(V),{key:2},{default:N(()=>[x(P(e.facts.kind),1)]),_:1})):R(``,!0),e.about?.instance?(j(),F(C(V),{key:3},{default:N(()=>[x(P(e.about.instance),1)]),_:1})):R(``,!0),e.about&&!e.about.available?(j(),F(C(V),{key:4,tone:`warn`,title:e.about.blocked?.reason},{default:N(()=>[...n[4]||=[x(`Not available now`,-1)]]),_:1},8,[`title`])):R(``,!0),Me(t.$slots,`badges`,{},void 0,!0)]),e.about?.signature?(j(),E(`code`,Oa,P(e.about.signature),1)):R(``,!0),e.about&&!e.about.available&&e.about.blocked?(j(),E(`p`,ka,P(e.about.blocked.reason),1)):R(``,!0)]),e.facts?.notice?(j(),F(C(Mt),{key:2,tone:`neutral`,"data-testid":`fn-notice`},{default:N(()=>[x(P(e.facts.notice),1)]),_:1})):R(``,!0),a.value.length>0?(j(),E(`ul`,Aa,[(j(!0),E(M,null,D(a.value,e=>(j(),E(`li`,{key:e.key,class:`figure`,"data-figure":e.key},[T(`span`,Ma,P(e.label),1),T(`span`,Na,P(e.value),1),T(`span`,Pa,P(e.detail),1)],8,ja))),128))])):R(``,!0),e.facts&&(e.facts.reads.length>0||e.facts.writes.length>0||s.value.length>0)?(j(),E(`dl`,Fa,[e.facts.reads.length>0?(j(),E(M,{key:0},[n[5]||=T(`dt`,null,`Reads`,-1),T(`dd`,null,[(j(!0),E(M,null,D(e.facts.reads,e=>(j(),E(`code`,{key:e,class:`chip`},P(e),1))),128))])],64)):R(``,!0),e.facts.writes.length>0?(j(),E(M,{key:1},[n[6]||=T(`dt`,null,`Writes`,-1),T(`dd`,null,[(j(!0),E(M,null,D(e.facts.writes,e=>(j(),E(`code`,{key:e,class:`chip write`},P(e),1))),128))])],64)):R(``,!0),s.value.length>0?(j(),E(M,{key:2},[n[7]||=T(`dt`,null,`Uses`,-1),T(`dd`,null,[(j(!0),E(M,null,D(s.value,e=>(j(),F(dt,{key:e,name:e},null,8,[`name`]))),128))])],64)):R(``,!0)])):R(``,!0),T(`section`,Ia,[T(`h3`,La,[n[8]||=x(`Examples`,-1),e.examplesTotal>0?(j(),E(`span`,Ra,` · `+P(e.examplesTotal),1)):R(``,!0)]),e.examplesProblem===``?e.examples.length===0&&e.examplesLoading?(j(),E(`p`,Ba,`Loading…`)):e.examples.length===0?(j(),F(C(Mt),{key:2,tone:`warn`,"data-testid":`fn-no-examples`},{default:N(()=>[x(` No examples. Every fn needs at least one: `+P(c.value),1)]),_:1})):(j(),E(`ol`,Va,[(j(!0),E(M,null,D(e.examples,e=>(j(),E(`li`,{key:e.id,class:`example`},[e.note?(j(),E(`p`,Ha,P(e.note),1)):R(``,!0),T(`pre`,Ua,P(C(xa)(i.value,e)),1),e.result===void 0?R(``,!0):(j(),E(`pre`,Wa,[n[9]||=T(`span`,{class:`arrow`},`→ `,-1),x(P(C(ba)(e.result)),1)]))]))),128))])):(j(),E(`p`,za,P(e.examplesProblem),1)),e.moreExamples?(j(),F(C(H),{key:4,size:`sm`,variant:`ghost`,loading:e.examplesLoading,"data-testid":`fn-more-examples`,onClick:n[1]||=e=>r(`more`)},{default:N(()=>[x(` More examples (`+P(e.examplesTotal-e.examples.length)+` left) `,1)]),_:1},8,[`loading`])):R(``,!0)]),Me(t.$slots,`runs`,{},void 0,!0)],8,wa))}}),[[`__scopeId`,`data-v-e343e112`]]),Ka=A({__name:`FnPayload`,props:ge({payload:{},readable:{},maxHeight:{default:360}},{form:{default:`readable`},formModifiers:{}}),emits:[`update:form`],setup(e){let t=e,n=_e(e,`form`),r=k(()=>[{value:`readable`,label:t.readable?.language.toUpperCase()??`Readable`},{value:`stored`,label:`Stored form`}]),i=k(()=>Ca(t.payload,t.readable,n.value));return(t,a)=>i.value?(j(),F(C(kt),{key:0,title:`What it runs`,"data-testid":`fn-payload`},Ae({default:N(()=>[b(C(Tt),{code:i.value.code,language:i.value.language,wrap:``,"max-height":e.maxHeight},null,8,[`code`,`language`,`max-height`])]),_:2},[e.readable?{name:`actions`,fn:N(()=>[b(C(Gt),{modelValue:n.value,"onUpdate:modelValue":a[0]||=e=>n.value=e,options:r.value,label:`Show it as`,"data-testid":`fn-payload-form`},null,8,[`modelValue`,`options`])]),key:`0`}:void 0]),1024)):R(``,!0)}}),qa=[`aria-current`,`data-testid`],Ja={key:0,class:`mark`},Ya={class:`main`},Xa={class:`top`},Za={class:`title`},Qa={key:0,class:`badges`},$a={key:0,class:`detail`},eo={key:1,class:`figures`},to=[`datetime`,`title`],no=Y(A({__name:`BrowserRow`,props:{title:{},detail:{default:``},at:{default:void 0},now:{},selected:{type:Boolean,default:!1},testid:{default:``}},emits:[`open`],setup(e,{emit:t}){let n=t,r=ve();return(t,i)=>(j(),E(`li`,{class:w([`browser-row`,{selected:e.selected}])},[T(`button`,{type:`button`,class:`open`,"aria-current":e.selected?`true`:void 0,"data-testid":e.testid||void 0,onClick:i[0]||=e=>n(`open`)},[r.mark?(j(),E(`span`,Ja,[Me(t.$slots,`mark`)])):R(``,!0),T(`span`,Ya,[T(`span`,Xa,[T(`span`,Za,P(e.title),1),r.badges?(j(),E(`span`,Qa,[Me(t.$slots,`badges`)])):R(``,!0)]),e.detail===``?R(``,!0):(j(),E(`span`,$a,P(e.detail),1))]),r.figures?(j(),E(`span`,eo,[Me(t.$slots,`figures`)])):R(``,!0),e.at===void 0?R(``,!0):(j(),E(`time`,{key:2,class:`at`,datetime:new Date(e.at).toISOString(),title:C(St)(e.at)},P(C(Kt)(e.at,e.now)),9,to))],8,qa)],2))}}),[[`__scopeId`,`data-v-1a21ed96`]]),ro={key:0,class:`none bad`,role:`alert`},io={key:1,class:`none`},ao={key:2,class:`list`},oo={key:0},so=Y(A({__name:`FnRuns`,props:{runs:{},now:{},title:{},loading:{type:Boolean,default:!1},problem:{default:``},empty:{default:`No runs yet.`}},emits:[`open`],setup(e,{emit:t}){let n=t,r=ve();return(t,i)=>(j(),F(C(kt),{class:`runs`,title:e.title,flush:``,compact:``,"data-testid":`fn-recent`},Ae({default:N(()=>[e.problem===``?e.runs.length===0?(j(),E(`p`,io,P(e.loading?`Loading…`:e.empty),1)):(j(),E(`ul`,ao,[(j(!0),E(M,null,D(e.runs,t=>(j(),F(no,{key:t.id,title:C(Mn)(t.args)||C(J)(t.fn),at:t.createdAt,now:e.now,testid:`fn-run-${t.id}`,onOpen:e=>n(`open`,t.id)},{mark:N(()=>[b(zr,{status:t.status,size:10},null,8,[`status`])]),badges:N(()=>[t.status===`failed`||t.status===`awaiting-approval`?(j(),F(C(V),{key:0,tone:C(fr)[t.status].tone},{default:N(()=>[x(P(C(fr)[t.status].word),1)]),_:2},1032,[`tone`])):R(``,!0),t.attempt>1?(j(),F(C(V),{key:1,tone:`warn`},{default:N(()=>[x(`Try `+P(t.attempt),1)]),_:2},1024)):R(``,!0)]),figures:N(()=>[T(`span`,null,P(C(B)(t.totalCost)),1),C(mr)(t,e.now)===void 0?R(``,!0):(j(),E(`span`,oo,P(C(z)(C(mr)(t,e.now)??0)),1))]),_:2},1032,[`title`,`at`,`now`,`testid`,`onOpen`]))),128))])):(j(),E(`p`,ro,P(e.problem),1))]),_:2},[r.actions?{name:`actions`,fn:N(()=>[Me(t.$slots,`actions`,{},void 0,!0)]),key:`0`}:void 0]),1032,[`title`]))}}),[[`__scopeId`,`data-v-dc316a5b`]]),co=A({__name:`FnDetails`,props:ge({name:{},describe:{type:Boolean,default:!0},compact:{type:Boolean,default:!1}},{days:{required:!0},daysModifiers:{},form:{default:`readable`},formModifiers:{},tab:{default:`about`},tabModifiers:{}}),emits:ge([`run`,`runs`,`switched`],[`update:days`,`update:form`,`update:tab`]),setup(e,{emit:t}){let n=e,r=_e(e,`days`),i=_e(e,`form`),a=_e(e,`tab`),o=t,s=ve(),{admin:c,chat:l,fns:u,toasts:d}=G(),f=c.fn,p=nn(3e4),m=k(()=>{let e=f.record.value.value;return e?.name===n.name?e:void 0}),h=k(()=>f.recent.value.value??[]),g=k(()=>{let e=m.value?.decl.kind;return e!==void 0&&e!==`native`&&l.renderers.drawsKind(e)}),_=k(()=>g.value?h.value.find(e=>e.outcome?.status===`done`):void 0),ee=k(()=>_.value===void 0?void 0:l.renderers.storedResultView(_.value,J(n.name))),{opening:te,open:ne}=ma(),re=k(()=>m.value?.decl.kind===Nr),v=c.injected,ie=k(()=>v.page.value.value?.injections??[]),ae=k(()=>jr(re.value,v.page.value.value===void 0?void 0:ie.value.length)),oe=k(()=>re.value?a.value:`about`);async function se(e,t){await v.switchOn(e,t)||d.error(v.saving.problem.value)}async function ce(e,t){await v.reorder(e,t)||d.error(v.saving.problem.value)}async function le(e){let t=m.value?.name;t!==void 0&&(await f.switchOn(e)?o(`switched`,t,e):d.error(f.switching.problem.value))}return S(()=>[n.name,r.value],([e,t])=>{f.open(e,t)},{immediate:!0}),S(()=>n.name,e=>{u.open(e)},{immediate:!0}),S(()=>[n.name,re.value],([e,t])=>{t?v.open({agent:e}):v.close()},{immediate:!0}),De(()=>{f.close(),u.close(),v.close()}),(t,n)=>(j(),F(Re,{class:`fn-details`,loading:C(f).record.loading.value,problem:C(f).record.problem.value,ready:m.value!==void 0,empty:!1,lines:6,"data-testid":`fn-details`,onRetry:n[10]||=t=>C(f).open(e.name,r.value)},{default:N(()=>[m.value?(j(),E(M,{key:0},[re.value?(j(),F(C(Wt),{key:0,modelValue:a.value,"onUpdate:modelValue":n[0]||=e=>a.value=e,tabs:ae.value,label:`Fn`,"data-testid":`fn-tabs`},null,8,[`modelValue`,`tabs`])):R(``,!0),oe.value===`injected`?(j(),F(Pr,{key:1,per:`agent`,views:ie.value,loading:C(v).page.loading.value,problem:C(v).page.problem.value,busy:C(v).busyKey.value,now:C(p),"data-testid":`fn-injected`,onSwitch:se,onReorder:ce,onRetry:n[1]||=e=>C(v).refresh()},null,8,[`views`,`loading`,`problem`,`busy`,`now`])):(j(),E(M,{key:2},[g.value?(j(),F(C(kt),{key:0,title:`Latest result`,"data-testid":`fn-widget`},{actions:N(()=>[b(C(H),{size:`sm`,icon:`play`,loading:C(te)===e.name,"data-testid":`fn-widget-open`,onClick:n[2]||=t=>C(ne)(e.name)},{default:N(()=>[...n[11]||=[x(`Open in chat`,-1)]]),_:1},8,[`loading`])]),default:N(()=>[ee.value&&_.value?(j(),F(Rr,{key:_.value.id,view:ee.value,label:C(J)(e.name)},null,8,[`view`,`label`])):(j(),F(C(At),{key:1,icon:`grid`,title:`Not run yet`,body:`Open it in a chat to run it; its latest run shows here.`}))]),_:1})):R(``,!0),b(Ga,{name:e.name,about:C(u).about.value.value,facts:C(u).facts.value.value,loading:C(u).facts.loading.value,problem:C(u).facts.problem.value,describe:e.describe,examples:C(u).examples.value,"examples-total":C(u).examplesTotal.value,"more-examples":C(u).examplesNext.value!==void 0,"examples-loading":C(u).examplesLoading.value,"examples-problem":C(u).examplesProblem.value,onMore:n[3]||=e=>C(u).moreExamples(),onRetry:n[4]||=t=>C(u).open(e.name)},Ae({badges:N(()=>[b(C(Ht),{"model-value":!m.value.disabled,label:`In use`,disabled:C(f).switching.busy.value,"data-testid":`fn-on`,"onUpdate:modelValue":le},null,8,[`model-value`,`disabled`]),m.value.paused?(j(),F(C(V),{key:0},{default:N(()=>[...n[12]||=[x(`Paused`,-1)]]),_:1})):R(``,!0),(j(!0),E(M,null,D(m.value.decl.tags,e=>(j(),F(C(V),{key:e},{default:N(()=>[x(P(e),1)]),_:2},1024))),128))]),_:2},[s.runs?{name:`runs`,fn:N(()=>[Me(t.$slots,`runs`)]),key:`0`}:void 0]),1032,[`name`,`about`,`facts`,`loading`,`problem`,`describe`,`examples`,`examples-total`,`more-examples`,`examples-loading`,`examples-problem`]),b(ca,{days:r.value,"onUpdate:days":n[5]||=e=>r.value=e,metrics:C(f).metrics.value.value,daily:C(f).daily.value.value??[],loading:C(f).metrics.loading.value,problem:C(f).metrics.problem.value||C(f).daily.problem.value,now:C(p),compact:e.compact,onRetry:n[6]||=t=>C(f).open(e.name,r.value)},null,8,[`days`,`metrics`,`daily`,`loading`,`problem`,`now`,`compact`]),b(Ka,{form:i.value,"onUpdate:form":n[7]||=e=>i.value=e,payload:m.value.decl.payload,readable:m.value.decl.readable,"max-height":e.compact?240:360},null,8,[`form`,`payload`,`readable`,`max-height`]),b(fa,{target:{kind:`fn`,fn:e.name}},null,8,[`target`]),b(Ar,{item:{system:m.value.system,section:`fns`,name:e.name}},null,8,[`item`]),b(so,{runs:h.value,now:C(p),title:`Latest runs`,loading:C(f).recent.loading.value,problem:C(f).recent.problem.value,onOpen:n[9]||=e=>o(`run`,e)},{actions:N(()=>[b(C(H),{size:`sm`,variant:`ghost`,icon:`arrow-right`,"data-testid":`fn-runs`,onClick:n[8]||=t=>o(`runs`,e.name)},{default:N(()=>[...n[13]||=[x(`All its runs`,-1)]]),_:1})]),_:1},8,[`runs`,`now`,`loading`,`problem`])],64))],64)):R(``,!0)]),_:3},8,[`loading`,`problem`,`ready`]))}}),lo=A({__name:`FnModal`,props:{modal:{},fn:{}},setup(e){let t=e,{fns:n,session:r}=G(),i=ie(),a=u(),o=k({get:()=>{let e=le.safeParse(a.query[_r]);return e.success?e.data:`about`},set:e=>{let t={...a.query};e===`about`?Reflect.deleteProperty(t,_r):t[_r]=e,i.replace({query:t,hash:a.hash})}}),s=k(()=>r.user.value?.role===`admin`),c=I(7),l=I(`readable`),d=nn(3e4),f=k({get:()=>!0,set:e=>{e||t.modal.close()}}),p=k(()=>[...(t.modal.scope.value.runs?.()??[]).filter(e=>e.fn===t.fn)].reverse());S([()=>t.fn,s],([e,t])=>{t||n.open(e)},{immediate:!0}),De(()=>{s.value||n.close()});function m(e){i.push(e)}return(t,r)=>(j(),F(C(yt),{open:f.value,"onUpdate:open":r[12]||=e=>f.value=e,title:C(J)(e.fn),description:e.fn,width:`720px`},{footer:N(()=>[b(C(H),{variant:`ghost`,onClick:r[10]||=t=>e.modal.close()},{default:N(()=>[...r[13]||=[x(`Close`,-1)]]),_:1}),s.value?(j(),F(C(H),{key:0,variant:`secondary`,icon:`arrow-right`,"data-testid":`fn-open-page`,onClick:r[11]||=t=>m(C(y).fn(e.fn,o.value===`about`?{}:{tab:o.value}))},{default:N(()=>[...r[14]||=[x(`Open page`,-1)]]),_:1})):R(``,!0)]),default:N(()=>[s.value?(j(),F(co,{key:0,days:c.value,"onUpdate:days":r[1]||=e=>c.value=e,form:l.value,"onUpdate:form":r[2]||=e=>l.value=e,tab:o.value,"onUpdate:tab":r[3]||=e=>o.value=e,name:e.fn,compact:``,onRun:r[4]||=t=>e.modal.openRun(t),onRuns:r[5]||=e=>m(C(y).fnRuns(e)),onSwitched:r[6]||=(t,n)=>e.modal.scope.value.switched?.(t,n)},Ae({_:2},[p.value.length>0?{name:`runs`,fn:N(()=>[b(so,{runs:p.value,now:C(d),title:`Its runs here`,onOpen:r[0]||=t=>e.modal.openRun(t)},null,8,[`runs`,`now`])]),key:`0`}:void 0]),1032,[`days`,`form`,`tab`,`name`])):(j(),F(Ga,{key:1,name:e.fn,about:C(n).about.value.value,facts:C(n).facts.value.value,loading:C(n).facts.loading.value,problem:C(n).facts.problem.value,examples:C(n).examples.value,"examples-total":C(n).examplesTotal.value,"more-examples":C(n).examplesNext.value!==void 0,"examples-loading":C(n).examplesLoading.value,"examples-problem":C(n).examplesProblem.value,onMore:r[8]||=e=>C(n).moreExamples(),onRetry:r[9]||=t=>C(n).open(e.fn)},Ae({_:2},[p.value.length>0?{name:`runs`,fn:N(()=>[b(so,{runs:p.value,now:C(d),title:`Its runs here`,onOpen:r[7]||=t=>e.modal.openRun(t)},null,8,[`runs`,`now`])]),key:`0`}:void 0]),1032,[`name`,`about`,`facts`,`loading`,`problem`,`examples`,`examples-total`,`more-examples`,`examples-loading`,`examples-problem`]))]),_:1},8,[`open`,`title`,`description`]))}}),uo={"approval-needed":{icon:`shield`,tone:`warn`,label:`Approval needed`},"input-needed":{icon:`edit`,tone:`warn`,label:`Input needed`},"config-needed":{icon:`settings`,tone:`warn`,label:`Setup needed`},message:{icon:`chat`,tone:`accent`,label:`Message`},replied:{icon:`chat`,tone:`accent`,label:`Reply`},"turn-finished":{icon:`success`,tone:`ok`,label:`Finished`},"turn-failed":{icon:`error`,tone:`danger`,label:`Failed`},"pairing-requested":{icon:`key`,tone:`accent`,label:`Pairing`},"system-disconnected":{icon:`offline`,tone:`danger`,label:`Disconnected`},"spend-limit":{icon:`warning`,tone:`danger`,label:`Spend limit`},"system-paused":{icon:`pause`,tone:`danger`,label:`System paused`},"system-notice":{icon:`warning`,tone:`warn`,label:`System notice`},"system-message":{icon:`info`,tone:`neutral`,label:`Update`}},fo={ok:{icon:`success`,tone:`ok`,label:`Went well`},failed:{icon:`error`,tone:`danger`,label:`Failed`}};function po(e){let t=uo[e.reason],n=e.tone===void 0||e.tone===`info`?t:{...fo[e.tone],label:t.label};return e.resolved===void 0?n:{icon:`check`,tone:`neutral`,label:`${n.label} · ${e.resolved}`}}var mo=[`data-testid`],ho={class:`text`},go={class:`top`},_o={class:`title`},vo=[`datetime`,`title`],yo={key:0,class:`body`},bo={key:0,class:`dot`,"aria-hidden":`true`},xo={key:1,class:`sr-only`},So={class:`side`},Co=Y(A({__name:`NotificationRow`,props:{notification:{},now:{},compact:{type:Boolean,default:!1}},emits:[`open`,`also`,`read`],setup(e){let t=e,n=k(()=>po(t.notification));return(t,r)=>(j(),E(`li`,{class:w([`row`,{unread:!e.notification.read,resolved:e.notification.resolved!==void 0,compact:e.compact}]),"data-testid":`notification-${e.notification.id}`},[T(`button`,{type:`button`,class:`open`,onClick:r[0]||=n=>t.$emit(`open`,e.notification)},[T(`span`,{class:w([`mark`,`tone-${n.value.tone}`])},[b(C(Ft),{name:n.value.icon,size:16},null,8,[`name`])],2),T(`span`,ho,[T(`span`,go,[T(`span`,_o,P(e.notification.title),1),T(`time`,{class:`time`,datetime:new Date(e.notification.createdAt).toISOString(),title:C(St)(e.notification.createdAt)},P(C(Kt)(e.notification.createdAt,e.now)),9,vo)]),e.notification.body===``?R(``,!0):(j(),E(`span`,yo,P(e.notification.body),1)),T(`span`,{class:w([`reason`,`tone-${n.value.tone}`]),"data-testid":`notification-reason`},[e.notification.read?R(``,!0):(j(),E(`span`,bo)),x(` `+P(n.value.label),1),e.notification.read?R(``,!0):(j(),E(`span`,xo,`, unread`))],2)])]),T(`div`,So,[e.notification.also?(j(),F(C(H),{key:0,class:`also`,size:`sm`,variant:`ghost`,"data-testid":`notification-also`,onClick:r[1]||=n=>t.$emit(`also`,e.notification)},{default:N(()=>[x(P(e.notification.also.label),1)]),_:1})):R(``,!0),e.notification.read?R(``,!0):(j(),F(C(Ct),{key:1,class:`read`,icon:`check`,label:`Mark as read`,size:`sm`,onClick:r[2]||=n=>t.$emit(`read`,e.notification)}))])],10,mo))}}),[[`__scopeId`,`data-v-3a6b7c55`]]),wo=[`aria-busy`],To={key:1,class:`skeletons`,"aria-label":`Loading notifications`},Eo={key:4,class:`more`},Do=Y(A({__name:`NotificationList`,props:{items:{},now:{},loading:{type:Boolean},loaded:{type:Boolean},problem:{default:``},hasMore:{type:Boolean,default:!1},loadingMore:{type:Boolean,default:!1},compact:{type:Boolean,default:!1},emptyTitle:{default:`All caught up`},emptyBody:{default:`Approvals, replies and finished work show up here.`}},emits:[`open`,`also`,`read`,`more`,`retry`],setup(e){return(n,r)=>(j(),E(`div`,{class:w([`list`,{compact:e.compact}]),"aria-busy":e.loading?`true`:`false`},[e.problem===``?R(``,!0):(j(),F(C(Mt),{key:0,tone:`danger`,class:`problem`},{actions:N(()=>[b(C(H),{size:`sm`,variant:`ghost`,onClick:r[0]||=e=>n.$emit(`retry`)},{default:N(()=>[...r[5]||=[x(`Retry`,-1)]]),_:1})]),default:N(()=>[x(P(e.problem)+` `,1)]),_:1})),e.loading&&!e.loaded?(j(),E(`ul`,To,[(j(!0),E(M,null,D(e.compact?3:5,e=>(j(),E(`li`,{key:e,class:`skeleton`},[b(C(Dt),{shape:`circle`,size:32}),b(C(Dt),{shape:`lines`,lines:2,class:`lines`})]))),128))])):e.loaded&&e.items.length===0?(j(),F(C(At),{key:2,icon:`inbox`,title:e.emptyTitle,body:e.emptyBody},null,8,[`title`,`body`])):(j(),F(t,{key:3,tag:`ul`,name:`row`,class:`rows`},{default:N(()=>[(j(!0),E(M,null,D(e.items,t=>(j(),F(Co,{key:t.id,notification:t,now:e.now,compact:e.compact,onOpen:r[1]||=e=>n.$emit(`open`,e),onAlso:r[2]||=e=>n.$emit(`also`,e),onRead:r[3]||=e=>n.$emit(`read`,e)},null,8,[`notification`,`now`,`compact`]))),128))]),_:1})),e.hasMore&&e.items.length>0?(j(),E(`div`,Eo,[b(C(H),{variant:`ghost`,size:`sm`,loading:e.loadingMore,onClick:r[4]||=e=>n.$emit(`more`)},{default:N(()=>[...r[6]||=[x(`Load older`,-1)]]),_:1},8,[`loading`])])):R(``,!0)],10,wo))}}),[[`__scopeId`,`data-v-c9cb4a65`]]),Oo={class:`panel`,"data-testid":`inbox-panel`},ko={class:`head`},Ao={class:`foot`},jo=Y(A({__name:`InboxPanel`,props:{items:{},unread:{},now:{},loading:{type:Boolean},loaded:{type:Boolean},problem:{default:``},limit:{default:6}},emits:[`open`,`also`,`read`,`readAll`,`all`,`retry`],setup(e){let t=e,n=k(()=>t.items.slice(0,t.limit));return(t,r)=>(j(),E(`div`,Oo,[T(`header`,ko,[r[7]||=T(`h2`,{class:`title`},`Notifications`,-1),e.unread>0?(j(),F(C(H),{key:0,size:`sm`,variant:`ghost`,icon:`check`,onClick:r[0]||=e=>t.$emit(`readAll`)},{default:N(()=>[...r[6]||=[x(`Mark all read`,-1)]]),_:1})):R(``,!0)]),b(Do,{items:n.value,now:e.now,loading:e.loading,loaded:e.loaded,problem:e.problem,compact:``,onOpen:r[1]||=e=>t.$emit(`open`,e),onAlso:r[2]||=e=>t.$emit(`also`,e),onRead:r[3]||=e=>t.$emit(`read`,e),onRetry:r[4]||=e=>t.$emit(`retry`)},null,8,[`items`,`now`,`loading`,`loaded`,`problem`]),T(`footer`,Ao,[b(C(H),{size:`sm`,variant:`ghost`,"icon-right":`arrow-right`,block:``,onClick:r[5]||=e=>t.$emit(`all`)},{default:N(()=>[...r[8]||=[x(`Open inbox`,-1)]]),_:1})])]))}}),[[`__scopeId`,`data-v-d2b5d353`]]),Mo={class:`steps`,"data-testid":`install-sheet`},No=Y(A({__name:`InstallSheet`,props:ge({name:{}},{open:{type:Boolean,required:!0},openModifiers:{}}),emits:[`update:open`],setup(e){let t=_e(e,`open`);return(n,r)=>(j(),F(C(yt),{open:t.value,"onUpdate:open":r[1]||=e=>t.value=e,title:`Add to Home Screen`,description:`Put ${e.name} on your home screen, like any other app.`,width:`420px`},{footer:N(()=>[b(C(H),{variant:`primary`,onClick:r[0]||=e=>t.value=!1},{default:N(()=>[...r[6]||=[x(`Got it`,-1)]]),_:1})]),default:N(()=>[T(`ol`,Mo,[r[4]||=T(`li`,null,[T(`span`,null,[x(`Tap `),T(`strong`,null,`Share`)]),T(`svg`,{class:`glyph`,viewBox:`0 0 24 24`,"aria-label":`the Share button`,role:`img`},[T(`path`,{d:`M12 3v12M8 7l4-4 4 4`}),T(`path`,{d:`M7 10H5v11h14V10h-2`})]),T(`span`,{class:`dim`},`at the bottom of Safari (at the top on an iPad).`)],-1),r[5]||=T(`li`,null,[T(`span`,null,[x(`Scroll down and tap `),T(`strong`,null,`Add to Home Screen`),x(`.`)])],-1),T(`li`,null,[T(`span`,null,[r[2]||=x(`Tap `,-1),r[3]||=T(`strong`,null,`Add`,-1),x(`. Open `+P(e.name)+` from your home screen from now on.`,1)])])]),r[7]||=T(`p`,{class:`dim note`},`Only Safari can add it. In another browser, open this page in Safari first.`,-1)]),_:1},8,[`open`,`description`]))}}),[[`__scopeId`,`data-v-f47f52f1`]]),Po=[`title`],Fo=[`width`,`height`],Io={key:0,class:`name`,"data-testid":`brand-name`},Lo=Y(A({__name:`AppBrand`,props:{name:{},markOnly:{type:Boolean,default:!1},size:{default:28}},setup(e){return(t,n)=>(j(),E(`span`,{class:`brand`,title:e.markOnly?e.name:void 0},[(j(),E(`svg`,{class:`mark`,width:e.size,height:e.size,viewBox:`0 0 32 32`,"aria-hidden":`true`},[...n[0]||=[be(`<rect width="32" height="32" rx="9" class="tile" data-v-c7bc8cf6></rect><g class="lines" stroke-width="2" stroke-linecap="round" data-v-c7bc8cf6><path d="M16 16 9 9M16 16l7-7M16 16v8" data-v-c7bc8cf6></path></g><circle cx="16" cy="16" r="3.5" class="hub" data-v-c7bc8cf6></circle><circle cx="9" cy="9" r="2.3" class="node" data-v-c7bc8cf6></circle><circle cx="23" cy="9" r="2.3" class="node" data-v-c7bc8cf6></circle><circle cx="16" cy="24" r="2.3" class="node" data-v-c7bc8cf6></circle>`,6)]],8,Fo)),e.markOnly?R(``,!0):(j(),E(`span`,Io,P(e.name),1))],8,Po))}}),[[`__scopeId`,`data-v-c7bc8cf6`]]),Ro={class:`head`},zo={class:`head-tools`},Bo={class:`entries`},Vo={class:`label`},Ho=[`aria-label`],Uo={class:`middle`},Wo={key:0,class:`foot`},Go=[`title`,`onClick`],Ko={class:`who`},qo={class:`name`},Jo={class:`email`},Yo=Y(A({__name:`AppSidebar`,props:{brand:{},entries:{},user:{},unread:{},collapsed:{type:Boolean,default:!1},collapsible:{type:Boolean,default:!0},installable:{type:Boolean,default:!1}},emits:[`toggle`,`inbox`,`settings`,`install`,`signOut`,`navigate`],setup(e,{emit:t}){let n=e,r=t,i=ve(),a=k(()=>[{value:`settings`,label:`Settings`,icon:`settings`},...n.installable?[{value:`install`,label:`Install app`,icon:`download`}]:[],{kind:`separator`},{value:`sign-out`,label:`Sign out`,icon:`log-out`,danger:!0}]);function o(e){e.currentTarget instanceof HTMLElement&&r(`inbox`,e.currentTarget)}function s(e){switch(e){case`settings`:r(`settings`);break;case`install`:r(`install`);break;case`sign-out`:r(`signOut`)}}return(t,n)=>{let r=ye(`RouterLink`);return j(),E(`nav`,{class:w([`sidebar`,{collapsed:e.collapsed}]),"aria-label":`Main`},[T(`div`,Ro,[b(Lo,{name:e.brand,"mark-only":e.collapsed},null,8,[`name`,`mark-only`]),T(`div`,zo,[b(C(Ct),{icon:`bell`,label:e.unread>0?`Notifications, ${C(Nt)(e.unread)} unread`:`Notifications`,badge:e.unread,"data-testid":`open-inbox`,onClick:o},null,8,[`label`,`badge`]),e.collapsible?(j(),F(C(Ct),{key:0,icon:`sidebar`,label:e.collapsed?`Expand sidebar`:`Collapse sidebar`,"data-testid":`toggle-sidebar`,onClick:n[0]||=e=>t.$emit(`toggle`)},null,8,[`label`])):R(``,!0)])]),T(`ul`,Bo,[(j(!0),E(M,null,D(e.entries,i=>(j(),E(`li`,{key:i.id},[b(r,{to:i.to,class:w([`entry`,{active:i.active}]),"aria-current":i.active?`page`:void 0,title:e.collapsed?i.label:void 0,"data-testid":`nav-${i.id}`,onClick:n[1]||=e=>t.$emit(`navigate`)},{default:N(()=>[b(C(Ft),{name:i.icon,size:18},null,8,[`name`]),T(`span`,Vo,P(i.label),1),i.count>0?(j(),E(`span`,{key:0,class:`count`,"aria-label":`${i.count} unread`},P(C(Nt)(i.count)),9,Ho)):R(``,!0)]),_:2},1032,[`to`,`class`,`aria-current`,`title`,`data-testid`])]))),128))]),T(`div`,Uo,[i.default&&!e.collapsed?Me(t.$slots,`default`,{},void 0,!0,0):R(``,!0)]),e.user?(j(),E(`div`,Wo,[b(C(It),{items:a.value,label:`Account`,side:`top`,align:`start`,onSelect:s},{trigger:N(({toggle:t,attrs:n})=>[T(`button`,we({type:`button`,class:`person`},n,{title:e.collapsed?e.user.name:void 0,"data-testid":`user-menu`,onClick:t}),[b(C(jt),{name:e.user.name,size:30},null,8,[`name`]),T(`span`,Ko,[T(`span`,qo,P(e.user.name),1),T(`span`,Jo,P(e.user.email),1)]),b(C(Ft),{name:`chevron-up`,size:16,class:`chevron`})],16,Go)]),_:1},8,[`items`])])):R(``,!0)],2)}}}),[[`__scopeId`,`data-v-db84e1b2`]]),Xo={class:`topbar`},Zo={class:`title`},Qo=Y(A({__name:`AppTopBar`,props:{title:{},unread:{}},emits:[`menu`,`inbox`],setup(e,{emit:t}){let n=t;function r(e){e.currentTarget instanceof HTMLElement&&n(`inbox`,e.currentTarget)}return(t,n)=>(j(),E(`header`,Xo,[b(C(Ct),{icon:`menu`,label:`Open navigation`,"data-testid":`open-nav`,onClick:n[0]||=e=>t.$emit(`menu`)}),T(`h1`,Zo,P(e.title),1),b(C(Ct),{icon:`bell`,label:e.unread>0?`Notifications, ${C(Nt)(e.unread)} unread`:`Notifications`,badge:e.unread,"data-testid":`open-inbox`,onClick:r},null,8,[`label`,`badge`])]))}}),[[`__scopeId`,`data-v-58e88c22`]]),$o=[{id:`chat`,to:y.chat(),label:`Chat`,icon:`chat`,routes:[v.chat,v.session,v.turnTree],adminOnly:!1},{id:`inbox`,to:y.inbox(),label:`Inbox`,icon:`inbox`,routes:[v.inbox],adminOnly:!1},{id:`resources`,to:y.resources(),label:`Resources`,icon:`layers`,routes:[v.resources],adminOnly:!1},{id:`context`,to:y.context(),label:`Context`,icon:`book`,routes:[v.context,v.contextItem],adminOnly:!1},{id:`data`,to:y.data(),label:`Data`,icon:`database`,routes:[v.data,v.dataType],adminOnly:!1},{id:`admin`,to:y.systems(),label:`Admin`,icon:`shield`,adminOnly:!0,routes:[v.admin,v.systems,v.system,v.review,v.instance,v.fn,v.graph,v.models,v.limits,v.people,v.policies,v.actorSettings,v.runs,v.llmCalls,v.modelCalls,v.mcps,v.mcp,v.adminSystemPage]},{id:`settings`,to:y.settings(),label:`Settings`,icon:`settings`,routes:[v.settings],adminOnly:!1}],es=e=>typeof e==`string`&&Object.values(v).includes(e);function ts(e,t,n){let r=e.filter(e=>e.system===t);return r.find(e=>e.segment===n)??r[0]}function ns(e,t,n,r=[],i=[]){let a=es(e.name)?e.name:void 0,o=$o.filter(e=>!e.adminOnly||t?.role===`admin`).map(e=>({id:e.id,to:e.to,label:e.label,icon:e.icon,active:a!==void 0&&e.routes.includes(a),count:e.id===`inbox`?n.inbox:e.id===`admin`?n.admin:0})),s=r.map(t=>({id:`connect-${t.system}`,to:y.connect(t.system),label:t.title,icon:t.icon,active:a===v.connect&&e.params?.system===t.system,count:0})),c=i.map(t=>({id:`page-${t.system}-${t.segment}`,to:y.systemPage(t.system,t.segment),label:t.title,icon:t.icon,active:a===v.systemPage&&t===ts(i,e.params?.system,e.params?.page),count:0})),l=o.findIndex(e=>e.id===`context`)+1;return[...o.slice(0,l),...s,...c,...o.slice(l)]}function rs(){let{keeper:e}=G(),t=ie();return async()=>{await e.signOut(),window.location.replace(t.resolve(y.signIn()).href)}}function is(){let{session:e}=G(),t=ie();S(e.signedIn,e=>{let n=t.currentRoute.value;e||n.meta.public===!0||window.location.replace(t.resolve(y.signIn(n.fullPath)).href)})}function as(e){return[`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">`,`<rect width="32" height="32" rx="9" fill="#5b5bd6"/>`,`<g stroke="#fff" stroke-width="2" stroke-linecap="round" opacity="0.7"><path d="M16 16 9 9M16 16l7-7M16 16v8"/></g>`,`<circle cx="16" cy="16" r="3.5" fill="#fff"/><circle cx="9" cy="9" r="2.3" fill="#fff"/><circle cx="23" cy="9" r="2.3" fill="#fff"/><circle cx="16" cy="24" r="2.3" fill="#fff"/>`,e?`<circle cx="26" cy="26" r="6" fill="#e5484d" stroke="#fff" stroke-width="2"/>`:``,`</svg>`].join(``)}function os(e){return`data:image/svg+xml,${encodeURIComponent(as(e))}`}function ss(e,t){let n=e.querySelector(`link[rel="icon"]`);n===null&&(n=e.createElement(`link`),n.rel=`icon`,e.head.append(n)),n.type=`image/svg+xml`,n.href=os(t)}function cs(e,t,n){let r=t>0?`(${t>99?`99+`:String(t)}) `:``;return e===n?`${r}${n}`:`${r}${e} · ${n}`}var ls={class:`titlebar`,"aria-hidden":`true`,"data-testid":`titlebar`},us={class:`titlebar-name`},ds=[`aria-busy`],fs={key:0,class:`connection`,"data-testid":`connection-banner`},ps=Y(A({__name:`AppShell`,setup(e){let{session:t,identity:n,keeper:r,layout:i,toasts:a,inbox:o,connection:s,admin:c,chat:l,pages:d,outsideImages:f,install:p}=G(),m=rs(),h=u(),g=ie(),_=Vt(Wr),ee=nn(),te=t.signedIn,ne=k(()=>h.meta.bare===!0||!te.value),re=k(()=>ns(h,t.user.value,{inbox:o.unread.value,admin:c.systems.pending.value},l.connections.nav.value,d.nav.value)),ae=k(()=>i.pageTitle.value===void 0?(h.name===v.connect?l.connections.nav.value.find(e=>e.system===h.params.system):void 0)?.title??h.meta.title??n.name.value:i.pageTitle.value),oe=k(()=>_.value&&h.meta.ownHeader!==!0),se=L(!1),ce=L(null);S(te,(e,t)=>{n.load(),e?(r.start(),n.start(),o.start(),l.connections.load(!0),d.start(),d.load(!0),f.load()):(d.clear(),f.clear(),r.stop(),o.stop(),n.stop(),t===!0&&h.meta.public!==!0&&g.replace(y.signIn(h.fullPath)))},{immediate:!0}),S([ae,o.unread,n.name],([e,t,n])=>{document.title=cs(e,t,n),ss(document,t>0)},{immediate:!0}),S(()=>h.fullPath,()=>{i.drawerOpen.value=!1,se.value=!1});function le(e){se.value&&ce.value===e?se.value=!1:(ce.value=e,i.drawerOpen.value=!1,se.value=!0,o.load(`all`))}async function ue(e,t=`link`){se.value=!1,e.read||o.markRead([e.id]),await g.push(await de(e,e=>l.sessionOfRun(e),t))}async function fe(){i.drawerOpen.value=!1,await p.install()===`accepted`&&a.ok(`Installed`)}async function pe(){await o.markAllRead()&&a.ok(`All caught up`)}return(e,r)=>{let c=ye(`RouterView`);return j(),E(`div`,{class:w([`shell`,{bare:ne.value,compact:C(_),"no-bar":C(_)&&!oe.value,collapsed:!C(_)&&C(i).collapsed}])},[T(`div`,ls,[T(`span`,us,P(C(n).name.value),1)]),ne.value?R(``,!0):(j(),E(M,{key:0},[C(_)?oe.value?(j(),F(Qo,{key:1,title:ae.value,unread:C(o).unread.value,onMenu:r[2]||=e=>C(i).drawerOpen.value=!0,onInbox:le},null,8,[`title`,`unread`])):R(``,!0):(j(),F(Yo,{key:0,class:`side`,brand:C(n).name.value,entries:re.value,user:C(t).user.value,unread:C(o).unread.value,collapsed:C(i).collapsed,installable:C(p).offered,onToggle:r[0]||=e=>C(i).toggleSidebar(),onInbox:le,onSettings:r[1]||=e=>C(g).push(C(y).settings()),onSignOut:C(m),onInstall:fe},null,8,[`brand`,`entries`,`user`,`unread`,`collapsed`,`installable`,`onSignOut`])),C(_)?(j(),F(C(vt),{key:2,open:C(i).drawerOpen.value,"onUpdate:open":r[5]||=e=>C(i).drawerOpen.value=e,placement:`left`,label:`Navigation`,width:`300px`},{default:N(()=>[b(Yo,{brand:C(n).name.value,entries:re.value,user:C(t).user.value,unread:C(o).unread.value,collapsible:!1,installable:C(p).offered,onInbox:le,onSettings:r[3]||=e=>C(g).push(C(y).settings()),onSignOut:C(m),onNavigate:r[4]||=e=>C(i).drawerOpen.value=!1,onInstall:fe},null,8,[`brand`,`entries`,`user`,`unread`,`installable`,`onSignOut`])]),_:1},8,[`open`])):R(``,!0)],64)),T(`main`,{class:`page`,"aria-busy":C(o).loading.value?`true`:void 0},[!ne.value&&C(s).state.value!==`online`?(j(),E(`div`,fs,[b(C(Mt),{tone:C(s).state.value===`offline`?`warn`:`ok`,icon:C(s).state.value===`offline`?`offline`:`success`},{default:N(()=>[x(P(C(s).state.value===`offline`?`Reconnecting to the hub…`:`Back online`),1)]),_:1},8,[`tone`,`icon`])])):R(``,!0),b(c,null,{default:N(({Component:e,route:t})=>[(j(),F(je(e),{key:t.meta.group??t.matched[0]?.path??t.path,class:`routed`}))]),_:1})],8,ds),b(C(Yt),{open:se.value,"onUpdate:open":r[11]||=e=>se.value=e,anchor:ce.value,side:C(_)?`bottom`:`right`,align:`start`,label:`Notifications`},{default:N(()=>[b(jo,{items:C(o).items.value,unread:C(o).unread.value,now:C(ee),loading:C(o).loading.value,loaded:C(o).loaded.value,problem:C(o).problem.value,onOpen:r[6]||=e=>ue(e),onAlso:r[7]||=e=>ue(e,`also`),onRead:r[8]||=e=>C(o).markRead([e.id]),onReadAll:pe,onAll:r[9]||=e=>C(g).push(C(y).inbox()),onRetry:r[10]||=e=>C(o).load(`all`)},null,8,[`items`,`unread`,`now`,`loading`,`loaded`,`problem`])]),_:1},8,[`open`,`anchor`,`side`]),b(No,{open:C(p).sheetOpen.value,"onUpdate:open":r[12]||=e=>C(p).sheetOpen.value=e,name:C(n).name.value},null,8,[`open`,`name`]),b(C(Bt),{toasts:C(a).items,onDismiss:r[13]||=e=>C(a).dismiss(e),onAction:r[14]||=e=>C(a).act(e),onHold:r[15]||=e=>C(a).hold(e),onRelease:r[16]||=e=>C(a).release(e)},null,8,[`toasts`])],2)}}}),[[`__scopeId`,`data-v-73b0dbae`]]),ms=A({__name:`App`,setup(e){let{chat:t,itemVersions:n,session:i,outsideImages:s}=G();Ee(Ut,()=>s.value.value),Ee(tn,t.types),Ee(kr,n),Ee($t,e=>t.renderers.inputView(e)),Ee(r,_t),Ee(o,Ne),Ee(a,Ri),Ee(Fe,t.visuals),is();let c=hr(ie());return(e,t)=>(j(),E(M,null,[b(ps),C(c).name.value&&C(i).signedIn.value?(j(),F(lo,{key:0,modal:C(c),fn:C(c).name.value},null,8,[`modal`,`fn`])):R(``,!0)],64))}});function hs(e,t){let n=g({history:t,routes:oe,scrollBehavior:(e,t,n)=>n??{top:0}});return n.beforeEach(t=>{let n=e.signedIn.value;return t.name===v.signIn&&n?fe(t.query.next)??y.chat():t.meta.public===!0?!0:n?t.meta.admin===!0&&e.user.value?.role!==`admin`?y.chat():!0:y.signIn(t.fullPath)}),n}var gs=K({server:K({name:q(),version:q()}),instructions:q().optional(),tools:Yn(K({name:q(),description:q().optional()}))}),_s=`2025-06-18`,vs=Nn([K({jsonrpc:mn(`2.0`),id:Nn([Cn(),q()]),result:Rn()}),K({jsonrpc:mn(`2.0`),id:Nn([Cn(),q(),sn()]),error:K({code:Cn(),message:q()})})]),ys=K({serverInfo:K({name:q(),version:q()}),instructions:q().optional()}),bs=K({tools:Yn(K({name:q(),description:q().optional()}))});function xs(e,t){if(!e.includes(`text/event-stream`))return JSON.parse(t);let n=t.split(/\r?\n/).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trim()).filter(e=>e!==``);for(let e of n.reverse())try{return JSON.parse(e)}catch{}throw Error(`The MCP sent no answer.`)}var Ss=class{#e;constructor(e){this.#e=e}async tools(e,t){let n,r=async(r,i,a)=>{let o=await this.#e(e,{method:`POST`,headers:{"content-type":`application/json`,accept:`application/json, text/event-stream`,authorization:`Bearer ${t}`,"mcp-protocol-version":_s,...n===void 0?{}:{"mcp-session-id":n}},body:JSON.stringify({jsonrpc:`2.0`,method:i,params:a,...r===void 0?{}:{id:r}})});if(o.status===401||o.status===403)throw Error(`The MCP refused that secret.`);if(!o.ok&&o.status!==202)throw Error(`The MCP answered ${o.status}.`);if(n=o.headers.get(`mcp-session-id`)??n,r===void 0)return;let s=vs.parse(xs(o.headers.get(`content-type`)??``,await o.text()));if(`error`in s)throw Error(s.error.message);return s.result},i=ys.parse(await r(1,`initialize`,{protocolVersion:_s,capabilities:{},clientInfo:{name:`harness-admin`,version:`1`}}));await r(void 0,`notifications/initialized`,{});let a=bs.parse(await r(2,`tools/list`,{}));return gs.parse({server:i.serverInfo,...i.instructions===void 0?{}:{instructions:i.instructions},tools:a.tools})}},Cs=class{#e;#t;secrets=new W;revoking=new U;constructor(e){this.#e=e}async load(e,t=!1){this.#t=e,await this.secrets.load(()=>this.#e.autoPairs.call({system:e}),`Couldn't load the auto pair secrets.`,t)}async revoke(e){let t=await this.revoking.run(async()=>(await this.#e.revokeAutoPair.call({id:e})).ok,`Couldn't revoke that secret.`);return t.ok&&this.#t!==void 0&&await this.load(this.#t,!0),t}},ws=class{#e;decision=new W;saving=new U;preview=new W;search=new W;searchSaving=new U;constructor(e){this.#e=e}async load(e=!1){await this.decision.load(()=>this.#e.suggestDecision.call({}),`Couldn't load the suggestions setting.`,e)}async save(e){let t=await this.saving.run(()=>this.#e.setSuggestDecision.call(e),`Couldn't save the suggestions setting.`);return t.ok&&this.decision.set(t.value),t}async loadSearch(e=!1){await this.search.load(()=>this.#e.searchDecisions.call({}),`Couldn't load the search settings.`,e)}async saveSearch(e,t){let n=await this.searchSaving.run(()=>this.#e.setSearchDecision.call({item:e,value:t}),`Couldn't save the search setting.`);return n.ok&&this.search.set(n.value),n}async try(e,t){await this.preview.load(()=>this.#e.previewSuggestions.call({session:e,text:t}),`Couldn't try the suggestions.`)}},Ts=class{#e;setting=new W;saving=new U;constructor(e){this.#e=e}async load(e=!1){await this.setting.load(()=>this.#e.autoClassifier.call({}),`Couldn't load the auto mode classifier.`,e)}async save(e){let t=await this.saving.run(()=>this.#e.setAutoClassifier.call(e),`Couldn't save the auto mode classifier.`);return t.ok&&this.setting.set(t.value),t}},Es=class{#e;setting=new W;saving=new U;constructor(e){this.#e=e}async load(e=!1){await this.setting.load(()=>this.#e.imageEmbedding.call({}),`Couldn't load where pictures are embedded.`,e)}async save(e){let t=await this.saving.run(()=>this.#e.setImageEmbedding.call(e),`Couldn't save where pictures are embedded.`);return t.ok&&this.setting.set(t.value),t}},Ds=class{#e;list=new W;#t=k(()=>new Map((this.list.value.value??[]).map(e=>[e.id,e])));constructor(e){this.#e=e}async load(e=!1){(e||this.list.value.value===void 0&&!this.list.loading.value)&&await this.list.load(()=>this.#e.actors.call({}),`Couldn't load people and groups.`)}nameOf=e=>this.#t.value.get(e)?.name??e;options(e){return(this.list.value.value??[]).filter(t=>e.includes(t.kind)&&!t.disabled).map(e=>({id:e.id,name:e.name,kind:e.kind,detail:e.kind===`user`?e.email:e.about})).sort((e,t)=>e.name.localeCompare(t.name))}},Os=class{#e;#t=new Set;byRun=L(new Map);problem=I(``);constructor(e){this.#e=e}async load(e){let t=[...new Set(e)].filter(e=>!this.#t.has(e)).slice(0,200);if(t.length!==0){for(let e of t)this.#t.add(e);try{let e=await this.#e.approvals.call({runs:t}),n=new Map(this.byRun.value);for(let t of e)t.status===`pending`&&n.set(t.run,t);this.byRun.value=n,this.problem.value=``}catch(e){for(let e of t)this.#t.delete(e);this.problem.value=X(e)}}}async decide(e,t,n,r){let i=this.byRun.value,a=new Map(i);a.delete(e.run),this.byRun.value=a;try{return await this.#e.approve.call({approval:e.id,approve:t,remember:`once`,...n===``?{}:{reason:n},...r===void 0?{}:{answer:r}}),!0}catch(e){return this.byRun.value=i,this.problem.value=X(e),!1}}};function ks(e){return e.run===void 0?{query:e.query}:{run:e.run}}var As=class{#e;list;opened=new W;openedId=L(void 0);constructor(e,t){this.#e=e,this.list=new f(e,t)}async open(e){let t=this.openedId.value===e;t||this.opened.reset(),this.openedId.value=e,await this.opened.load(()=>this.#e.one(e),this.#e.oneFailure,t)}close(){this.openedId.value=void 0,this.opened.reset()}},js=class extends As{#e;control=new U;constructor(e,t){super(e,{}),this.#e=t}async background(e){let t=await this.control.run(()=>this.#e.background.call({run:e}),`Couldn't move it to the background.`);return t.ok&&this.open(e),t}async undoTurn(e){let t=await this.control.run(()=>this.#e.undoTurn.call({turn:e}),`Couldn't undo the turn.`);return t.ok&&this.list.refresh(),t}};function Ms(e,t){return new js({fetch:(t,n,r)=>e.runs.call(h({query:t},r,n)),key:e=>e.id,failure:`Couldn't load runs.`,limit:50,one:e=>t.run.call({run:e}),oneFailure:`Couldn't load this run.`},t)}function Ns(e,t){return new As({fetch:(t,n,r)=>e.llmCalls.call(h({query:t},r,n)),key:e=>e.id,failure:`Couldn't load LLM calls.`,limit:50,one:e=>t.llmCall.call({id:e}),oneFailure:`Couldn't load this LLM call.`},{})}function Ps(e,t){return new As({fetch:(t,n,r)=>e.modelCalls.call(h(ks(t),r,n)),key:e=>e.id,failure:`Couldn't load model calls.`,limit:50,one:async n=>{let r=await e.modelCall.call({id:n});return r.interaction===void 0?{call:r}:{call:r,interaction:await t.llmCall.call({id:r.interaction})}},oneFailure:`Couldn't load this model call.`},{query:{}})}function Fs(e,t){return new As({fetch:(t,n,r)=>e.resources.call(h({query:t},r,n)),key:e=>e.uri,failure:`Couldn't load resources.`,limit:50,one:e=>t.resource.call({uri:e,want:[`text`,`links`]}),oneFailure:`Couldn't open this resource.`},{})}var Is=class{#e;#t;#n;key=L(void 0);instances=new W;configForm=new W;config=new U;exporting=new U;removing=new U;view=k(()=>this.instances.value.value?.find(e=>e.instance===this.key.value?.instance));constructor(e,t){this.#e=e,this.#t=t}async open(e){let t=this.key.value?.system===e.system&&this.key.value.instance===e.instance;t||this.close(),this.key.value=e,this.#n??=this.#t(e=>{this.#i(e)}),await Promise.all([this.#r(e.system,t),this.configForm.load(async()=>{let t=await this.#e.system.call({system:e.system});return{type:t.configType,secrets:t.configSecrets??[],instanceMode:t.instanceMode,store:t.store}},`Couldn't load this system.`,t)])}close(){this.#n?.(),this.#n=void 0,this.key.value=void 0,this.instances.reset(),this.configForm.reset()}async configure(e){let t=this.key.value;if(t===void 0)return{ok:!1,problems:[`No instance is open.`]};let n=await this.config.run(()=>this.#e.configureSystem.call({system:t.system,instance:t.instance,config:e}),`Couldn't save the config.`);return n.ok?`problems`in n.value?{ok:!1,problems:n.value.problems}:(this.#r(t.system,!0),{ok:!0,version:n.value.version}):{ok:!1,problems:[n.problem]}}async exportData(e,t=this.key.value){return t===void 0?{ok:!1,problem:`No instance is open.`}:this.exporting.run(async()=>{let n=await this.#e.exportSystemData.call({...t,...e?{withSecrets:e}:{}});return{url:n.url,size:n.size}},`Couldn't export this instance's data.`)}async remove(e){let t=this.key.value;if(t===void 0)return!1;let n=await this.removing.run(()=>this.#e.removeInstance.call({...t,...e===void 0?{}:{keepStore:e}}),`Couldn't remove ${t.system}@${t.instance}.`);return n.ok&&n.value.ok}async#r(e,t){await this.instances.load(()=>this.#e.instances.call({system:e}),`Couldn't load this system's instances.`,t)}#i(e){let t=this.key.value;e.type===`system`&&t!==void 0&&e.system===t.system&&this.#r(t.system,!0)}};function Ls(e,t){return e.filter(e=>e.decl.routing?.to===`instance`&&e.decl.routing.instance===t)}function Rs(e,t,n){return{list:`types`,query:{filters:[{field:`system`,op:`is`,value:e.system},...e.instance===void 0?[]:[{field:`instance`,op:`is`,value:e.instance}]],sort:[{field:`name`,dir:`asc`}],limit:n,...t===void 0?{}:{cursor:t}}}}function zs(e,t){let n=$n.safeParse(t.includes(`/`)?t:`${e}/${t}`);return n.success?n.data:void 0}function Bs(e,t){let n=new Set;for(let r of t)for(let t of r.preview?.parts??[]){if(t.type!==`type-diff`)continue;let r=zs(e,t.name);r!==void 0&&n.add(r)}return n}function Vs(e,t){return e.filter(e=>e.status===`awaiting-approval`&&e.instance===t)}function Hs(e){return e.filter(e=>e.proposed===!0&&e.status===`pending`)}function Us(e,t){return[...new Set([...e??[],...Ws(t)])]}function Ws(e,t=``){return e===`•••• kept`?t===``?[]:[t]:qn(e)?Object.entries(e).flatMap(([e,n])=>Ws(n,t===``?e:`${t}.${e}`)):[]}function Gs(e,t,n,r=!1){let i=[{label:`Version`,value:e.version}];return e.address!==void 0&&!r&&i.push({label:`Address`,value:e.address}),i.push({label:`Key`,value:e.keyFingerprint}),e.pairedAt!==void 0&&i.push({label:`Paired`,value:`${Kt(e.pairedAt,t)}${e.pairedBy===void 0?``:` by ${n(e.pairedBy)}`}`,title:St(e.pairedAt)}),e.lastSeenAt!==void 0&&i.push({label:`Last seen`,value:e.status===`connected`?`Online now`:Kt(e.lastSeenAt,t),title:St(e.lastSeenAt)}),e.config!==void 0&&i.push({label:`Config`,value:`Version ${e.config.version}, ${Kt(e.config.setAt,t)}`,title:St(e.config.setAt)}),i.push({label:`Manifest`,value:e.manifestHash,code:!0}),i}var Ks=class{#e;#t=L(void 0);fns=new W;types;typeCount=I(void 0);waitingRuns=new W;desk;proposals=k(()=>Hs((this.waitingRuns.value.value??[]).flatMap(e=>{let t=this.desk.byRun.value.get(e.id);return t===void 0?[]:[t]})));changing=k(()=>{let e=this.#t.value;return e===void 0?new Set:Bs(e.system,this.proposals.value)});constructor(e,t){this.#e=e,this.desk=new Os(t),this.types=new f({fetch:async(e,t,n)=>{if(e===void 0)return{items:[]};let r=await this.#e.query.call(Rs(e,t,n));return t===void 0&&(this.typeCount.value=r.total),{items:Pn.array().parse(r.items),...r.cursor===void 0?{}:{cursor:r.cursor}}},key:e=>e.name,failure:`Couldn't load this instance's types.`,limit:100},void 0)}async open(e){let t=this.#t.value,n=t?.system===e.system&&t.instance===e.instance;n||this.close(),this.#t.value=e,await Promise.all([this.fns.load(async()=>Ls(await this.#e.systemFns.call({system:e.system}),e.instance),`Couldn't load this instance's fns.`,n),this.waitingRuns.load(async()=>{let t=Vs((await this.#e.runs.call({query:{filters:[{field:`system`,op:`is`,value:e.system},{field:`status`,op:`is`,value:`awaiting-approval`}],limit:100}})).items,e.instance);return await this.desk.load(t.map(e=>e.id)),t},`Couldn't load the changes waiting for approval.`,n),this.types.load(e)])}async decide(e,t,n){let r=await this.desk.decide(e,t,n),i=this.#t.value;return r&&i!==void 0&&this.open(i),r}close(){this.#t.value=void 0,this.fns.reset(),this.types.load(void 0),this.typeCount.value=void 0,this.waitingRuns.reset()}},qs=class{#e;list=new W;create=new U;constructor(e){this.#e=e}async load(e=!1){await this.list.load(()=>this.#e.mcps.call({}),`Couldn't load the MCPs.`,e)}async make(e){let t=await this.create.run(()=>this.#e.createMcp.call(e),`Couldn't make that MCP.`);return t.ok&&this.list.set([...this.list.value.value??[],t.value.mcp]),t}},Js=class{#e;#t;id=I(void 0);view=new W;sessions=new W;draft=L(void 0);preview=new W;save=new U;rotate=new U;remove=new U;secret=I(``);tried=new W;changed=k(()=>this.draft.value!==void 0&&JSON.stringify(this.draft.value)!==JSON.stringify(this.view.value.value?.rules));constructor(e,t){this.#e=e,this.#t=t}async open(e,t=``){this.id.value!==e&&this.close(),this.id.value=e,t!==``&&(this.secret.value=t),await this.view.load(()=>this.#e.mcp.call({mcp:e}),`Couldn't load this MCP.`,this.view.value.value?.id===e);let n=this.view.value.value;n!==void 0&&this.draft.value===void 0&&this.edit(n.rules)}close(){this.id.value=void 0,this.view.reset(),this.sessions.reset(),this.preview.reset(),this.tried.reset(),this.draft.value=void 0,this.secret.value=``}edit(e){this.draft.value=e,this.preview.load(()=>this.#e.previewMcp.call({rules:e}),`Couldn't preview these rules.`,this.preview.value.value!==void 0)}revert(){let e=this.view.value.value;e!==void 0&&this.edit(e.rules)}async update(e={}){let t=this.id.value;if(t===void 0)return{ok:!1,problem:`No MCP is open.`};let n=e.rules??this.draft.value,r=await this.save.run(()=>this.#e.updateMcp.call({mcp:t,...e,...n===void 0?{}:{rules:n}}),`Couldn't save the MCP.`);return r.ok&&(this.view.set(r.value),this.draft.value=r.value.rules),r}async rotateSecret(){let e=this.id.value;if(e===void 0)return{ok:!1,problem:`No MCP is open.`};let t=await this.rotate.run(()=>this.#e.rotateMcpSecret.call({mcp:e}),`Couldn't rotate the secret.`);return t.ok&&(this.secret.value=t.value.secret,this.sessions.set([])),t}async delete(){let e=this.id.value;if(e===void 0)return!1;let t=await this.remove.run(()=>this.#e.deleteMcp.call({mcp:e}),`Couldn't delete the MCP.`);return t.ok&&t.value.ok}async loadSessions(e=!1){let t=this.id.value;t!==void 0&&await this.sessions.load(()=>this.#e.mcpSessions.call({mcp:t}),`Couldn't load this MCP's sessions.`,e)}async tryIt(e){let t=this.view.value.value,n=e.trim()===``?this.secret.value:e.trim();t!==void 0&&n!==``&&await this.tried.load(()=>this.#t.tools(t.url,n),`Couldn't reach the MCP with that secret.`)}};async function Ys(e,t,n,r,i,a){let o=n.type===``?`application/octet-stream`:n.type,{url:s,upload:c}=await e.upload.call({name:r,mime:o,size:n.size});return await t.put(s,n,i,a),e.uploaded.call({upload:c})}var Xs={make:e=>e.type.startsWith(`image/`)?URL.createObjectURL(e):void 0,revoke:e=>{URL.revokeObjectURL(e)}},Zs=class{#e;#t;#n;#r=new Map;#i=1;items=L([]);busy=k(()=>this.items.value.some(e=>e.status===`uploading`));parts=k(()=>this.items.value.flatMap(e=>e.ref===void 0?[]:[{type:`file`,ref:e.ref,name:e.name}]));constructor(e,t,n=Xs){this.#e=e,this.#t=t,this.#n=n}add(e){for(let t of e){let e=this.#i++,n=this.#n.make(t);this.#r.set(e,{file:t,abort:new AbortController}),this.items.value=[...this.items.value,{id:e,name:t.name===``?`pasted file`:t.name,size:t.size,mime:t.type,status:`uploading`,progress:0,...n===void 0?{}:{preview:n}}],this.#a(e)}}remove(e){this.#r.get(e)?.abort.abort(),this.#r.delete(e);let t=this.items.value.find(t=>t.id===e);t?.preview!==void 0&&this.#n.revoke(t.preview),this.items.value=this.items.value.filter(t=>t.id!==e)}retry(e){let t=this.#r.get(e);t!==void 0&&(this.#r.set(e,{file:t.file,abort:new AbortController}),this.#o(e,{status:`uploading`,progress:0}),this.#a(e))}clear(){for(let e of[...this.#r.keys()])this.remove(e)}async#a(e){let t=this.#r.get(e);if(t!==void 0)try{let n=await Ys(this.#e,this.#t,t.file,t.file.name===``?`pasted file`:t.file.name,t=>{this.#o(e,{progress:t})},t.abort.signal);this.#o(e,{status:`ready`,progress:1,ref:n})}catch(t){if(!this.#r.has(e))return;this.#o(e,{status:`failed`,problem:X(t,t instanceof Error?t.message:`Upload failed.`)})}}#o(e,t){this.items.value=this.items.value.map(n=>n.id===e?{...n,...t}:n)}};function Qs(e){return/\.zip$/i.test(e.name)}var $s=class{#e;#t;install=new U;progress=I(0);#n;constructor(e,t){this.#e=e,this.#t=t}async installZip(e,t){if(!Qs(e))return{ok:!1,problem:`A package is a .zip made by harness system pack.`};let n=t.instance.trim();if(n!==``&&!vn.safeParse(n).success)return{ok:!1,problem:`An instance name is lowercase letters, digits and dashes, starting with a letter.`};this.#n=new AbortController;let r=this.#n.signal;return this.progress.value=0,this.install.run(async()=>{let i=await Ys(this.#e,this.#t,e,e.name,e=>{this.progress.value=e},r),a=t.data===void 0?void 0:await Ys(this.#e,this.#t,t.data,t.data.name,()=>void 0,r);return this.#e.installPackage.call({zip:i,autoStart:t.autoStart,...n===``?{}:{instance:vn.parse(n)},...t.config===void 0?{}:{config:t.config},...a===void 0?{}:{data:a},...t.store===void 0?{}:{store:t.store}})},`Couldn't install that package.`)}cancel(){this.#n?.abort()}},ec=2e3;function tc(e){return e!==void 0&&e.phase!==`done`&&e.phase!==`failed`}function nc(e){let t=e?.status?.state;return e?.holding===!0||t===`preparing`||t===`migrating`||t===`moving`||tc(e?.move)}var rc=class{#e;view=new W;moveTask=new U;answering=new U;deleting=new U;deletedNote=I(``);#t;#n;constructor(e){this.#e=e}async open(e,t,n=!1){let r=this.#t?.system!==e||this.#t.instance!==t;r&&this.close(),this.#t={system:e,instance:t},await this.view.load(()=>this.#e.systemStore.call({system:e,...t===void 0?{}:{instance:t}}),`Couldn't read its storage.`,n&&!r),this.#a()}async refresh(){this.#t!==void 0&&await this.open(this.#t.system,this.#t.instance,!0)}async move(e){if(this.#t===void 0)return{ok:!1,problem:`No store is open.`};let t=await this.moveTask.run(()=>this.#e.systemStoreMove.call({...this.#r(),to:e}),`Couldn't start the move.`);return t.ok&&this.#i(t.value),this.refresh(),t}async answer(e){let t=await this.answering.run(()=>this.#e.systemStoreMoveAnswer.call({...this.#r(),answer:e}),`Couldn't answer the move.`);return t.ok&&this.#i(t.value),this.refresh(),t}async deleteBackup(e){this.deletedNote.value=``;let t=await this.deleting.run(()=>this.#e.systemStoreBackupDelete.call({...this.#r(),backup:e}),`Couldn't delete that backup.`);if(!t.ok)return!1;this.deletedNote.value=t.value.note??``;let n=this.view.value.value;return n!==void 0&&this.view.set({...n,backups:n.backups.filter(t=>t.id!==e)}),this.refresh(),!0}close(){this.#n!==void 0&&clearTimeout(this.#n),this.#n=void 0,this.#t=void 0,this.deletedNote.value=``,this.view.reset()}#r(){let e=this.#t;if(e===void 0)throw Error(`no store is open`);return{system:e.system,...e.instance===void 0?{}:{instance:e.instance}}}#i(e){let t=this.view.value.value;t!==void 0&&this.view.set({...t,move:e}),this.#a()}#a(){this.#n!==void 0&&clearTimeout(this.#n),this.#n=void 0,this.#t!==void 0&&nc(this.view.value.value)&&(this.#n=setTimeout(()=>{this.refresh()},ec))}},Q={hub:`Hub`,group:`Group`,user:`Person`,session:`Chat`,turn:`Message`,system:`System`,fn:`Fn`,model:`Model`},ic=[`hub`,`group`,`user`,`session`,`system`,`fn`,`model`],ac=[`hub`,`group`,`user`,`session`,`turn`],oc={urgent:`Urgent`,interactive:`Interactive`,normal:`Normal`,background:`Background`};function sc(e,t){switch(e.scope){case`hub`:return`Whole hub`;case`group`:return`${Q.group}: ${t(e.group)}`;case`user`:return`${Q.user}: ${t(e.user)}`;case`session`:return`${Q.session}: ${e.session}`;case`turn`:return`${Q.turn}: ${e.turn}`;case`system`:return`${Q.system}: ${e.system}`;case`fn`:return`${Q.fn}: ${J(e.fn)}`;case`model`:return`${Q.model}: ${e.model}`}}var cc=[{label:`Hour`,ms:36e5},{label:`Day`,ms:864e5},{label:`Week`,ms:6048e5},{label:`30 days`,ms:2592e6}];function lc(e){if(e===`all-time`)return`all time`;if(e===`per-turn`)return`per message`;let t=cc.find(t=>t.ms===e.window);return t===void 0?`per ${z(e.window)}`:`per ${t.label.toLowerCase()}`}var uc={refuse:`Refuses`,wait:`Waits for room`,ask:`Asks to raise it`};function dc(e){let t=e.maxCost<=0?1:Math.min(1,Math.max(0,e.spent/e.maxCost));return{fraction:t,tone:t>=1?`danger`:t>=.8?`warn`:`ok`}}function fc(e){let t=[`${B(e.maxCost)} ${lc(e.period)}`];return e.maxTokens!==void 0&&t.push(`${e.maxTokens.toLocaleString()} tokens`),e.maxCalls!==void 0&&t.push(`${e.maxCalls.toLocaleString()} calls`),e.maxTime!==void 0&&t.push(`${z(e.maxTime)} each`),t.join(` · `)}function pc(e){let t=`${Q[e.priorityFrom.default].toLowerCase()} default`,n=e.priorityFrom.cappedBy===void 0?``:`, capped by the ${Q[e.priorityFrom.cappedBy].toLowerCase()}`;return{priority:`${oc[e.priority]}, from the ${t}${n}.`,turn:`Each message may spend up to ${B(e.turn.cost)} and run for ${z(e.turn.time)}.`,tightest:e.limitedBy===void 0?-1:e.budgets.findIndex(t=>t.rule===e.limitedBy)}}var mc={setBudget:An.endpoints.setBudget.cfg.body,setPriority:An.endpoints.setPriority.cfg.body,setPolicy:An.endpoints.setPolicy.cfg.body,setModelCategory:An.endpoints.setModelCategory.cfg.body,createPairingToken:An.endpoints.createPairingToken.cfg.body,upgradeSystem:An.endpoints.upgradeSystem.cfg.body},hc=e=>e.trim()===``?void 0:Number(e),gc=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``)),_c=e=>e===void 0?``:String(e),vc={group:`group`,user:`user`};function yc(e){return e.level===`hub`?{scope:`hub`}:{scope:e.level,[e.level]:e.target.trim()}}function bc(e){let t=e[e.scope];return{level:e.scope,target:typeof t==`string`?t:``}}function xc(e){let t=e?.period;return{scope:e===void 0?{level:`hub`,target:``}:bc(e.target),period:t===void 0||typeof t==`object`?`window`:t,window:t!==void 0&&typeof t==`object`?t.window:cc[1].ms,maxCost:e===void 0?``:String(e.maxCost),maxTokens:_c(e?.maxTokens),maxCalls:_c(e?.maxCalls),maxTime:e?.maxTime===void 0?``:String(e.maxTime/1e3),share:e?.share??`pooled`,onLimit:e?.onLimit??`refuse`}}function Sc(e){let t=e.period===`window`?{window:e.window}:e.period,n=hc(e.maxTime);return Z(mc.setBudget,gc({target:yc(e.scope),period:t,maxCost:hc(e.maxCost)??NaN,maxTokens:hc(e.maxTokens),maxCalls:hc(e.maxCalls),maxTime:e.period===`per-turn`&&n!==void 0?Math.round(n*1e3):void 0,share:e.scope.level===`group`?e.share:void 0,onLimit:e.onLimit}))}function Cc(e){return{scope:e===void 0?{level:`hub`,target:``}:bc(e.target),default:e?.default??``,max:e?.max??``}}function wc(e){return e.default===``&&e.max===``?{ok:!1,problems:{default:`Set a default, a ceiling, or both.`}}:Z(mc.setPriority,gc({target:yc(e.scope),default:e.default,max:e.max}))}function Tc(e){let t=e?.subject,n=e?.decision,r=n?.effect===`ask`?n.approver:void 0;return{description:e?.description??``,subject:t===void 0||`everyone`in t?`everyone`:`actor`in t?`actor`:`group`in t?`group`:`kind`,subjectValue:t===void 0||`everyone`in t?``:`actor`in t?t.actor:`group`in t?t.group:t.kind,fn:e?.target.fn??``,system:e?.target.system??``,kind:e?.target.kind??``,tags:[...e?.target.tags??[]],effect:n?.effect??`ask`,reason:n?.effect===`deny`?n.reason:``,approver:r?.by??`turn-user`,approverValue:r===void 0?``:r.by===`actor`?r.actor:r.by===`group`?r.group:r.by===`judge`?r.fn:``,quorum:r?.by===`group`?_c(r.quorum):``,priority:String(e?.priority??0)}}function Ec(e){let t=e.subjectValue.trim(),n=e.subject===`everyone`?{everyone:!0}:{[e.subject]:t},r=e.tags.map(e=>e.trim()).filter(e=>e!==``),i=gc({fn:e.fn.trim(),system:e.system.trim(),kind:e.kind.trim(),tags:r.length===0?void 0:r}),a=e.approverValue.trim(),o=e.approver===`actor`?{by:`actor`,actor:a}:e.approver===`group`?gc({by:`group`,group:a,quorum:hc(e.quorum)}):e.approver===`judge`?{by:`judge`,fn:a}:{by:e.approver},s=e.effect===`allow`?{effect:`allow`}:e.effect===`deny`?{effect:`deny`,reason:e.reason.trim()}:{effect:`ask`,approver:o};return e.effect===`deny`&&e.reason.trim()===``?{ok:!1,problems:{decision:`Say why, for the people it stops.`}}:e.description.trim()===``?{ok:!1,problems:{description:`Required.`}}:Z(mc.setPolicy,{description:e.description.trim(),subject:n,target:i,decision:s,priority:hc(e.priority)??0})}function Dc(e){return{name:e?.name??``,description:e?.description??``,models:e?.models??[]}}function Oc(e){return e.name.trim()===``?{ok:!1,problems:{name:`Required.`}}:e.models.length===0?{ok:!1,problems:{models:`Add at least one model.`}}:Z(mc.setModelCategory,{name:e.name.trim(),description:e.description.trim(),models:[...e.models]})}var kc=[{value:`keys`,label:`Access keys`},{value:`apiKey`,label:`API key`}],Ac={apiKey:{label:`API key`,secret:!0},baseURL:{label:`Base URL`,secret:!1},contextWindow:{label:`Context window (tokens)`,secret:!1,kind:`number`},decisionModels:{label:`Decision models`,secret:!1,kind:`list`,placeholder:`qwen3-systemone`,hint:`System One models to treat as decision models, comma separated. Only needed when the server’s /api/show lists no capabilities; newer servers say so themselves.`},region:{label:`Region`,secret:!1,placeholder:`us-east-1`},accessKeyId:{label:`Access key ID`,secret:!1},secretAccessKey:{label:`Secret access key`,secret:!0},sessionToken:{label:`Session token`,secret:!0,hint:`Only for temporary credentials.`},profilePrefix:{label:`Inference profile prefix`,secret:!1,placeholder:`us.`,hint:`Left empty, one is picked for the region.`}},jc={openai:`OpenAI`,anthropic:`Anthropic`,google:`Google Gemini`,openrouter:`OpenRouter`,ollama:`Ollama`,aws:`Amazon Bedrock`};function Mc(e){let t=pn.safeParse(e);return t.success?jc[t.data]:e}var Nc=e=>e in Ac;function Pc(e){let t=Zn.options.find(t=>t.shape.provider.value===e);if(t===void 0)throw Error(`No provider input schema for ${e}`);return t}function Fc(e){let t=Pc(`aws`).shape;if(!(`auth`in t))throw Error(`The AWS provider input has no sign-in`);let n=t.auth.options.find(t=>t.shape.kind.value===e);if(n===void 0)throw Error(`No AWS sign-in schema for ${e}`);return n}function Ic(e){return Object.entries(e).flatMap(([e,t])=>Nc(e)?[{name:e,...Ac[e],required:!t.safeParse(void 0).success}]:[])}function Lc(e,t=`keys`){let n=Pc(e).shape;if(e!==`aws`)return Ic(n);let r=Ic(n);return[...r.filter(e=>e.name===`region`),...Ic(Fc(t).shape),...r.filter(e=>e.name!==`region`)]}function Rc(e,t,n=`keys`){let r=e=>gc(Object.fromEntries(e.map(e=>[e.name,zc(e,t[e.name])]))),i=e===`aws`?Ic(Fc(n).shape):[],a=Lc(e,n).filter(e=>!i.includes(e)),o=e===`aws`?{provider:e,...r(a),auth:{kind:n,...r(i)}}:{provider:e,...r(a)},s=Z(Pc(e),o);if(s.ok)return{ok:!0,value:s.value};let c={},l=e===`aws`&&`auth`in s.problems?{...s.problems,...Bc(n,o)}:s.problems;for(let[e,t]of Object.entries(l))Nc(e)&&(c[e]=t);return{ok:!1,problems:c}}function zc(e,t){let n=t?.trim();if(n!==void 0&&n!==``){if(e.kind===`number`)return Number(n);if(e.kind===`list`){let e=n.split(/[,\n]/).map(e=>e.trim()).filter(e=>e!==``);return e.length===0?void 0:e}return n}}function Bc(e,t){let n=Z(Fc(e),t.auth);return n.ok?{}:n.problems}var Vc=[`package`,`path`,`git`];function Hc(e){let t=_n.options.find(t=>e in t.shape);if(t===void 0)throw Error(`No install source schema for ${e}`);return t}function Uc(e){return Object.keys(Hc(e).shape).filter(Gc)}var Wc={package:!0,version:!0,path:!0,git:!0,ref:!0,zip:!0,file:!0},Gc=e=>Object.hasOwn(Wc,e);function Kc(e){let t=Uc(e.kind),n=Object.fromEntries(t.map(t=>[t,(e.fields[t]??``).trim()])),r=Z(Hc(e.kind),n),i=r.ok?{}:r.problems,a={};for(let e of t){let t=n[e]===``?`Required.`:i[e];t!==void 0&&(a[e]=t)}return r.ok&&Object.keys(a).length===0?{ok:!0,value:r.value}:{ok:!1,problems:a}}var qc=[{label:`15 minutes`,ms:9e5},{label:`1 hour`,ms:36e5},{label:`1 day`,ms:864e5}],Jc=[{label:`90 days`,ms:7776e6},{label:`30 days`,ms:2592e6},{label:`1 year`,ms:31536e6},{label:`Never ends`,ms:null}];function Yc(e){return e===void 0?{}:{autoPair:e}}function Xc(e,t){let n=e.trim(),r=Z(mc.createPairingToken,n===``?{expiresIn:t}:{name:n,expiresIn:t});return r.ok?r:{ok:!1,problems:{...r.problems,...r.problems.name===void 0?{}:{name:`Lowercase letters, digits and dashes, starting with a letter.`}}}}var Zc=class{#e;#t;#n;#r;request=new W;answer=new U;system=I(void 0);status=L(void 0);#i=I(void 0);phase=k(()=>{if(this.#i.value===`refused`)return`refused`;if(this.answer.busy.value)return`pairing`;if(this.#i.value===`approved`)return this.status.value===`connected`?`connected`:this.status.value===`needs-config`?`needs-config`:`joining`;let e=this.request.value.value;return e===void 0?`loading`:e.status===`expired`||e.expiresAt<=this.#n()?`expired`:e.status===`pending`?`waiting`:`elsewhere`});constructor(e,t,n=Date.now){this.#e=e,this.#t=t,this.#n=n}async open(e){this.request.value.value?.id!==e&&this.close(),this.#r??=this.#t(e=>{this.#a(e)}),await this.request.load(()=>this.#e.pairing.call({pairing:e}),`Couldn't load this pairing request. It may have expired or been answered.`)}close(){this.#r?.(),this.#r=void 0,this.request.reset(),this.system.value=void 0,this.status.value=void 0,this.#i.value=void 0}codeMatches(e){let t=this.request.value.value;return t===void 0?!1:t.code===void 0||t.code===e.trim()}async approve(e,t,n,r){let i=this.request.value.value;if(i===void 0)return{ok:!1,problem:`No pairing request is open.`};let a=await this.answer.run(()=>this.#e.approvePairing.call({pairing:i.id,approve:!0,...e===void 0?{}:{instance:e},...t===void 0?{}:{config:t},...Yc(n),...r===void 0?{}:{store:r}}),`Couldn't pair it.`);return a.ok&&(this.#i.value=`approved`,this.system.value=a.value.system??i.name,this.status.value??=`pairing`),a}async refuse(){let e=this.request.value.value;if(e===void 0)return!1;let t=await this.answer.run(()=>this.#e.approvePairing.call({pairing:e.id,approve:!1}),`Couldn't refuse it.`);return t.ok&&(this.#i.value=`refused`),t.ok}#a(e){let t=this.request.value.value;if(e.type===`pairing`&&t!==void 0&&e.pairing.id===t.id){this.request.set(e.pairing);return}let n=this.system.value??t?.name;e.type===`system`&&e.system===n&&(this.status.value=e.status)}},Qc=class{#e;budgets=new W;priorities=new W;resolved=new W;save=new U;remove=new U;constructor(e){this.#e=e}async load(e=!1){await Promise.all([this.#t(e),this.#n(e)])}async saveBudget(e){let t=await this.save.run(()=>this.#e.setBudget.call(e),`Couldn't save the budget.`);return t.ok&&this.#t(!0),t}async savePriority(e){let t=await this.save.run(()=>this.#e.setPriority.call(e),`Couldn't save the priority rule.`);return t.ok&&this.#n(!0),t}async removeBudget(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`budget`,id:e}),`Couldn't remove the budget.`);return t.ok&&this.budgets.set((this.budgets.value.value??[]).filter(t=>t.id!==e)),t.ok}async removePriority(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`priority`,id:e}),`Couldn't remove the priority rule.`);return t.ok&&this.priorities.set((this.priorities.value.value??[]).filter(t=>t.id!==e)),t.ok}async resolve(e,t){await this.resolved.load(()=>this.#e.resolveLimits.call({user:e,...t===void 0?{}:{session:t}}),`Couldn't work out the limits.`)}#t(e){return this.budgets.load(()=>this.#e.budgets.call({}),`Couldn't load budgets.`,e)}#n(e){return this.priorities.load(()=>this.#e.priorityRules.call({}),`Couldn't load priority rules.`,e)}},$c=class{#e;providers=new W;models=new W;categories=new W;save=new U;remove=new U;modelIds=k(()=>(this.models.value.value??[]).map(e=>e.id).sort());constructor(e){this.#e=e}async load(e=!1){await Promise.all([this.providers.load(()=>this.#e.providers.call({}),`Couldn't load providers.`,e),this.models.load(()=>this.#e.models.call({}),`Couldn't load models.`,e),this.categories.load(()=>this.#e.modelCategories.call({}),`Couldn't load model categories.`,e)])}async saveProvider(e){let t=await this.save.run(()=>this.#e.configureProvider.call(e),`Couldn't save the provider.`);return t.ok&&this.load(!0),t}async saveCategory(e){let t=await this.save.run(()=>this.#e.setModelCategory.call(e),`Couldn't save the category.`);return t.ok&&this.categories.load(()=>this.#e.modelCategories.call({}),`Couldn't load model categories.`,!0),t}async removeCategory(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`category`,id:e}),`Couldn't remove the category.`);return t.ok&&this.categories.set((this.categories.value.value??[]).filter(t=>t.id!==e)),t.ok}async removeProvider(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`provider`,id:e}),`Couldn't remove the provider.`);return t.ok&&this.load(!0),t.ok}},el={user:{plural:`people`,label:`People`},group:{plural:`groups`,label:`Groups`},agent:{plural:`agents`,label:`Agents`},system:{plural:`systems`,label:`Systems`},mcp:{plural:`MCP clients`,label:`MCP clients`}};function tl(e,t){return`actor`in e?t(e.actor):`group`in e?`Group ${t(e.group)}`:`kind`in e?`All ${el[e.kind].plural}`:`Everyone`}function nl(e){let t=[];if(e.fn!==void 0){let n=$n.safeParse(e.fn);t.push(n.success&&!e.fn.includes(`*`)?J(n.data):e.fn)}return e.system!==void 0&&t.push(`fns of ${e.system}`),e.kind!==void 0&&t.push(e.kind===`native`?`native fns`:`${e.kind} fns`),e.tags!==void 0&&e.tags.length>0&&t.push(`tagged ${e.tags.join(`, `)}`),e.when!==void 0&&t.push(`when its args match`),t.length===0?`any fn`:t.join(`, `)}function rl(e,t){switch(e.by){case`turn-user`:return`the message's sender`;case`actor`:return t(e.actor);case`group`:return`group ${t(e.group)}${e.quorum===void 0?``:` (${e.quorum} needed)`}`;case`judge`:return`the judge ${J(e.fn)}`;case`hub`:return`the hub`;case`admins`:return`an admin`}}function il(e,t){switch(e.effect){case`allow`:return{word:`Allow`,detail:`runs without asking`,tone:`ok`};case`deny`:return{word:`Deny`,detail:e.reason,tone:`danger`};case`ask`:return{word:`Ask`,detail:`asks ${rl(e.approver,t)}`,tone:`warn`}}}function al(e){let t={deny:0,ask:1,allow:2};return[...e].sort((e,n)=>n.priority-e.priority||t[e.decision.effect]-t[n.decision.effect])}var ol=class{#e;list=new W;sorted=k(()=>al(this.list.value.value??[]));save=new U;remove=new U;constructor(e){this.#e=e}async load(e=!1){await this.list.load(()=>this.#e.policies.call({}),`Couldn't load policies.`,e)}async savePolicy(e){let t=await this.save.run(()=>this.#e.setPolicy.call(e),`Couldn't save the policy.`);return t.ok&&this.load(!0),t}async removePolicy(e){let t=await this.remove.run(()=>this.#e.removeRule.call({kind:`policy`,id:e}),`Couldn't remove the policy.`);return t.ok&&this.list.set((this.list.value.value??[]).filter(t=>t.id!==e)),t.ok}},sl=class{#e;users;groups;person=new W;members=new W;signIn=new W;checks=L(new Map);checking=L(void 0);test=new W;save=new U;constructor(e){this.#e=e,this.users=new f({fetch:(t,n,r)=>e.people.call(h(t,r,n)),key:e=>e.id,failure:`Couldn’t load the people.`,limit:50},{}),this.groups=new f({fetch:(t,n,r)=>e.groups.call(h(t,r,n)),key:e=>e.id,failure:`Couldn’t load the groups.`,limit:50},{})}openPerson(e,t=!1){return this.person.load(async()=>(await this.#e.people.call({filters:[{field:`email`,op:`is`,value:e}],limit:1})).items[0],`Couldn’t load them.`,t)}openGroup(e,t=!1){return this.members.load(()=>this.#e.groupMembers.call({group:e,limit:200}),`Couldn’t load the group.`,t)}loadSignIn(e=!1){return this.signIn.load(()=>this.#e.signInSettings.call({}),`Couldn’t load how people sign in.`,e)}loadTest(e){return this.test.load(()=>this.#e.ssoTestResult.call({test:e}),`Couldn’t read the test sign-in.`)}async check(e){this.checking.value=e;try{let t=await this.#e.checkSsoProvider.call({provider:e});this.checks.value=new Map([...this.checks.value,[e,t]])}catch(t){let n=t instanceof Error?t.message:String(t);this.checks.value=new Map([...this.checks.value,[e,{provider:e,ok:!1,discovery:{ok:!1,detail:n},keys:{ok:!1,detail:`Not checked.`},checkedAt:Date.now()}]])}finally{this.checking.value=void 0}}startTest(e){return this.save.run(()=>this.#e.testSsoSignIn.call({provider:e}),`Couldn’t start the test sign-in.`)}addPerson(e){let t={name:e.name,email:e.email,role:e.role,...e.groups===void 0?{}:{groups:[...e.groups]}};return this.#t(this.save.run(()=>this.#e.addUser.call(t),`Couldn’t add them.`))}addGroup(e){return this.#t(this.save.run(()=>this.#e.addGroup.call(e),`Couldn’t add the group.`))}update(e){return this.#t(this.save.run(()=>this.#e.updateUser.call(e),`Couldn’t change them.`))}membership(e){return this.#t(this.save.run(()=>this.#e.setMembership.call(e),`Couldn’t change the group.`))}async setPolicy(e){let t=await this.save.run(()=>this.#e.setSignInPolicy.call(e),`Couldn’t save who can join.`);return t.ok&&this.loadSignIn(!0),t}async setLimits(e){let t=await this.save.run(()=>this.#e.setSignInLimits.call(e),`Couldn’t save the sign-in limits.`);return t.ok&&this.loadSignIn(!0),t}async setProxy(e){let t=await this.save.run(()=>this.#e.setProxyTrust.call(e),`Couldn’t save the proxy setting.`);return t.ok&&this.loadSignIn(!0),t}async#t(e){let t=await e;if(!t.ok)return t;this.users.refresh(),this.groups.refresh();let n=this.person.value.value;n!==void 0&&this.openPerson(n.email,!0);let r=this.members.value.value?.group;return r!==void 0&&this.openGroup(r.id,!0),t}};function cl(e,t,n){let r=e??[];return r.some(e=>n(e,t))?r.map(e=>n(e,t)?t:e):[...r,t]}var ll=class{#e;roles=new W;limits=new W;save=new U;constructor(e){this.#e=e}async loadRoles(e=!1){await this.roles.load(()=>this.#e.modelRoles.call({}),`Couldn't load the model roles.`,e)}async loadLimits(e=!1){await this.limits.load(()=>this.#e.modelLimits.call({}),`Couldn't load the model limits.`,e)}role(e){return this.roles.value.value?.find(t=>t.role===e)}async setRole(e){let t=await this.save.run(()=>this.#e.setModelRole.call(e),`Couldn't save that role.`);return t.ok&&this.roles.set(cl(this.roles.value.value,t.value,(e,t)=>e.role===t.role)),t}async clearRole(e){let t=await this.save.run(()=>this.#e.clearModelRole.call({role:e}),`Couldn't clear that role.`);return t.ok&&this.roles.set(cl(this.roles.value.value,t.value,(e,t)=>e.role===t.role)),t}async setLimits(e,t){let n=await this.save.run(()=>this.#e.setModelLimits.call({model:e,limits:t}),`Couldn't save the limits of ${e}.`);return n.ok&&this.limits.set(cl(this.limits.value.value,n.value,(e,t)=>e.model===t.model)),n}},ul=class{#e;data=new W;save=new U;groups=k(()=>{let e=this.data.value.value;if(e===void 0)return[];let t=new Map;for(let n of[...e.declared].sort((e,t)=>e.setting.localeCompare(t.setting))){let r={view:n,values:e.values.filter(e=>e.setting===n.setting)};t.set(n.system,[...t.get(n.system)??[],r])}return[...t].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({system:e,settings:t}))});constructor(e){this.#e=e}async load(e=!1){await this.data.load(()=>this.#e.actorSettings.call({}),`Couldn't load actor settings.`,e)}async set(e,t,n,r,i){let a=await this.save.run(()=>this.#e.setActorSetting.call({setting:e,actor:t,value:n}),`Couldn't save the setting.`),o=this.data.value.value;if(!a.ok||!a.value.ok||o===void 0)return a.ok&&a.value.ok;let s={setting:e,actor:t,value:n,setBy:r,updatedAt:i};return this.data.set({...o,values:[...o.values.filter(n=>n.setting!==e||n.actor!==t),s]}),!0}},dl=class{#e;review=new W;refusals;switching=new U;deciding=new U;decidingChange=I(void 0);testing=new U;off=k(()=>Kr(this.review.value.value?.off??[]));constructor(e){this.#e=e,this.refusals=new f({fetch:async({system:e,rule:t},n,r)=>{if(e===void 0)return{items:[]};let i=await this.#e.refusals.call({system:e,limit:r,...t===void 0?{}:{rule:t},...n===void 0?{}:{cursor:n}});return{items:i.items,...i.next===void 0?{}:{cursor:i.next}}},key:e=>e.id,failure:`Couldn't load the refusals.`,limit:50},{system:void 0,rule:void 0})}async open(e){let t=this.review.value.value?.system===e;t||this.review.reset(),await this.review.load(()=>this.#e.systemReview.call({system:e}),`Couldn't load this system's review.`,t)}async loadRefusals(e,t){await this.refusals.load({system:e,rule:t})}isOn(e){return!this.off.value.has(Gr(e))}async switch(e,t){let n=this.review.value.value;if(n===void 0)return!1;let r=n.off;this.review.set({...n,off:Jr(r,e,t)});let i=await this.switching.run(()=>this.#t(n.system,e,t),`Couldn't switch that.`);if(!i.ok){let n=this.review.value.value;n!==void 0&&this.review.set({...n,off:Jr(n.off,e,!t)})}return i.ok}async#t(e,t,n){let{section:r,name:i}=t;r===`fns`||r===`context`?await this.#e.switchItem.call({section:r,name:$n.parse(i),on:n}):await this.#e.switchPart.call({system:e,section:r,name:i,on:n})}#n(e){let t=this.review.value.value;return t===void 0?void 0:{system:t.system,hash:e,off:t.off}}async goLive(){let e=this.review.value.value,t=e===void 0?void 0:this.#n(e.manifest.hash);if(e===void 0||t===void 0)return{ok:!1,problem:`No system is open.`};let n=await this.deciding.run(()=>this.#e.goLive.call(t),`Couldn't go live.`);return this.open(e.system),n.ok?{ok:!0,value:n.value.stage}:n}async approve(){let e=this.review.value.value,t=e?.pending,n=t===void 0?void 0:this.#n(t.hash);if(e===void 0||n===void 0)return{ok:!1,problem:`Nothing waits for review.`};let r=await this.deciding.run(()=>this.#e.approveReview.call(n),`Couldn't approve the changes.`);return this.open(e.system),r.ok?{ok:!0,value:r.value.hash}:r}async decide(e,t){let n=this.review.value.value,r=n?.pending;if(n===void 0||r===void 0)return{ok:!1,problem:`Nothing waits for review.`};this.decidingChange.value=Yr(e);let i=qr(e),a={system:n.system,hash:r.hash,approve:t===`approve`?[i]:[],decline:t===`decline`?[i]:[],off:[]};try{let e=await this.deciding.run(()=>this.#e.decideReview.call(a),t===`approve`?`Couldn't approve that change.`:`Couldn't decline that change.`);return await this.open(n.system),e}finally{this.decidingChange.value=void 0}}async reject(){let e=this.review.value.value,t=e?.pending;if(e===void 0||t===void 0)return{ok:!1,problem:`Nothing waits for review.`};let n=await this.deciding.run(()=>this.#e.rejectReview.call({system:e.system,hash:t.hash}),`Couldn't reject the changes.`);return this.open(e.system),n.ok?{ok:!0,value:n.value.ok}:n}async testCall(e,t){let n=await this.testing.run(()=>this.#e.testCall.call({fn:e,args:t}),`Couldn't run that.`);return n.ok?{ok:!0,value:n.value.run}:n}close(){this.review.reset(),this.refusals.load({system:void 0,rule:void 0})}},fl=1e3,pl=`Restarted by an admin from its page`,ml=class{#e;#t;#n;#r;#i;name=I(void 0);view=new W;fns=new W;logs=new W;config=new U;enabling=new U;switching=new U;action=new U;acting=L(void 0);constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}async open(e){this.name.value!==e&&(this.close(),this.name.value=e),this.#r??=this.#t(e=>{this.#o(e)}),await this.view.load(()=>this.#e.system.call({system:e}),`Couldn't load this system.`,this.view.value.value?.name===e)}close(){this.#r?.(),this.#r=void 0,this.unfollowLogs(),this.name.value=void 0,this.view.reset(),this.fns.reset(),this.logs.reset()}async loadFns(){let e=this.name.value;e!==void 0&&await this.fns.load(()=>this.#e.systemFns.call({system:e}),`Couldn't load this system's fns.`)}fnSwitched(e,t){let n=this.fns.value.value;n!==void 0&&this.fns.set(n.map(n=>n.name===e?{...n,disabled:!t}:n))}async switchFn(e,t){if(this.fnSwitched(e,t),!(await this.switching.run(()=>this.#e.switchItem.call({section:`fns`,name:e,on:t}),`Couldn't switch that.`)).ok)return this.fnSwitched(e,!t),!1;let n=this.name.value;return n!==void 0&&await this.fns.load(()=>this.#e.systemFns.call({system:n}),`Couldn't load this system's fns.`,!0),!0}async followLogs(){let e=this.name.value;e!==void 0&&(this.#i??=this.#n(e,e=>{let t=this.logs.value.value??[];this.logs.set([...t,e].slice(-1e3))}),await this.logs.load(()=>this.#e.systemLogs.call({system:e,limit:fl}),`Couldn't load this system's output.`))}unfollowLogs(){this.#i?.(),this.#i=void 0}async configure(e){let t=this.name.value;if(t===void 0)return{ok:!1,problems:[`No system is open.`]};let n=await this.config.run(()=>this.#e.configureSystem.call({system:t,config:e}),`Couldn't save the config.`);return n.ok?`problems`in n.value?{ok:!1,problems:n.value.problems}:(this.open(t),{ok:!0,version:n.value.version}):{ok:!1,problems:[n.problem]}}async enable(e,t){let n=this.name.value,r=this.view.value.value;if(n===void 0||r===void 0)return!1;this.view.set({...r,enabled:{...r.enabled,[e]:t}});let i=await this.enabling.run(()=>this.#e.enableSystem.call({system:n,[e]:t}),`Couldn't change that.`),a=this.view.value.value;return a===void 0||this.view.set({...a,enabled:i.ok?i.value.enabled:r.enabled}),i.ok}async act(e,t,n){let r=this.name.value;if(r===void 0)return{ok:!1,problem:`No system is open.`};this.acting.value=e;let i=await this.action.run(()=>this.#a(r,e,t,n),`Couldn't ${e} ${r}.`);return this.acting.value=void 0,i.ok&&e!==`remove`&&this.open(r),i}async#a(e,t,n,r){switch(t){case`start`:return await this.#e.startSystem.call({system:e}),{kind:`done`};case`stop`:return await this.#e.stopSystem.call({system:e}),{kind:`done`};case`restart`:return await this.#e.restartSystem.call({system:e,reason:pl}),{kind:`done`};case`upgrade`:return{kind:`upgrade`,...await this.#e.upgradeSystem.call({system:e,...n===void 0||n===``?{}:{version:n}})};case`reimport`:return{kind:`reimport`,report:await this.#e.reimport.call({system:e})};case`remove`:return await this.#e.removeSystem.call({system:e,...r===void 0?{}:{keepStore:r}}),{kind:`done`}}}#o(e){let t=this.view.value.value;if(t===void 0||e.type!==`system`&&e.type!==`fn`||e.system!==t.name)return;if(e.type===`system`){this.view.set({...t,status:e.status});return}let n=this.fns.value.value;n?.some(t=>t.name===e.fn)===!0&&this.fns.set(n.map(t=>t.name===e.fn?{...t,stats:e.stats}:t))}},hl=class{#e;#t;context;types;contextCount=I(void 0);typeCount=I(void 0);others=new W;roots=new W;switching=new U;constructor(e){this.#e=e,this.context=new f({fetch:async(e,t,n)=>{if(e===void 0)return{items:[]};let r=await this.#e.query.call(vr(e,t,n));return t===void 0&&(this.contextCount.value=r.total),{items:In.array().parse(r.items),...r.cursor===void 0?{}:{cursor:r.cursor}}},key:e=>e.name,failure:`Couldn't load this system's context.`,limit:50},void 0),this.types=new f({fetch:async(e,t,n)=>{if(e===void 0)return{items:[]};let r=await this.#e.query.call(Rs({system:e},t,n));return t===void 0&&(this.typeCount.value=r.total),{items:Pn.array().parse(r.items),...r.cursor===void 0?{}:{cursor:r.cursor}}},key:e=>e.name,failure:`Couldn't load this system's types.`,limit:50},void 0)}async loadContext(e){this.context.filter.value===e&&this.context.loaded.value?await this.context.refresh():(this.contextCount.value=void 0,await this.context.load(e))}async loadTypes(e){this.types.filter.value===e&&this.types.loaded.value?await this.types.refresh():(this.typeCount.value=void 0,await this.types.load(e))}async loadOthers(e){let t=this.#t===e&&this.others.value.value!==void 0;t||(this.others.reset(),this.roots.reset()),this.#t=e,await Promise.all([this.others.load(()=>this.#e.systemParts.call({system:e}),`Couldn't load what this system added.`,t),this.roots.load(()=>this.#e.exploreRoots.call({system:e}),`Couldn't load this system's resource roots.`,t)])}async switchContext(e,t){this.context.update(e,e=>({...e,status:t?`active`:`hidden`}));let n=await this.switching.run(()=>this.#e.switchItem.call({section:`context`,name:e,on:t}),`Couldn't switch that.`);return n.ok||this.context.update(e,e=>({...e,status:t?`hidden`:`active`})),n.ok}close(){this.others.reset(),this.roots.reset(),this.#t=void 0,this.context.load(void 0),this.types.load(void 0),this.contextCount.value=void 0,this.typeCount.value=void 0}},gl=class{#e;#t;#n;list=new W;pairings=new W;query=L({});sorted=k(()=>{let e=this.list.value.value??[];return this.query.value.sort===void 0?Cr(e):e});pending=k(()=>(this.pairings.value.value??[]).filter(e=>e.status===`pending`).length);answering=L(new Set);answer=new U;token=new U;install=new U;constructor(e,t){this.#e=e,this.#t=t}start(){this.#n??=this.#t(e=>{this.#i(e)})}stop(){this.#n?.(),this.#n=void 0}async load(e=!1){await Promise.all([this.#r(e),this.pairings.load(()=>this.#e.pairings.call({status:`pending`}),`Couldn't load pairing requests.`,e)])}async search(e){JSON.stringify(e)!==JSON.stringify(this.query.value)&&(this.query.value=e,await this.#r(!1))}async#r(e){let t=this.query.value;await this.list.load(()=>this.#e.systems.call(Object.keys(t).length===0?{}:{query:t}),`Couldn't load systems.`,e)}async answerPairing(e,t,n,r){this.answering.value=new Set([...this.answering.value,e]);let i=await this.answer.run(()=>this.#e.approvePairing.call({pairing:e,approve:t,...t?Yc(n):{},...t&&r!==void 0?{store:r}:{}}),t?`Couldn't approve the pairing.`:`Couldn't reject the pairing.`);return this.answering.value=new Set([...this.answering.value].filter(t=>t!==e)),i.ok&&(this.pairings.set((this.pairings.value.value??[]).filter(t=>t.id!==e)),t&&this.#r(!0)),i}async createToken(e,t,n){return this.token.run(()=>this.#e.createPairingToken.call({expiresIn:t,...e===void 0?{}:{name:e},...Yc(n)}),`Couldn't make a pairing token.`)}async installSystem(e,t,n,r){let i=await this.install.run(()=>this.#e.installSystem.call({source:e,autoStart:t,...n===void 0?{}:{config:n},...r===void 0?{}:{store:r}}),`Couldn't install the system.`);return i.ok&&this.load(!0),i}#i(e){if(e.type===`system`){let t=this.list.value.value;if(t===void 0)return;if(!t.some(t=>t.name===e.system)){this.load(!0);return}this.list.set(t.map(t=>t.name===e.system?{...t,status:e.status}:t))}else if(e.type===`pairing`){let t=e.pairing,n=(this.pairings.value.value??[]).filter(e=>e.id!==t.id);this.pairings.set(t.status===`pending`?[t,...n]:n)}}},_l=class{actors;systems;system;systemParts;review;models;roles;limits;policies;settings;runs;runApprovals;llm;modelCalls;fn;injected;itemInjected;instance;instanceParts;packages;storage;mcps;mcp;pairing;resources;fns;suggestions;classifier;images;autoPairs;people;constructor(e){let{api:t}=e;this.actors=new Ds(t),this.systems=new gl(t,e.userEvents),this.system=new ml(t,e.userEvents,e.systemLogs),this.systemParts=new hl(t),this.review=new dl(t),this.models=new $c(t),this.roles=new ll(t),this.limits=new Qc(t),this.policies=new ol(t),this.settings=new ul(t),this.runs=Ms(t,e.chat),this.runApprovals=new Os(e.chat),this.llm=Ns(t,e.chat),this.modelCalls=Ps(t,e.chat),this.fn=new Wi(t,e.userEvents),this.injected=new Mr(t),this.itemInjected=new Mr(t),this.instance=new Is(t,e.userEvents),this.instanceParts=new Ks(t,e.chat),this.packages=new $s(t,e.sender),this.storage=new rc(t),this.mcps=new qs(t),this.mcp=new Js(t,e.probe),this.pairing=new Zc(t,e.userEvents),this.resources=Fs(t,e.chat),this.suggestions=new ws(t),this.classifier=new Ts(t),this.images=new Es(t),this.autoPairs=new Cs(t),this.people=new sl(t),this.fns=new f({fetch:(e,n,r)=>t.fns.call({...e,limit:r,...n===void 0?{}:{cursor:n}}),key:e=>e.name,failure:`Couldn't load the fns.`,limit:50},{})}start(){this.systems.start(),this.systems.pairings.value.value===void 0&&this.systems.load(!0)}stop(){this.systems.stop(),this.system.close()}};function vl(e){return{systems:e.caller(`systems`,{dedupe:!0}),system:e.caller(`system`,{dedupe:!0}),pairings:e.caller(`pairings`,{dedupe:!0}),approvePairing:e.caller(`approvePairing`),createPairingToken:e.caller(`createPairingToken`),configureSystem:e.caller(`configureSystem`),enableSystem:e.caller(`enableSystem`),switchItem:e.caller(`switchItem`),switchPart:e.caller(`switchPart`),systemReview:e.caller(`systemReview`,{dedupe:!0}),goLive:e.caller(`goLive`),approveReview:e.caller(`approveReview`),rejectReview:e.caller(`rejectReview`),decideReview:e.caller(`decideReview`),testCall:e.caller(`testCall`),refusals:e.caller(`refusals`,{lastOnly:!0}),removeSystem:e.caller(`removeSystem`),installSystem:e.caller(`installSystem`),systemStore:e.caller(`systemStore`),systemStoreMove:e.caller(`systemStoreMove`),systemStoreMoveState:e.caller(`systemStoreMoveState`),systemStoreMoveAnswer:e.caller(`systemStoreMoveAnswer`),systemStoreBackups:e.caller(`systemStoreBackups`),systemStoreBackupDelete:e.caller(`systemStoreBackupDelete`),startSystem:e.caller(`startSystem`),stopSystem:e.caller(`stopSystem`),restartSystem:e.caller(`restartSystem`),upgradeSystem:e.caller(`upgradeSystem`),reimport:e.caller(`reimport`),systemFns:e.caller(`systemFns`,{dedupe:!0}),systemLogs:e.caller(`systemLogs`,{dedupe:!0}),systemParts:e.caller(`systemParts`,{dedupe:!0}),exploreRoots:e.caller(`exploreRoots`,{dedupe:!0}),providers:e.caller(`providers`,{dedupe:!0}),configureProvider:e.caller(`configureProvider`),models:e.caller(`models`,{dedupe:!0}),modelCategories:e.caller(`modelCategories`,{dedupe:!0}),setModelCategory:e.caller(`setModelCategory`),budgets:e.caller(`budgets`,{dedupe:!0}),setBudget:e.caller(`setBudget`),priorityRules:e.caller(`priorityRules`,{dedupe:!0}),setPriority:e.caller(`setPriority`),resolveLimits:e.caller(`resolveLimits`,{lastOnly:!0}),policies:e.caller(`policies`,{dedupe:!0}),setPolicy:e.caller(`setPolicy`),removeRule:e.caller(`removeRule`),actors:e.caller(`actors`,{dedupe:!0}),actorSettings:e.caller(`actorSettings`,{dedupe:!0}),setActorSetting:e.caller(`setActorSetting`),runs:e.caller(`runs`,{lastOnly:!0}),fns:e.caller(`fns`,{lastOnly:!0}),llmCalls:e.caller(`llmCalls`,{lastOnly:!0}),query:e.caller(`query`),resources:e.caller(`resources`,{lastOnly:!0}),modelRoles:e.caller(`modelRoles`,{dedupe:!0}),setModelRole:e.caller(`setModelRole`),clearModelRole:e.caller(`clearModelRole`),modelLimits:e.caller(`modelLimits`,{dedupe:!0}),setModelLimits:e.caller(`setModelLimits`),modelCalls:e.caller(`modelCalls`,{lastOnly:!0}),modelCall:e.caller(`modelCall`,{dedupe:!0}),fnMetrics:e.caller(`fnMetrics`,{dedupe:!0}),fnMetricsDays:e.caller(`fnMetricsDays`,{dedupe:!0}),mcps:e.caller(`mcps`,{dedupe:!0}),mcp:e.caller(`mcp`,{dedupe:!0}),createMcp:e.caller(`createMcp`),updateMcp:e.caller(`updateMcp`),rotateMcpSecret:e.caller(`rotateMcpSecret`),deleteMcp:e.caller(`deleteMcp`),previewMcp:e.caller(`previewMcp`,{lastOnly:!0}),mcpSessions:e.caller(`mcpSessions`,{dedupe:!0}),pairing:e.caller(`pairing`,{dedupe:!0}),instances:e.caller(`instances`,{dedupe:!0}),installPackage:e.caller(`installPackage`),removeInstance:e.caller(`removeInstance`),addInstance:e.caller(`addInstance`),readFn:e.caller(`readFn`),exportSystemData:e.caller(`exportSystemData`),autoPairs:e.caller(`autoPairs`,{dedupe:!0}),revokeAutoPair:e.caller(`revokeAutoPair`),suggestDecision:e.caller(`suggestDecision`,{dedupe:!0}),setSuggestDecision:e.caller(`setSuggestDecision`),previewSuggestions:e.caller(`previewSuggestions`,{lastOnly:!0}),searchDecisions:e.caller(`searchDecisions`,{dedupe:!0}),setSearchDecision:e.caller(`setSearchDecision`),injections:e.caller(`injections`,{lastOnly:!0}),setInjection:e.caller(`setInjection`),autoClassifier:e.caller(`autoClassifier`,{dedupe:!0}),setAutoClassifier:e.caller(`setAutoClassifier`),imageEmbedding:e.caller(`imageEmbedding`,{dedupe:!0}),setImageEmbedding:e.caller(`setImageEmbedding`),upload:e.caller(`upload`),uploaded:e.caller(`uploaded`),people:e.caller(`people`,{lastOnly:!0}),groups:e.caller(`groups`,{lastOnly:!0}),groupMembers:e.caller(`groupMembers`,{lastOnly:!0}),addUser:e.caller(`addUser`),addGroup:e.caller(`addGroup`),updateUser:e.caller(`updateUser`),setMembership:e.caller(`setMembership`),signInSettings:e.caller(`signInSettings`,{dedupe:!0}),setSignInPolicy:e.caller(`setSignInPolicy`),setSignInLimits:e.caller(`setSignInLimits`),setProxyTrust:e.caller(`setProxyTrust`),checkSsoProvider:e.caller(`checkSsoProvider`),testSsoSignIn:e.caller(`testSsoSignIn`),ssoTestResult:e.caller(`ssoTestResult`,{lastOnly:!0})}}function yl(e){return(t,n)=>e.on(`systemLog`,{system:t},n)}var bl=`connections`;function xl(e){return{connectPages:e.caller(`connectPages`,{cache:{ttl:3e4,tags:[bl]},dedupe:!0}),connect:e.caller(`connect`,{invalidates:[bl]}),updateConnection:e.caller(`updateConnection`,{invalidates:[bl]}),disconnect:e.caller(`disconnect`,{invalidates:[bl]})}}var Sl=`access`;function Cl(e){return{pick:e.caller(`pick`,{cache:{ttl:15e3},dedupe:!0}),accessInfo:e.caller(`accessInfo`,{cache:{ttl:6e4},dedupe:!0}),access:e.caller(`access`,{cache:{ttl:3e4,tags:[Sl]},dedupe:!0}),setAccess:e.caller(`setAccess`,{invalidates:[Sl]})}}var wl=`sessions`,Tl=`capabilities`;function El(e){return{capabilities:e.caller(`capabilities`,{cache:{ttl:6e4,tags:[Tl]},dedupe:!0}),types:e.caller(`types`,{cache:{ttl:3e5,tags:[Tl]},dedupe:!0}),sessions:e.caller(`sessions`,{cache:{ttl:5e3,tags:[wl]},dedupe:!0,lastOnly:!0}),searchSessions:e.caller(`sessions`,{debounce:250,lastOnly:!0}),session:e.caller(`session`,{dedupe:!0}),listValues:e.caller(`listValues`,{cache:{ttl:1e4},dedupe:!0}),createSession:e.caller(`createSession`,{invalidates:[wl]}),updateSession:e.caller(`updateSession`,{invalidates:[wl]}),deleteSession:e.caller(`deleteSession`,{invalidates:[wl]}),limits:e.caller(`limits`,{dedupe:!0}),messages:e.caller(`messages`,{dedupe:!0}),send:e.caller(`send`,{invalidates:[wl]}),invoke:e.caller(`invoke`),compare:e.caller(`compare`,{invalidates:[wl]}),compareView:e.caller(`compareView`,{lastOnly:!0}),chooseVariant:e.caller(`chooseVariant`,{invalidates:[wl]}),control:e.caller(`control`),controls:e.caller(`controls`,{dedupe:!0}),background:e.caller(`background`),undoTurn:e.caller(`undoTurn`),continueTurn:e.caller(`continueTurn`),tree:e.caller(`tree`,{dedupe:!0}),treeRefresh:e.caller(`tree`,{debounce:400,lastOnly:!0}),run:e.caller(`run`,{dedupe:!0}),llmCall:e.caller(`llmCall`,{cache:{ttl:3e5},dedupe:!0}),suggest:e.caller(`suggest`,{debounce:700,lastOnly:!0}),mentions:e.caller(`mentions`),mentionHover:e.caller(`mentionHover`,{cache:{ttl:3e4},dedupe:!0}),waiting:e.caller(`waiting`),approve:e.caller(`approve`),approvals:e.caller(`approvals`,{dedupe:!0}),contributions:e.caller(`contributions`,{cache:{ttl:6e4,tags:[Tl]},dedupe:!0}),setBudget:e.caller(`setBudget`),answer:e.caller(`answer`),presence:e.caller(`presence`),resource:e.caller(`resource`,{cache:{ttl:3e4},dedupe:!0}),upload:e.caller(`upload`),uploaded:e.caller(`uploaded`),transcribe:e.caller(`transcribe`),act:e.caller(`act`),submit:e.caller(`submit`),state:e.caller(`state`,{dedupe:!0}),previewSelection:e.caller(`previewSelection`,{lastOnly:!0}),...Cl(e),...xl(e)}}function Dl(e){return(t,n)=>e.on(`session`,{session:t},n)}var Ol=class{put(e,t,n,r){return new Promise((i,a)=>{let o=new XMLHttpRequest;o.open(`PUT`,e),t.type!==``&&o.setRequestHeader(`content-type`,t.type),o.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&n(e.loaded/e.total)},o.onload=()=>{o.status>=200&&o.status<300?(n(1),i()):a(Error(`Upload failed (${o.status}).`))},o.onerror=()=>{a(Error(`Upload failed.`))},o.onabort=()=>{a(new DOMException(`Upload cancelled.`,`AbortError`))},r.addEventListener(`abort`,()=>{o.abort()},{once:!0}),o.send(t)})}};function kl(e){return{setup:e.caller(`setup`,{cache:{ttl:5e3},dedupe:!0}),createAdmin:e.caller(`createAdmin`),signIn:e.caller(`signIn`),refresh:e.caller(`refresh`),redeemSso:e.caller(`redeemSso`),signOut:e.caller(`signOut`),me:e.caller(`me`,{dedupe:!0}),account:e.caller(`account`,{dedupe:!0})}}var Al={transport:`http`};function jl(e){return{identity:e.caller(`identity`,{dedupe:!0}),setHubName:e.caller(`setHubName`)}}function Ml(e){return{outsideImages:e.caller(`outsideImages`,{dedupe:!0}),setOutsideImages:e.caller(`setOutsideImages`)}}function Nl(e){return{https:e.caller(`https`,{dedupe:!0}),setHttps:e.caller(`setHttps`)}}var Pl=`inbox`;function Fl(e){return{list:e.caller(`notifications`,{cache:{ttl:1e4,tags:[Pl]},dedupe:!0}),markRead:e.caller(`readNotifications`,{invalidates:[Pl],retry:{attempts:3}}),pushKey:e.caller(`pushKey`,{cache:{ttl:36e5},dedupe:!0}),subscribePush:e.caller(`subscribePush`,{retry:{attempts:3}})}}function Il(e,t){return n=>{let r,i=S(t,t=>{r?.(),r=t===void 0?void 0:e.on(`user`,{user:t},n)},{immediate:!0});return()=>{i(),r?.()}}}function Ll(e){return{browse:e.caller(`browseResources`,{lastOnly:!0}),browseGroup:e.caller(`browseResources`),find:e.caller(`browseResources`,{lastOnly:!0}),forms:e.caller(`resourceForms`,{dedupe:!0}),read:e.caller(`readResource`,{dedupe:!0}),convert:e.caller(`convertResource`),download:e.caller(`downloadResource`,{dedupe:!0}),importResource:e.caller(`importResource`),rename:e.caller(`renameResource`),remove:e.caller(`deleteResource`),contextFrom:e.caller(`contextFromResource`),upload:e.caller(`upload`),uploaded:e.caller(`uploaded`),systemRead:e.caller(`resource`,{dedupe:!0}),exploreRoots:e.caller(`exploreRoots`,{lastOnly:!0}),exploreList:e.caller(`exploreList`),exploreRead:e.caller(`exploreRead`,{lastOnly:!0})}}function Rl(e){return t=>e(e=>{e.type===`resource`&&t({uri:e.uri,forms:e.forms})})}function zl(e){return{list:e.caller(`contexts`,{lastOnly:!0}),item:e.caller(`contextItem`,{dedupe:!0}),remember:e.caller(`remember`),updateMemory:e.caller(`updateMemory`),forget:e.caller(`forget`),link:e.caller(`linkContext`),unlink:e.caller(`unlinkContext`),fromResource:e.caller(`contextFromResource`),values:e.caller(`listValues`),metadata:e.caller(`contextMetadata`,{dedupe:!0}),setStatus:e.caller(`setContextStatus`),review:e.caller(`contextReview`,{lastOnly:!0}),merge:e.caller(`mergeContext`),notDuplicate:e.caller(`notDuplicate`),reextract:e.caller(`reextractContext`),newStatus:e.caller(`newContextStatus`),setNewStatus:e.caller(`setNewContextStatus`),plans:e.caller(`contextPlans`,{lastOnly:!0}),plan:e.caller(`contextPlan`),answerPlan:e.caller(`answerPlan`)}}function Bl(e){return t=>e(e=>{e.type===`context`&&t(e.name)})}function Vl(e){return{searchFns:e.caller(`searchFns`,{cache:{ttl:3e4},dedupe:!0}),fnFacts:e.caller(`fnFacts`,{dedupe:!0}),fnExamples:e.caller(`fnExamples`,{dedupe:!0}),fnsOfModelNames:e.caller(`fnsOfModelNames`,{dedupe:!0})}}function Hl(e){return{graph:e.caller(`graph`,{lastOnly:!0})}}var Ul=`records`;function Wl(e){return{dataSets:e.caller(`dataSets`,{cache:{ttl:1e4,tags:[Ul]},dedupe:!0,lastOnly:!0}),records:e.caller(`records`,{dedupe:!0,lastOnly:!0}),recordTable:e.caller(`recordTable`,{lastOnly:!0}),record:e.caller(`record`,{dedupe:!0}),saveRecord:e.caller(`saveRecord`,{invalidates:[Ul]}),removeRecord:e.caller(`removeRecord`,{invalidates:[Ul]}),recordVersions:e.caller(`recordVersions`,{dedupe:!0}),rowActions:e.caller(`rowActions`,{cache:{ttl:3e4},dedupe:!0}),readFn:e.caller(`readFn`),exportCsv:e.caller(`export`),itemVersions:e.caller(`itemVersions`,{dedupe:!0})}}function Gl(e){return{systemPages:e.caller(`systemPages`,{dedupe:!0})}}function Kl(e,t){let n=Il(e,t);return{auth:kl(e),identity:jl(e),outsideImages:Ml(e),https:Nl(e),notifications:Fl(e),userEvents:n,chat:El(e),sessionEvents:Dl(e),admin:vl(e),systemLogs:yl(e),resources:Ll(e),resourceEvents:Rl(n),context:zl(e),fns:Vl(e),graph:Hl(e),data:Wl(e),pages:Gl(e),contextEvents:Bl(n),connection:e.connection}}function ql(e){let t=new Map(e.questions.map(e=>[e.name,e])),n=Hn(e),r=new Set(e.roots.filter(e=>t.has(e))),i=new Map;for(let t of e.questions)for(let e of t.options)for(let n of e.raises)r.has(n)&&i.set(n,[...i.get(n)??[],{question:t,via:e.label}]);let a=new Set,o=[],s=(e,c,l)=>{let u=t.get(e);if(u===void 0)return;let d=n.get(e)?.live===!0,f=a.has(e),p=c===0&&!f?i.get(e):void 0;if(o.push({question:u,indent:c,...l===void 0?{}:{via:l},live:d,repeat:f,...p===void 0?{}:{alsoRaisedBy:p}}),!f){a.add(e);for(let e of u.options)for(let t of e.raises)r.has(t)||s(t,c+1,e.label)}};for(let t of e.roots)s(t,0,void 0);for(let t of e.questions)a.has(t.name)||s(t.name,0,void 0);return o}function Jl(e,t){return!t||e.status===`not_applicable`?{label:`Ruled out`,tone:`neutral`}:e.known===!0?{label:`Answered in context`,tone:`ok`}:bn(e)?{label:`Answered`,tone:`ok`}:e.status===`hidden`?{label:`Hidden`,tone:`warn`}:e.planned?{label:`Open`,tone:`accent`}:{label:`No options yet`,tone:`warn`}}var Yl={person:`For you`,system:`For the system`,research:`To research`};function Xl(e){return e.stop===`complete`?er(e.counts):`${er(e.counts)} · ${Sn[e.stop]}`}function Zl(e){return[`${e.answered} answered`,`${e.open} open`,`${e.decide} to decide now`,...e.ruledOut>0?[`${e.ruledOut} ruled out`]:[]]}function Ql(e){return`plan-${e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)||`plan`}.md`}function $l(e,t){return Math.max(0,Math.round((e-t)/2))}var eu=28,tu=72,nu=36,ru=252,iu=16,au=24,ou=6.4,su=4,cu=20,lu=16,uu=[.62,.5,.74,.4,.84,.3,.9,.22];function du(e,t){let n=e.y+64;return{x1:e.x+100,y1:n,x2:t.x+100,y2:t.y,bend:Math.max(30,Math.abs(t.y-n)/2)}}function fu(e,t){let{x1:n,y1:r,x2:i,y2:a,bend:o}=e,s=1-t,[c,l,u,d]=[s*s*s,3*s*s*t,3*s*t*t,t*t*t];return{x:c*n+l*n+u*i+d*i,y:c*r+l*(r+o)+u*(a-o)+d*a}}function pu(e,t){return e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height}function mu(e,t,n,r,i){for(let a of uu){let o=fu(e,a);for(let e of[0,-t/2-2,t/2+2]){let a={x:o.x+e-t/2,y:o.y-n/2,width:t,height:n};if(!(a.x<0||a.y<0||a.x+a.width>i.width||a.y+a.height>i.height)&&!r.some(e=>pu(a,e)))return a}}}function hu(e){let t=Hn(e),n=ql(e).filter(e=>!e.repeat).map(e=>e.question),r=new Map;for(let e of n)r.set(e.depth,[...r.get(e.depth)??[],e]);let i=[...r.keys()].sort((e,t)=>e-t),a=Math.max(1,...[...r.values()].map(e=>e.length)),o=32+a*200+(a-1)*eu,s=new Map;for(let t of e.questions)for(let e of t.options)for(let n of e.raises){let r=t.picked.includes(e.id)?`picked`:t.picked.length>0?`not`:`open`,i=`${t.name} ${n}`,a=s.get(i);s.set(i,a===void 0?{from:t.name,to:n,label:e.label,state:r}:{from:t.name,to:n,label:`${a.label} / ${e.label}`,state:a.state===`picked`||r===`picked`?`picked`:a.state===`open`||r===`open`?`open`:`not`})}let c=[...s.values()],l={picked:0,open:1,not:2},u=[...c].sort((e,t)=>l[e.state]-l[t.state]),d=i.slice(1).map(()=>tu);for(;;){let e=new Map,n=[],a=iu;i.forEach((i,s)=>{let c=r.get(i)??[],l=c.length*200+(c.length-1)*eu,u=(o-l)/2;c.forEach((r,i)=>{let o=t.get(r.name)?.live===!0?bn(r)?`answered`:r.planned?`open`:`unplanned`:`out`,c=r.options.filter(e=>r.picked.includes(e.id)).map(e=>e.label).join(`, `);n.push({name:r.name,label:r.question,x:u+i*228,y:a,state:o,picked:c}),e.set(r.name,s)}),a+=64+(d[s]??0)});let s=a-(d[i.length-1]??0)+iu,l={width:o,height:s},f=new Map(n.map(e=>[e.name,e])),p=n.map(e=>({x:e.x-4,y:e.y-4,width:208,height:72})),m=new Map,h=new Set,g=[];for(let t of u){let n=f.get(t.from),r=f.get(t.to);if(n===void 0||r===void 0)continue;let i=_u(t.label,au,2),a=mu(du(n,r),Math.max(...i.map(e=>e.length))*ou+8,i.length*13+su,p,l);a===void 0?(g.push(t),h.add(e.get(t.from)??0)):(p.push(a),m.set(`${t.from} ${t.to}`,{...a,lines:i}))}let _=!1;for(let e of h){let t=d[e];t!==void 0&&t<ru&&(d[e]=Math.min(ru,t+nu),_=!0)}if(g.length>0&&_)continue;let ee=new Map,te=[];for(let e of g){let t=f.get(e.from),n=f.get(e.to);if(t===void 0||n===void 0)continue;let r=du(t,n),i=mu(r,cu,lu,p,l),a=i===void 0?fu(r,.5):{x:i.x+cu/2,y:i.y+lu/2},o=te.length+1;i!==void 0&&p.push(i),ee.set(`${e.from} ${e.to}`,{n:o,x:a.x,y:a.y}),te.push({n:o,label:e.label,state:e.state})}return{width:o,height:s,nodes:n,edges:c.flatMap(e=>{let t=f.get(e.from),n=f.get(e.to);if(t===void 0||n===void 0)return[];let{x1:r,y1:i,x2:a,y2:o,bend:s}=du(t,n),c=`${e.from} ${e.to}`,l=m.get(c),u=ee.get(c);return[{...e,path:`M ${r} ${i} C ${r} ${i+s}, ${a} ${o-s}, ${a} ${o}`,...l===void 0?{}:{placed:l},...u===void 0?{}:{marker:u}}]}),legend:te}}}function gu(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function _u(e,t,n){let r=[],i=``;for(let n of e.split(/\s+/))i===``?i=n:i.length+1+n.length<=t?i=`${i} ${n}`:(r.push(i),i=n);if(i!==``&&r.push(i),r.length<=n)return r;let a=r.slice(0,n);return a[n-1]=gu(`${a[n-1]??``} ${r.slice(n).join(` `)}`,t),a}var vu={class:`plan-graph-wrap`},yu=[`width`,`height`,`viewBox`,`aria-label`],bu={class:`edges`},xu=[`d`],Su=[`d`],Cu={class:`labels`},wu=[`data-x`,`data-y`,`data-w`,`data-h`],Tu=[`x`,`y`,`width`,`height`],Eu=[`x`,`y`],Du=[`x`,`dy`],Ou=[`x`,`y`],ku=[`x`,`y`],Au=[`transform`,`aria-label`,`data-question`,`data-state`,`onClick`,`onKeydown`],ju=[`width`,`height`],Mu={x:`12`,y:`20`},Nu=[`dy`],Pu=[`y`],Fu={key:0,class:`legend`,"data-testid":`plan-graph-legend`,"aria-label":`Options too long to fit on their edges`},Iu={class:`n`},Lu=Y(A({__name:`PlanGraph`,props:{plan:{}},emits:[`pick`],setup(e,{emit:t}){let n=e,r=t,i=k(()=>hu(n.plan)),a=I(null),o=async()=>{await ke(),a.value!==null&&(a.value.scrollLeft=$l(i.value.width,a.value.clientWidth))};Se(()=>{o()}),S(()=>i.value.width,()=>{o()});let c=e=>_u(e.label,30,e.picked===``?3:2),l={answered:`answered`,open:`open`,out:`ruled out`,unplanned:`no options yet`};return(e,t)=>(j(),E(`div`,vu,[T(`div`,{ref_key:`box`,ref:a,class:`plan-graph`,"data-testid":`plan-graph`,tabindex:`0`,"aria-label":`The plan as a graph; scrolls both ways`},[(j(),E(`svg`,{width:i.value.width,height:i.value.height,viewBox:`0 0 ${i.value.width} ${i.value.height}`,role:`img`,"aria-label":`${i.value.nodes.length} questions and how they connect`},[t[0]||=T(`defs`,null,[T(`marker`,{id:`plan-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`},[T(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,class:`arrow`})])],-1),T(`g`,bu,[(j(!0),E(M,null,D(i.value.edges,e=>(j(),E(`g`,{key:`${e.from}-${e.to}`,class:w([`edge`,e.state]),"data-testid":`plan-graph-edge`},[T(`title`,null,P(e.label),1),T(`path`,{d:e.path,"marker-end":`url(#plan-arrow)`},null,8,xu),T(`path`,{d:e.path,class:`hit`},null,8,Su)],2))),128))]),T(`g`,Cu,[(j(!0),E(M,null,D(i.value.edges,e=>(j(),E(M,{key:`${e.from}-${e.to}-label`},[e.placed?(j(),E(`g`,{key:0,class:w([`label`,e.state]),"data-testid":`plan-graph-label`,"data-x":e.placed.x,"data-y":e.placed.y,"data-w":e.placed.width,"data-h":e.placed.height},[T(`title`,null,P(e.label),1),T(`rect`,{x:e.placed.x,y:e.placed.y,width:e.placed.width,height:e.placed.height,rx:`4`},null,8,Tu),T(`text`,{x:e.placed.x+e.placed.width/2,y:e.placed.y+C(13)-1,"text-anchor":`middle`},[(j(!0),E(M,null,D(e.placed.lines,(t,n)=>(j(),E(`tspan`,{key:n,x:e.placed.x+e.placed.width/2,dy:n===0?0:C(13)},P(t),9,Du))),128))],8,Eu)],10,wu)):e.marker?(j(),E(`g`,{key:1,class:w([`label`,`numbered`,e.state]),"data-testid":`plan-graph-marker`},[T(`title`,null,P(e.marker.n)+`: `+P(e.label),1),T(`rect`,{x:e.marker.x-10,y:e.marker.y-8,width:`20`,height:`16`,rx:`8`},null,8,Ou),T(`text`,{x:e.marker.x,y:e.marker.y+4,"text-anchor":`middle`},P(e.marker.n),9,ku)],2)):R(``,!0)],64))),128))]),(j(!0),E(M,null,D(i.value.nodes,e=>(j(),E(`g`,{key:e.name,class:w([`node`,e.state]),transform:`translate(${e.x} ${e.y})`,role:`button`,tabindex:`0`,"aria-label":`${e.label} (${l[e.state]})`,"data-testid":`plan-graph-node`,"data-question":e.name,"data-state":e.state,onClick:t=>r(`pick`,e.name),onKeydown:s(t=>r(`pick`,e.name),[`enter`])},[T(`rect`,{width:C(200),height:C(64),rx:`10`},null,8,ju),T(`text`,Mu,[(j(!0),E(M,null,D(c(e),(e,t)=>(j(),E(`tspan`,{key:t,x:`12`,dy:t===0?0:15},P(e),9,Nu))),128))]),e.picked===``?R(``,!0):(j(),E(`text`,{key:0,x:`12`,y:C(64)-10,class:`picked`},`✓ `+P(C(gu)(e.picked,28)),9,Pu))],42,Au))),128))],8,yu))],512),i.value.legend.length>0?(j(),E(`ol`,Fu,[(j(!0),E(M,null,D(i.value.legend,e=>(j(),E(`li`,{key:e.n,class:w(e.state)},[T(`span`,Iu,P(e.n),1),x(` `+P(e.label),1)],2))),128))])):R(``,!0)]))}}),[[`__scopeId`,`data-v-c009da68`]]),Ru=[`data-question`,`data-state`],zu={key:0,class:`again`},Bu={key:0,class:`via`},Vu={class:`head`},Hu=[`title`],Uu=[`id`],Wu={key:0,class:`also faint`,"data-testid":`plan-question-also`},Gu={key:0},Ku=[`title`,`onClick`],qu={class:`facts`},Ju={key:0,class:`faint`},Yu={key:1,class:`reason`,"data-testid":`plan-question-reason`},Xu={key:2,class:`reason-edit`},Zu={class:`row-actions`},Qu={key:3,class:`faint`},$u=[`aria-label`],ed=[`aria-pressed`,`disabled`,`title`,`data-option`,`onClick`],td={key:5,class:`faint`},nd={key:6,class:`own`},rd={class:`row-actions`},id=Y(A({__name:`PlanQuestionRow`,props:{row:{},busy:{type:Boolean,default:!1},deeper:{type:Boolean,default:!1},canDeepen:{type:Boolean,default:!0}},emits:[`answer`,`reason`,`deeper`,`jump`],setup(e,{emit:t}){let n=e,r=t,i=k(()=>n.row.question),a=k(()=>Jl(i.value,n.row.live)),o=k(()=>!n.row.live||i.value.status===`not_applicable`),s=k(()=>i.value.known===!0),c=I(i.value.text??``),l=I(i.value.statusReason??``),u=I(!1);S(()=>i.value.text,e=>{c.value=e??``}),S(()=>i.value.statusReason,e=>{l.value=e??``});let d=k(()=>c.value.trim()!==(i.value.text??``).trim()),f=k(()=>!i.value.planned&&!bn(i.value));function p(e){if(o.value||s.value)return;let t=i.value.picked.includes(e)?i.value.picked.filter(t=>t!==e):[...i.value.picked,e];r(`answer`,{question:i.value.name,picked:t,...c.value.trim()===``?{}:{text:c.value.trim()}})}function h(){r(`answer`,{question:i.value.name,picked:[...i.value.picked],...c.value.trim()===``?{}:{text:c.value.trim()}})}function g(){let e=l.value.trim();e!==``&&(r(`reason`,{question:i.value.name,reason:e}),u.value=!1)}return(t,n)=>(j(),E(`li`,{class:w([`plan-q`,{out:o.value,repeat:e.row.repeat}]),style:Ce({"--indent":String(Math.min(e.row.indent,6))}),"data-testid":`plan-question`,"data-question":i.value.name,"data-state":a.value.label},[e.row.repeat?(j(),E(`div`,zu,[e.row.via?(j(),E(`span`,Bu,P(e.row.via)+` →`,1)):R(``,!0),T(`button`,{type:`button`,class:`link`,"data-testid":`plan-question-jump`,onClick:n[0]||=e=>r(`jump`,i.value.name)},P(i.value.question),1),n[7]||=T(`span`,{class:`faint`},`(shown above)`,-1)])):(j(),E(M,{key:1},[T(`div`,Vu,[e.row.via?(j(),E(`span`,{key:0,class:`via`,title:`Raised by choosing “${e.row.via}”`},P(e.row.via)+` →`,9,Hu)):R(``,!0),T(`h3`,{id:`q-${i.value.name}`,class:`words`},P(i.value.question),9,Uu)]),e.row.alsoRaisedBy!==void 0&&e.row.alsoRaisedBy.length>0?(j(),E(`p`,Wu,[n[8]||=x(` Also raised by `,-1),(j(!0),E(M,null,D(e.row.alsoRaisedBy,(e,t)=>(j(),E(M,{key:`${e.question.name}-${e.via}`},[t>0?(j(),E(`span`,Gu,`, `)):R(``,!0),T(`button`,{type:`button`,class:`link`,"data-testid":`plan-question-also-jump`,title:`Choosing “${e.via}” for “${e.question.question}”`,onClick:t=>r(`jump`,e.question.name)},` “`+P(e.via)+`” `,9,Ku)],64))),128))])):R(``,!0),T(`div`,qu,[b(C(V),{tone:a.value.tone,"data-testid":`plan-question-state`},{default:N(()=>[x(P(a.value.label),1)]),_:1},8,[`tone`]),i.value.askedBy?(j(),E(`span`,Ju,P(C(Yl)[i.value.askedBy]??i.value.askedBy),1)):R(``,!0),b(C(m),{class:`faint item-link`,to:C(y).contextItem(i.value.name),"data-testid":`plan-question-item`,title:`Open ${i.value.name} on its context page to edit it`},{default:N(()=>[b(C(Ft),{name:`edit`,size:12}),n[9]||=x(` Context item `,-1)]),_:1},8,[`to`,`title`])]),o.value?(j(),E(`p`,Yu,[u.value?R(``,!0):(j(),E(M,{key:0},[T(`span`,null,P(i.value.statusReason??`Ruled out`),1),T(`button`,{type:`button`,class:`link`,"data-testid":`plan-reason-edit`,onClick:n[1]||=e=>u.value=!0},`Edit reason`)],64))])):R(``,!0),o.value&&u.value?(j(),E(`div`,Xu,[b(C(Lt),{modelValue:l.value,"onUpdate:modelValue":n[2]||=e=>l.value=e,label:`Why it doesn't apply`,rows:2,"data-testid":`plan-reason-text`},null,8,[`modelValue`]),T(`div`,Zu,[b(C(H),{size:`sm`,variant:`ghost`,onClick:n[3]||=e=>u.value=!1},{default:N(()=>[...n[10]||=[x(`Cancel`,-1)]]),_:1}),b(C(H),{size:`sm`,loading:e.busy,"data-testid":`plan-reason-save`,onClick:g},{default:N(()=>[...n[11]||=[x(`Save reason`,-1)]]),_:1},8,[`loading`])])])):R(``,!0),s.value?(j(),E(`p`,Qu,`Answered in context before this plan; change it on its context page.`)):R(``,!0),i.value.options.length>0?(j(),E(`div`,{key:4,class:`chips`,role:`group`,"aria-label":`Options for ${i.value.question}`},[(j(!0),E(M,null,D(i.value.options,t=>(j(),E(`button`,{key:t.id,type:`button`,class:w([`chip`,{picked:i.value.picked.includes(t.id)}]),"aria-pressed":i.value.picked.includes(t.id)?`true`:`false`,disabled:o.value||s.value||e.busy,title:t.detail,"data-testid":`plan-option`,"data-option":t.id,onClick:e=>p(t.id)},[i.value.picked.includes(t.id)?(j(),F(C(Ft),{key:0,name:`check`,size:12})):R(``,!0),x(P(t.label),1)],10,ed))),128))],8,$u)):f.value?(j(),E(`p`,td,`No options yet: planning deeper writes them.`)):R(``,!0),!o.value&&!s.value?(j(),E(`div`,nd,[b(C(Lt),{modelValue:c.value,"onUpdate:modelValue":n[4]||=e=>c.value=e,label:`Your own detail`,placeholder:`Anything the options leave out`,rows:1,"max-rows":6,disabled:e.busy,"data-testid":`plan-question-text`},null,8,[`modelValue`,`disabled`]),T(`div`,rd,[e.deeper&&e.canDeepen?(j(),F(C(H),{key:0,size:`sm`,variant:`ghost`,icon:`tree`,"data-testid":`plan-deeper-here`,onClick:n[5]||=e=>r(`deeper`,i.value.name)},{default:N(()=>[...n[12]||=[x(`Plan deeper here`,-1)]]),_:1})):f.value&&e.canDeepen?(j(),F(C(H),{key:1,size:`sm`,variant:`ghost`,icon:`tree`,"data-testid":`plan-deeper-here`,onClick:n[6]||=e=>r(`deeper`,i.value.name)},{default:N(()=>[...n[13]||=[x(`Write its options`,-1)]]),_:1})):R(``,!0),d.value?(j(),F(C(H),{key:2,size:`sm`,loading:e.busy,"data-testid":`plan-question-save`,onClick:h},{default:N(()=>[...n[14]||=[x(`Save`,-1)]]),_:1},8,[`loading`])):R(``,!0)])])):R(``,!0)],64))],14,Ru))}}),[[`__scopeId`,`data-v-0a11b25c`]]),ad={key:0,class:`plan`},od={class:`top`},sd={class:`line`,"data-testid":`plan-dialog-counts`},cd={key:0,class:`outline`,"data-testid":`plan-outline`},ld=Y(A({__name:`PlanDialog`,props:ge({run:{},canDeepen:{type:Boolean,default:!0}},{open:{type:Boolean,required:!0},openModifiers:{}}),emits:ge([`deeper`],[`update:open`]),setup(e,{emit:t}){let n=e,r=_e(e,`open`),i=t,{context:a,toasts:o}=G(),s=a.plans,c=I(`outline`),l=[{value:`outline`,label:`Outline`,icon:`list`},{value:`graph`,label:`Graph`,icon:`graph`}];S([r,()=>n.run],([e])=>{e&&s.show(n.run)},{immediate:!0}),a.follow();let u=k(()=>s.open.value.value?.run===n.run?s.open.value.value.plan:void 0),d=k(()=>u.value===void 0?[]:ql(u.value)),f=k(()=>new Set(s.deeper.value));async function p(e){let t=await s.answer(n.run,e);if(!t.ok){o.error(`Couldn't save that`,t.problem);return}let[r]=t.value.skipped;r!==void 0&&o.error(`Part of that wasn't saved`,r.reason)}async function m(e){c.value=`outline`,await ke(),document.querySelector(`[data-testid="plan-question"][data-question="${CSS.escape(e)}"]`)?.scrollIntoView({block:`center`,behavior:`smooth`})}async function h(){let e=await s.markdown(n.run);if(e===void 0){o.error(`Couldn't export the plan`);return}let t=URL.createObjectURL(new Blob([e],{type:`text/markdown`})),r=document.createElement(`a`);r.href=t,r.download=Ql(u.value?.description??`plan`),r.click(),URL.revokeObjectURL(t)}async function g(){let e=await s.markdown(n.run);e===void 0||!await xt(e)?o.error(`Couldn't copy the plan`):o.ok(`Copied the plan as markdown`)}return(t,n)=>(j(),F(C(yt),{open:r.value,"onUpdate:open":n[6]||=e=>r.value=e,title:`Plan`,description:u.value?.description??``,width:`min(920px, 100vw)`,"data-testid":`plan-dialog`},{footer:N(()=>[b(C(H),{variant:`ghost`,icon:`copy`,"data-testid":`plan-copy`,onClick:g},{default:N(()=>[...n[7]||=[x(`Copy markdown`,-1)]]),_:1}),b(C(H),{variant:`ghost`,icon:`download`,"data-testid":`plan-export`,onClick:h},{default:N(()=>[...n[8]||=[x(`Export`,-1)]]),_:1}),e.canDeepen?(j(),F(C(H),{key:0,icon:`tree`,"data-testid":`plan-deeper`,onClick:n[5]||=e=>i(`deeper`,void 0)},{default:N(()=>[...n[9]||=[x(`Plan deeper`,-1)]]),_:1})):R(``,!0)]),default:N(()=>[b(Re,{loading:C(s).open.loading.value&&u.value===void 0,problem:C(s).open.problem.value,ready:u.value!==void 0,empty:!1,onRetry:n[4]||=t=>C(s).show(e.run)},{default:N(()=>[u.value?(j(),E(`div`,ad,[T(`div`,od,[T(`p`,sd,P(C(Xl)(u.value)),1),b(C(Gt),{modelValue:c.value,"onUpdate:modelValue":n[0]||=e=>c.value=e,options:l,label:`Plan view`,"data-testid":`plan-view`},null,8,[`modelValue`])]),c.value===`outline`?(j(),E(`ul`,cd,[(j(!0),E(M,null,D(d.value,(t,r)=>(j(),F(id,{key:`${t.question.name}-${r}`,row:t,busy:C(s).busyQuestion.value===t.question.name,deeper:f.value.has(t.question.name),"can-deepen":e.canDeepen,onAnswer:n[1]||=e=>p({answer:e}),onReason:n[2]||=e=>p({reason:e}),onDeeper:n[3]||=e=>i(`deeper`,e),onJump:m},null,8,[`row`,`busy`,`deeper`,`can-deepen`]))),128))])):(j(),F(Lu,{key:1,plan:u.value,onPick:m},null,8,[`plan`]))])):R(``,!0)]),_:1},8,[`loading`,`problem`,`ready`])]),_:1},8,[`open`,`description`]))}}),[[`__scopeId`,`data-v-e412ee45`]]),ud=[`data-run`],dd={key:0,class:`lead`},fd={class:`title`},pd=[`title`],md={class:`counts`,"data-testid":`plan-card-counts`},hd={key:0},gd={key:1,class:`limited`,"data-testid":`plan-card-stop`},_d={class:`actions`},vd=Y(A({__name:`PlanCardBody`,props:{planRun:{},plan:{},lead:{default:``}},emits:[`deeper`],setup(e,{emit:t}){let n=e,r=t,i=rn(),a=I(!1),o=k(()=>n.plan.stop===`complete`?``:Sn[n.plan.stop]),s=I(!1);function c(e){a.value=!1,s.value=!0,r(`deeper`,e),setTimeout(()=>{s.value=!1},1500)}return(t,n)=>(j(),E(`section`,{class:`plan-card`,"data-testid":`plan-card`,"data-run":e.planRun},[e.lead===``?R(``,!0):(j(),E(`p`,dd,P(e.lead),1)),T(`div`,fd,[b(C(Ft),{name:`tree`,size:16}),T(`p`,{class:`description`,title:e.plan.description},P(e.plan.description),9,pd)]),T(`p`,md,[T(`strong`,null,P(C(er)(e.plan.counts)),1),e.plan.counts.ruledOut>0?(j(),E(`span`,hd,` · `+P(e.plan.counts.ruledOut)+` ruled out`,1)):R(``,!0)]),o.value===``?R(``,!0):(j(),E(`p`,gd,P(o.value)+`; Plan deeper goes on from there.`,1)),T(`div`,_d,[C(i)?(j(),F(C(H),{key:0,size:`sm`,variant:`primary`,icon:`maximize`,"data-testid":`plan-card-open`,onClick:n[0]||=e=>a.value=!0},{default:N(()=>[...n[3]||=[x(`Open`,-1)]]),_:1})):R(``,!0),b(C(H),{size:`sm`,icon:`tree`,loading:s.value,"data-testid":`plan-card-deeper`,onClick:n[1]||=e=>c(void 0)},{default:N(()=>[...n[4]||=[x(`Plan deeper`,-1)]]),_:1},8,[`loading`])]),C(i)&&a.value?(j(),F(ld,{key:2,open:a.value,"onUpdate:open":n[2]||=e=>a.value=e,run:e.planRun,onDeeper:c},null,8,[`open`,`run`])):R(``,!0)],8,ud))}}),[[`__scopeId`,`data-v-b7e399b0`]]),yd=i(l,{results:{fns:{ctx_plan:A({__name:`PlanResult`,props:{run:{},fn:{},args:{},result:{},title:{},system:{}},setup(e){let t=e,n=k(()=>cn.safeParse(t.result));function r(e){t.system.run.ctx_plan_expand({run:t.run,...e===void 0?{}:{under:e}})}return(t,i)=>n.value.success?(j(),F(vd,{key:0,"plan-run":e.run,plan:n.value.data,onDeeper:r},null,8,[`plan-run`,`plan`])):R(``,!0)}}),ctx_plan_expand:A({__name:`PlanExpandResult`,props:{run:{},fn:{},args:{},result:{},title:{},system:{}},setup(e){let t=e,n=k(()=>zn.safeParse(t.result)),r=k(()=>t.args.replan===!0?`Re-planned`:`Planned deeper`);function i(e){n.value.success&&t.system.run.ctx_plan_expand({run:n.value.data.run,...e===void 0?{}:{under:e}})}return(e,t)=>n.value.success?(j(),F(vd,{key:0,"plan-run":n.value.data.run,plan:n.value.data.plan,lead:r.value,onDeeper:i},null,8,[`plan-run`,`plan`,`lead`])):R(``,!0)}})}}}),bd=class{#e;multiUser=I(!1);saving=new U;#t=!1;constructor(e){this.#e=e}async load(){if(!this.#t){this.#t=!0;try{this.multiUser.value=(await this.#e.accessInfo.call({})).multiUser}catch{this.#t=!1}}}view(e){let t=new W;return t.load(async()=>{let[t]=await this.#e.access.call({targets:[e]});if(t===void 0)throw Error(`The hub did not say who can use this.`);return t},`Couldn’t load who can use this.`),t}async set(e,t){return this.saving.run(()=>this.#e.setAccess.call({target:e,sharing:t}),`Couldn’t change who can use this.`)}};function xd(e,t){let n=[...e.connections].sort((e,t)=>t.updatedAt-e.updatedAt);return{own:n.find(e=>e.owner===t),shared:n.filter(e=>e.owner!==t)}}function Sd(e,t){return Object.entries(e.decl.fns).map(([n,r])=>{let i=t?.fns[n],a=i??r;return{local:n,name:`${e.system}/${n}`,option:a,changed:i!==void 0&&(i.on!==r.on||i.ask!==r.ask)}})}function Cd(e,t,n){return Object.fromEntries(e.map(e=>[e.local,e.local===t?{...e.option,...n}:e.option]))}var wd={pending:{label:`Waiting for sign-in`,tone:`warn`},connected:{label:`Connected`,tone:`ok`},expired:{label:`Expired`,tone:`warn`},failed:{label:`Failed`,tone:`danger`}},Td=e=>e in Pt;function Ed(e){let t=e.decl.icon;return t!==void 0&&Td(t)?t:`link`}function Dd(e){return e.map(e=>({system:e.system,title:e.decl.title,icon:Ed(e)})).sort((e,t)=>e.title.localeCompare(t.title))}var Od=e=>e.name===`optional`?e.generic?.T??e:e,kd=e=>{let t=e.replace(/([a-z])([A-Z])/g,`$1 $2`).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)};function Ad(e,t){let n=e.name===`obj`?e.props:void 0;if(n===void 0||t===void 0)return;let r=Object.entries(n).map(([e,n])=>{let r=t[e];if(r!==void 0)return{key:e,label:kd(e),hint:n.docs??``,many:Od(n.type).name===`list`,options:r}});return r.every(e=>e!==void 0)&&r.length>0?r:void 0}function jd(e,t){let n=typeof e==`object`&&e&&!Array.isArray(e)?e[t]:void 0;return Array.isArray(n)?n.filter(e=>typeof e==`string`):typeof n==`string`?[n]:[]}function Md(e,t){return Object.fromEntries(e.flatMap(e=>{let n=t[e.key]??[];return n.length===0?[]:[[e.key,e.many?[...n]:n[0]??``]]}))}function Nd(e,t){return`key`in t?e.key===t.key:e.instance===t.instance}function Pd(e){return e.decl.scope===`instance`||e.decl.scope===`key`}function Fd(e,t,n){let r=[...e.connections].sort((e,t)=>t.updatedAt-e.updatedAt);return[...(e.instances??[]).map(e=>({target:{instance:e.instance},id:e.instance,label:e.label,connect:e.connect})),...(e.keys??[]).map(e=>({target:{key:e.key},id:e.key,label:e.label,connect:e.connect,host:e.host}))].map(e=>{let i=r.filter(t=>Nd(t,e.target)),a=e.connect.flow?.flow??`none`;return{...e,own:i.find(e=>e.owner===t),shared:i.filter(e=>e.owner!==t),flow:a,mayConnect:a!==`none`&&(!e.connect.share||n)}}).sort((e,t)=>e.label.localeCompare(t.label))}var Id=class{#e;pages=new W;saving=new U;nav=k(()=>Dd(this.pages.value.value??[]));constructor(e){this.#e=e}async load(e=!1){await this.pages.load(()=>this.#e.connectPages.call({}),`Couldn’t load the connect pages.`,e)}page(e){return this.pages.value.value?.find(t=>t.system===e)}async connect(e,t,n){let r={system:e,...t===void 0?{}:{form:t},...n},i=await this.saving.run(()=>this.#e.connect.call(r),`Couldn’t start connecting.`);return i.ok&&`connection`in i.value&&this.#t(i.value.connection),i}async update(e){let t=await this.saving.run(()=>this.#e.updateConnection.call(e),`Couldn’t save the change.`);return t.ok&&this.#t(t.value),t}async disconnect(e){let t=await this.saving.run(async()=>(await this.#e.disconnect.call({connection:e})).ok,`Couldn’t disconnect.`);return t.ok&&this.#n(e),t}#t(e){this.#r(e.system,t=>[e,...t.filter(t=>t.id!==e.id)])}#n(e){let t=this.pages.value.value?.find(t=>t.connections.some(t=>t.id===e));t!==void 0&&this.#r(t.system,t=>t.filter(t=>t.id!==e))}#r(e,t){let n=this.pages.value.value;n!==void 0&&this.pages.set(n.map(n=>n.system===e?{...n,connections:t(n.connections)}:n))}},Ld=class{#e;#t=new Map;#n;constructor(e){this.#e=e}source(e){let t=this.#t.get(e);if(t!==void 0)return t;let n={search:async t=>this.#e.pick.call({source:e,limit:12,...t===``?{}:{text:t}}),label:async t=>t.length===0?[]:this.#e.pick.call({source:e,values:[...t]})};return this.#t.set(e,n),n}people(){if(this.#n!==void 0)return this.#n;let e=this.source(`person`),t=this.source(`group`);return this.#n={search:async n=>(await Promise.all([e.search(n),t.search(n)])).flat(),label:async n=>Rd(n,await Promise.all([e.label(n),t.label(n)]))},this.#n}};function Rd(e,t){let n=t.flat();return e.map(e=>n.find(t=>t.value===e&&t.missing!==!0)??{value:e,label:e,missing:!0})}var zd=class{#e;#t;#n;#r=0;value=L(void 0);session=I(void 0);problem=I(``);can=k(()=>{let e=this.value.value;return{mention:(e?.mentions.length??0)>0,command:(e?.commands.length??0)>0,invoke:(e?.invocations.length??0)>0,upload:e?.uploads===!0,voice:e?.voiceInput===!0}});constructor(e,t){this.#e=e,this.#t=t}start(){this.#n===void 0&&(this.#n=this.#t(e=>{this.#i(e)}))}stop(){this.#n?.(),this.#n=void 0}async load(e=this.session.value){this.session.value=e;let t=++this.#r;try{let n=await this.#e.capabilities.call(e===void 0?{}:{session:e});if(t!==this.#r)return;this.value.value=n,this.problem.value=``}catch(e){t===this.#r&&(this.problem.value=X(e,`Couldn't load what this chat can do.`))}}online(e){return this.value.value?.systems.find(t=>t.name===e)?.status===`connected`}invocation(e){return this.value.value?.invocations.find(t=>t.fn===e)}commandFor(e){return this.value.value?.commands.find(t=>t.context===e)}#i(e){if(e.type===`capabilities`)this.#e.capabilities.invalidate(),this.load();else if(e.type===`system`){let t=this.value.value;if(t===void 0)return;this.value.value={...t,systems:t.systems.map(t=>t.name===e.system?{...t,status:e.status}:t)}}}},Bd=`harness.runCards`,Vd=new Set([`hub/ctx_plan`,`hub/ctx_plan_expand`]),Hd=gn([Vn,En()]);function Ud(e){return e.status===`done`&&e.fn!==void 0&&Vd.has(e.fn)||e.status===`done`&&e.outcome?.status===`done`&&Xr(e.outcome.result)?!1:e.status===`done`||e.status===`undone`}var Wd=class{#e;constructor(e){this.#e=Ur(e,Bd,Yn(Hd),[])}choice(e){return this.#e.value.find(([t])=>t===e)?.[1]}isCollapsed(e){return this.choice(e.id)??Ud(e)}set(e,t){this.setAll([e],t)}setAll(e,t){let n=new Set(e),r=this.#e.value.filter(([e])=>!n.has(e));this.#e.value=[...r,...e.map(e=>[e,t])].slice(-500)}};async function Gd(e,t,n,r,i){let a=n.outgoing();if(a===void 0)return{ok:!1,problem:`Write the message to compare first.`};let o=n.snapshot();n.clear(`keep`);try{let o=await e.compare.call({session:t.id,parts:[...a.parts],variants:[...r],client:i});return t.messages.value=Je(t.messages.value,o.message),n.uploads.clear(),{ok:!0,value:o.turn}}catch(e){return n.restore(o),{ok:!1,problem:X(e,`Couldn’t start the compare. Your message is back in the box.`)}}}function Kd(e,t){let n=setTimeout(e,t);return()=>{clearTimeout(n)}}var qd=class{view=new W;streamed=L(new Map);choosing=new U;deciding=new U;turn;#e;#t;#n=new Map;#r;constructor(e,t,n){this.#t=e,this.#e=t,this.turn=n}async open(){this.#i(this.#e),await this.view.load(()=>this.#t.api.compareView.call({turn:this.turn}),`Couldn’t load the compare.`);for(let e of this.view.value.value?.variants??[])this.#i(e.session)}close(){for(let e of this.#n.values())e();this.#n.clear(),this.#r?.(),this.#r=void 0}async choose(e,t){let n=await this.choosing.run(()=>this.#t.api.chooseVariant.call({turn:this.turn,variant:e,adopt:t}),`Couldn’t use that answer.`);return n.ok&&this.view.set(n.value),n}async decide(e,t,n,r,i){let a=await this.deciding.run(()=>this.#t.api.approve.call({approval:e,approve:t,remember:n,...r===``?{}:{reason:r},...i===void 0?{}:{answer:i}}),`Couldn’t answer that.`);return a.ok&&this.#o(),a.ok}#i(e){this.#n.has(e)||this.#n.set(e,this.#t.events(e,t=>{this.#a(e,t)}))}#a(e,t){switch(t.type){case`compare`:t.turn===this.turn&&this.#o();return;case`token`:case`reasoning`:{if(e===this.#e)return;let n=new Map(this.streamed.value),r=n.get(t.message)??{text:``,reasoning:``};n.set(t.message,t.type===`token`?{...r,text:r.text+t.text}:{...r,reasoning:r.reasoning+t.text}),this.streamed.value=n;return}case`message`:case`approval`:case`run`:e!==this.#e&&this.#o();return;case`controls`:case`state`:case`delivery`:case`handler`:case`budget`:case`presence`:case`session`:case`cite`:return}}#o(){this.#r?.(),this.#r=(this.#t.later??Kd)(()=>{this.#r=void 0,this.view.load(()=>this.#t.api.compareView.call({turn:this.turn}),`Couldn’t load the compare.`,!0).then(()=>{this.streamed.value=new Map})},300)}},Jd=e=>`harness.draft.${e}`,Yd=K({text:q(),mentions:Yn(Gn).transform(e=>e.filter(e=>e.type===`mention`)),replyTo:Fn.optional(),replyAll:En()}),Xd={delay:120,perProvider:6,max:24},Zd=(e,t)=>e.provider===t.provider&&JSON.stringify(e.target)===JSON.stringify(t.target),Qd=(e,...t)=>{let n=e.toLowerCase();return n===``||t.some(e=>e.toLowerCase().includes(n))},$d=class{session;uploads;#e;#t;#n;#r;#i=0;#a;text=I(``);caret=I(0);mentions=L([]);replyTo=I(void 0);replyAll=I(!1);editing=I(void 0);invoking=L(void 0);caretRequest=I(void 0);pickerItems=L([]);pickerActive=I(0);pickerLoading=I(!1);#o=I(void 0);trigger=k(()=>{let e=Ge(this.text.value,this.caret.value),t=this.#e.capabilities();if(e!==void 0&&t!==void 0)return(e.kind===`mention`?t.mentions.length>0:e.kind===`command`?t.commands.length>0:t.invocations.length>0)?e:void 0});pickerOpen=k(()=>{let e=this.trigger.value;return e!==void 0&&this.#o.value!==`${e.kind}:${e.start}`});hint=k(()=>st(this.text.value,this.#e.capabilities()?.commands??[]));canSend=k(()=>!this.uploads.busy.value&&(this.text.value.trim()!==``||this.uploads.parts.value.length>0));constructor(e,t=Xd){this.session=e.session,this.uploads=e.uploads,this.#e=e,this.#t=t,this.#n=Ur(e.store,Jd(e.session),Yd.optional(),void 0);let n=this.#n.value;n!==void 0&&(this.text.value=n.text,this.caret.value=n.text.length,this.mentions.value=n.mentions,this.replyTo.value=n.replyTo,this.replyAll.value=n.replyAll),S([this.text,this.mentions,this.replyTo,this.replyAll],()=>{this.#c()}),S(()=>[this.trigger.value?.kind,this.trigger.value?.query,this.trigger.value?.start],()=>{this.#l()})}input(e,t){this.text.value=e,this.caret.value=t,this.mentions.value=He(e,this.mentions.value)}moveCaret(e){this.caret.value=e}movePicker(e){let t=this.pickerItems.value.length;t!==0&&(this.pickerActive.value=(this.pickerActive.value+e+t)%t)}dismissPicker(){let e=this.trigger.value;e!==void 0&&(this.#o.value=`${e.kind}:${e.start}`)}pick(e=this.pickerItems.value[this.pickerActive.value]){let t=this.trigger.value;if(e!==void 0&&t!==void 0){if(e.kind===`mention`){let n={type:`mention`,provider:e.provider,label:e.option.label,target:e.option.target},r=this.mentions.value.find(e=>Zd(e,n)),i=r??n;this.#s(t,`${Ve(i)} `),r===void 0&&(this.mentions.value=[...this.mentions.value,i])}else if(e.kind===`command`){if(e.command.unavailable!==void 0)return;this.#s(t,`/${e.command.name} `)}else this.#s(t,``),this.invoking.value=e.invocation}}openInvocation(e,t){this.invoking.value=e,this.#a=t}closeInvocation(){this.invoking.value=void 0,this.#a=void 0}invocationArgs(e){return this.#a===void 0?e:at(e,this.#a)}insert(e){let t=this.caret.value,n=this.text.value.slice(0,t),r=n===``||/\s$/.test(n)?e:` ${e}`,i=Ue(this.text.value,t,t,r);this.text.value=i.text,this.caret.value=i.caret,this.caretRequest.value=i.caret}replace(e){this.text.value=e,this.caret.value=e.length,this.caretRequest.value=e.length,this.mentions.value=He(e,this.mentions.value)}setReply(e){this.replyTo.value=e}outgoing(){if(!this.canSend.value)return;let e=[...ot(this.text.value,this.mentions.value,this.#e.capabilities()?.commands??[]),...this.uploads.parts.value];if(e.length!==0)return{parts:e,replyTo:this.replyTo.value,replyAll:this.replyAll.value}}startEdit(e,t,n){this.editing.value=e,this.replyTo.value=void 0,this.mentions.value=n,this.replace(t)}cancelEdit(){this.editing.value=void 0,this.clear()}snapshot(){return{editing:this.editing.value,text:this.text.value,mentions:this.mentions.value,replyTo:this.replyTo.value,replyAll:this.replyAll.value}}restore(e){this.editing.value=e.editing,this.text.value=e.text,this.caret.value=e.text.length,this.mentions.value=e.mentions,this.replyTo.value=e.replyTo,this.replyAll.value=e.replyAll}clear(e=`clear`){this.text.value=``,this.caret.value=0,this.caretRequest.value=0,this.mentions.value=[],this.replyTo.value=void 0,this.editing.value=void 0,e===`clear`&&this.uploads.clear()}dispose(){clearTimeout(this.#r),this.uploads.clear()}#s(e,t){let n=Ue(this.text.value,e.start,e.end,t);this.text.value=n.text,this.caret.value=n.caret,this.caretRequest.value=n.caret}#c(){let e=this.text.value===``&&this.replyTo.value===void 0&&!this.replyAll.value;this.#n.value=e?void 0:{text:this.text.value,mentions:[...this.mentions.value],replyAll:this.replyAll.value,...this.replyTo.value===void 0?{}:{replyTo:this.replyTo.value}}}#l(){clearTimeout(this.#r);let e=++this.#i;this.pickerActive.value=0;let t=this.trigger.value,n=this.#e.capabilities();t===void 0||n===void 0?(this.pickerItems.value=[],this.pickerLoading.value=!1):t.kind===`command`?this.pickerItems.value=n.commands.filter(e=>Qd(t.query,e.name,e.description)).slice(0,this.#t.max).map(e=>({kind:`command`,key:`c:${e.context}:${e.name}`,command:e})):t.kind===`invoke`?this.pickerItems.value=n.invocations.filter(e=>Qd(t.query,e.fn,J(e.fn),e.description)).slice(0,this.#t.max).map(e=>({kind:`invoke`,key:`i:${e.fn}`,invocation:e})):(this.pickerLoading.value=!0,this.#r=setTimeout(()=>{this.#u(t.query,n.mentions,e)},this.#t.delay))}async#u(e,t,n){let r=await Promise.all(t.map(async t=>{try{return(await this.#e.api.mentions.call({session:this.session,provider:t.provider,query:e})).slice(0,this.#t.perProvider).map((e,n)=>({kind:`mention`,key:`m:${t.provider}:${n}:${e.label}`,provider:t.provider,group:t.title,option:e}))}catch{return[]}}));n===this.#i&&(this.pickerItems.value=r.flat().slice(0,this.#t.max),this.pickerLoading.value=!1)}},ef=class{#e;run=new W;tree=new W;treeTurn=I(void 0);resource=new W;calls=L(new Map);callProblems=L(new Map);constructor(e){this.#e=e}async openRun(e){this.run.value.value?.id!==e&&this.run.reset(),await this.run.load(()=>this.#e.run.call({run:e}),`Couldn't load this run.`,this.run.value.value?.id===e)}async openResource(e){this.resource.value.value?.stat.uri!==e&&this.resource.reset(),await this.resource.load(()=>this.#e.resource.call({uri:e,want:[`text`,`links`]}),`Couldn't open this.`)}async openTree(e){this.treeTurn.value!==e&&this.tree.reset(),this.treeTurn.value=e,await this.tree.load(()=>this.#e.tree.call({turn:e}),`Couldn't load this turn's tree.`)}refreshTree(){let e=this.treeTurn.value;e!==void 0&&this.tree.load(()=>this.#e.treeRefresh.call({turn:e}),`Couldn't refresh this turn's tree.`,!0)}closeTree(){this.#e.treeRefresh.cancel(),this.treeTurn.value=void 0,this.tree.reset()}async loadCalls(e){let t=[...new Set(e)].filter(e=>!this.calls.value.has(e));await Promise.all(t.map(async e=>{try{let t=await this.#e.llmCall.call({id:e}),n=new Map(this.calls.value);n.set(e,t),this.calls.value=n}catch(t){let n=new Map(this.callProblems.value);n.set(e,X(t,`Couldn't load this LLM call.`)),this.callProblems.value=n}}))}async loadTurn(e){await this.openTree(e);let t=this.tree.value.value;if(t===void 0)return[];let n=se(t);return await this.loadCalls(n),n.flatMap(e=>{let t=this.calls.value.get(e);return t===void 0?[]:[t]})}dispose(){this.#e.treeRefresh.cancel()}},tf=(e,t)=>`${e}:${JSON.stringify(t)}`,nf=class{#e;cards=L(new Map);constructor(e){this.#e=e}card(e,t){return this.cards.value.get(tf(e,t))??{loading:!0,hover:void 0,problem:``}}async load(e,t,n){let r=tf(t,n),i=this.cards.value.get(r);if(i===void 0||!i.loading&&i.problem!==``){this.#t(r,{loading:!0,hover:void 0,problem:``});try{let{hover:i}=await this.#e.mentionHover.call({session:e,provider:t,target:n});this.#t(r,{loading:!1,hover:i,problem:``})}catch(e){this.#t(r,{loading:!1,hover:void 0,problem:X(e,`Not available right now.`)})}}}#t(e,t){let n=new Map(this.cards.value);n.set(e,t),this.cards.value=n}},rf=Symbol.for(`harness.shared`);function af(e){Reflect.set(globalThis,rf,{vue:e.vue,"@harness/sdk":e.sdk})}function of(e){return typeof e==`object`&&!!e&&`system`in e&&typeof e.system==`string`&&`renderers`in e&&typeof e.renderers==`object`&&e.renderers!==null&&`contract`in e&&typeof e.contract==`object`&&e.contract!==null}function sf(e){return typeof e==`object`&&`component`in e&&`mode`in e}function cf(e,t){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n)]))}function lf(e){let t=e.indexOf(`/`);return{system:e.slice(0,t),local:e.slice(t+1)}}function uf(t,n){if(t===void 0)return{};if(!(t instanceof tr)){let r=e(t,n);return typeof r==`object`&&r?{...r}:{}}let r=t.fields;return Object.fromEntries(Object.entries(n).flatMap(([t,n])=>{let i=r[t];return i===void 0?[]:[[t,e(i.type,n)]]}))}function df(e){let t=e.renderers;return{renderers:{fns:t.fns??{},kinds:t.kinds??{},attachments:t.attachments??{},inputs:t.inputs??{},mentions:t.mentions??{},resultFns:t.results?.fns??{},resultKinds:t.results?.kinds??{}},config:ff(e),pages:pf(e),resultItems:Object.values(t.resultItems??{}),actions:e.contract.defs.actions,fns:e.contract.defs.fns,forms:Object.fromEntries(Object.entries(e.contract.defs.fns).map(([e,t])=>[e,t.form])),attachments:cf(e.contract.defs.attachments,e=>e.data),types:cf(e.contract.defs.types,e=>e.shape),mentions:cf(e.contract.defs.mentions,e=>e.target)}}function ff(e){let t=e.contract.configComponent,n=t===void 0?void 0:e.renderers.configs?.[t.component];return t===void 0||n===void 0?void 0:{component:n,mode:t.mode,type:e.contract.defs.config}}function pf(e){let t=e.renderers.pages??{};return new Map(e.contract.pages.flatMap(e=>{let n=t[e.component];return n===void 0?[]:[[e.segment,{decl:e,component:n}]]}))}var mf=class{#e=new Map;#t;#n=new Map;#r=new Map;#i=new Map;constructor(e){this.#t=e}register(e){this.#n.set(e.system,df(e));for(let t of this.#i.keys())(t===e.system||t.startsWith(`${e.system} `))&&this.#i.delete(t);for(let[t,n]of this.#r)this.#r.set(t,n.filter(t=>t.system!==e.system));for(let[t,n]of this.#e)this.#e.set(t,n.filter(t=>t.system!==e.system));for(let[t,n]of Object.entries(e.renderers.visuals??{})){let r=$n.parse(t),i=Object.entries(n).flatMap(([t,n])=>{let i=e.contract.contributes.find(e=>e.registry===r&&e.name===t);return i?.shape===void 0?[]:[{system:e.system,name:t,label:i.label,icon:i.icon,shape:i.shape,veto:(e,t)=>n.veto?.(e,t),component:n.component}]});this.#e.set(r,[...this.#e.get(r)??[],...i])}let t=e.renderers.resources??{};for(let[n,r]of Object.entries(t)){let t=sf(r)?{component:r.component,system:e.system,mode:r.mode,label:r.label??e.system}:{component:r,system:e.system,mode:`replace`,label:e.system};this.#r.set(n,[...this.#r.get(n)??[],t])}}async load(e){let t=await import(e),n=typeof t==`object`&&t&&`default`in t?t.default:void 0;if(!of(n))throw Error(`${e} is not a system client module (its default export should be client(contract, renderers)).`);return this.register(n),n}visuals(e,t,n){return(this.#e.get(e)??[]).flatMap(r=>{let i;try{i=r.veto(t,n)}catch(t){return console.warn(`client.visual.veto-failed`,{registry:e,system:r.system,name:r.name,error:t}),[]}return i===void 0?[{system:r.system,name:r.name,label:r.label,...r.icon===void 0?{}:{icon:r.icon},shape:r.shape,component:r.component,client:this.systemClient(r.system)}]:[]})}resultItems(e){return[...this.#n.entries()].flatMap(([t,n])=>n.resultItems.filter(n=>{try{return n.offered(e)}catch(e){return console.warn(`client.result-item.offered-failed`,{system:t,label:n.label,error:e}),!1}}))}systems(){return[...this.#n.keys()]}fnRenderer(e,t){return this.#s(e,`fns`)??(t===void 0?void 0:this.#s(t,`kinds`))}attachmentRenderer(e){return this.#s(e,`attachments`)}inputRenderer(e){return this.#s(e,`inputs`)}mentionRenderer(e){return this.#s(e,`mentions`)}resourceViewers(e){return this.#r.get(e)??[]}resourceViewer(e){return this.#a(e)?.component}viewerSystem(e){return this.#a(e)?.system}#a(e){return this.resourceViewers(e).find(e=>e.mode===`replace`)}systemClient(t,n){let r=n===void 0?t:`${t} ${n}`,i=this.#i.get(r);if(i!==void 0)return i;let a=this.#n.get(t),o=this.#t,s=n===void 0?{}:{run:n},l={get online(){return o.online(t)},send:Object.fromEntries(Object.entries(a?.actions??{}).map(([n,r])=>[n,i=>this.#c(t=>e(r.returns,t),()=>o.act({system:t,action:n,input:c(r.input,i),...s}))])),run:Object.fromEntries(Object.entries(a?.fns??{}).map(([e,n])=>[e,r=>Promise.resolve().then(()=>o.invoke({fn:nr(t,e),args:c(n.args,r)}))]))};return this.#i.set(r,l),l}submit(e,t,n){let r=c(t,n);return this.#c(()=>void 0,()=>this.#t.submit({run:e,value:r}))}formSubmit(e,t){let{system:n,local:r}=lf(e),i=this.#n.get(n)?.forms[r];return i===void 0?void 0:e=>this.submit(t,i,e)}fnView(t){let{fn:n,kind:r,args:i,result:a,state:o,...s}=t,c=this.#s(n,`fns`),l={...s,submit:this.formSubmit(n,t.run)};if(c!==void 0){let{system:r,local:s}=lf(n),u=this.#n.get(r)?.fns[s];if(u===void 0)return;let d=this.#o(n,()=>({args:e(u.args,i),state:uf(u.state,o),...a===void 0?{}:{result:e(u.returns,a)}}));return d===void 0?void 0:{component:c,props:{...l,...d,system:this.systemClient(r,t.run)}}}let u=r===void 0?void 0:this.#s(r,`kinds`);if(r!==void 0&&u!==void 0)return{component:u,props:{...l,args:i,state:o,...a===void 0?{}:{result:a},system:this.systemClient(lf(r).system,t.run)}}}drawsKind(e){return this.#s(e,`resultKinds`)!==void 0}resultView(t){let{kind:n,args:r,result:i,...a}=t,o=this.#s(t.fn,`resultFns`);if(o!==void 0){let{system:n,local:s}=lf(t.fn),c=this.#n.get(n)?.fns[s];if(c===void 0)return;let l=this.#o(t.fn,()=>({args:e(c.args,r),result:e(c.returns,i)}));return l===void 0?void 0:{component:o,props:{...a,...l,system:this.systemClient(n,t.run)}}}let s=n===void 0?void 0:this.#s(n,`resultKinds`);if(n!==void 0&&s!==void 0)return{component:s,props:{...a,args:r,result:i,system:this.systemClient(lf(n).system,t.run)}}}attachmentView(t){let n=this.#s(t.attachment,`attachments`),{system:r,local:i}=lf(t.attachment),a=this.#n.get(r)?.attachments[i];if(n===void 0||a===void 0)return;let o=this.#o(t.attachment,()=>e(a,t.data));return o===void 0?void 0:{component:n,props:{data:o,title:t.title,system:this.systemClient(r)}}}mentionView(t){let n=this.#s(t.provider,`mentions`),{system:r,local:i}=lf(t.provider),a=this.#n.get(r)?.mentions[i];if(n===void 0||a===void 0)return;let o=this.#o(t.provider,()=>e(a,t.target));return o===void 0?void 0:{component:n,props:{label:t.label,target:o,hover:t.hover,system:this.systemClient(r)}}}inputView(t){let n=this.#s(t,`inputs`),{system:r,local:i}=lf(t),a=this.#n.get(r)?.types[i];if(n!==void 0&&a!==void 0)return{component:n,props:{system:this.systemClient(r)},decode:n=>n===void 0?void 0:this.#o(t,()=>e(a,n)),encode:e=>e===void 0?void 0:this.#o(t,()=>c(a,e))}}configView(t,n){let r=this.#n.get(t)?.config;if(r===void 0)return;let i=nr(t,`config`),a=r.type;return{component:r.component,mode:r.mode,props:{config:n.config===void 0?void 0:this.#o(i,()=>e(a,n.config)),type:a,validate:e=>Promise.resolve().then(()=>n.validate(c(a,e))),change:e=>{n.change(c(a,e))},system:this.systemClient(t)}}}pages(e){return[...this.#n.get(e)?.pages.values()??[]].map(e=>e.decl)}pageView(e,t,n){let r=this.#n.get(e)?.pages.get(t);return r===void 0?void 0:{component:r.component,props:{...n,page:t,system:this.systemClient(e)}}}#o(e,t){try{return t()}catch(t){console.warn(`client.view.unfit`,{name:e,error:t});return}}#s(e,t){let{system:n,local:r}=lf(e);return this.#n.get(n)?.renderers[t][r]}#c(e,t){let n=this.#t,r=Te({id:void 0,status:jn.enum.queued}),i=t().then(async t=>(r.id=t,e(await n.follow(t,e=>{r.status=e}))));return i.catch(()=>void 0),{get id(){return r.id},get status(){return r.status},result:i}}},hf=class{runtime;#e;#t=new Map;#n;status=L(new Map);version=L(0);constructor(e){this.#e=e;let t={online:t=>e.online(t),act:({system:e,action:t,input:n,run:r})=>Promise.resolve().then(()=>this.#i().act(Un.parse(e),t,n,r)),submit:async({run:e,value:t})=>{let n=await this.#i().submit(e,t);if(n===void 0)throw Error(`Couldn't submit that.`);return n},invoke:async({fn:e,args:t})=>{let n=await this.#i().invoke(e,t);if(n===void 0)throw Error(`Couldn't run that.`);return n},follow:(e,t)=>Promise.resolve().then(()=>this.#i().follow(e,t))};this.runtime=new mf(t)}async sync(e){let t=e.filter(e=>this.#t.get(e.system)!==e.hash);t.length!==0&&(this.#n??=this.#e.share?.()??Promise.resolve(),await this.#n,await Promise.all(t.map(async e=>{this.#t.set(e.system,e.hash),this.#a(e.system,`loading`);try{await(this.#e.load??((e,t)=>e.load(t).then(()=>void 0)))(this.runtime,e.url),this.#a(e.system,`ready`),this.version.value++}catch(t){console.error(`chat.renderer.load-failed`,{system:e.system,url:e.url,error:t}),this.#a(e.system,`failed`)}})))}fnView(e,t){if(this.#r(),e.args===void 0)return;let n=cr(e),r=sr(e);return this.runtime.fnView({fn:e.fn,kind:e.kind===void 0||e.kind===`native`?void 0:e.kind,run:e.id,status:or(e),args:e.args,state:t,...n===void 0?{}:{result:n},...r===void 0?{}:{error:r},...e.progress===void 0?{}:{progress:e.progress}})}resultView(e,t){this.#r();let n=cr(e);if(e.status===`done`&&e.args!==void 0&&n!==void 0)return this.runtime.resultView({fn:e.fn,kind:e.kind===void 0||e.kind===`native`?void 0:e.kind,run:e.id,args:e.args,result:n,title:t})}drawsKind(e){return this.#r(),this.runtime.drawsKind(e)}storedResultView(e,t){if(this.#r(),e.outcome?.status===`done`)return this.runtime.resultView({fn:e.fn,kind:e.kind===`native`?void 0:e.kind,run:e.id,args:e.args,result:e.outcome.result??null,title:t})}pageView(e,t,n){return this.#r(),this.runtime.pageView(e,t,n)}attachmentView(e){return this.#r(),this.runtime.attachmentView({attachment:e.attachment,data:e.data,title:e.title})}inputView(e){this.#r();let t=$n.safeParse(e);return t.success?this.runtime.inputView(t.data):void 0}mentionView(e,t){return this.#r(),this.runtime.mentionView({provider:e.provider,label:e.label,target:e.target,hover:t})}contributedVisuals(e,t,n){return this.#r(),this.runtime.visuals(e,t,n)}resultItems(e){return this.#r(),this.runtime.resultItems(e)}#r(){return this.version.value}#i(){let e=this.#e.thread();if(e===void 0)throw Error(`No chat is open.`);return e}#a(e,t){let n=new Map(this.status.value);n.set(e,t),this.status.value=n}},gf=(e,t)=>t.updatedAt-e.updatedAt;function _f(e){return e.updatedAt===e.createdAt}function vf(e){return Qn.parse(e)}var yf=class{#e;#t;#n;#r;items=L([]);search=I(``);archived=I(!1);loading=I(!1);loadingMore=I(!1);loaded=I(!1);problem=I(``);creating=I(!1);partial=I(!1);#i=I(!1);hasMore=k(()=>this.#i.value);constructor(e,t){this.#e=e,this.#t=t}start(){this.#n===void 0&&(this.#n=this.#t(e=>{this.#u(e)}))}stop(){this.#n?.(),this.#n=void 0,this.#e.searchSessions.cancel()}load(){return this.#e.searchSessions.cancel(),this.#a(e=>this.#e.sessions.call(e))}async#a(e){this.loading.value=!0,this.problem.value=``;try{let t=await e(this.#s());this.items.value=t.items,this.#r=t.cursor,this.#i.value=t.cursor!==void 0,this.partial.value=pe(t),this.loaded.value=!0,this.loading.value=!1}catch(e){if(Fr(e))return;this.problem.value=X(e,`Couldn't load your chats.`),this.loading.value=!1}}async loadMore(){let e=this.#r;if(!(e===void 0||this.loadingMore.value)){this.loadingMore.value=!0;try{let t=await this.#e.sessions.call(this.#s(e)),n=new Set(this.items.value.map(e=>e.id));this.items.value=[...this.items.value,...t.items.filter(e=>!n.has(e.id))],this.#r=t.cursor,this.#i.value=t.cursor!==void 0}catch(e){this.problem.value=X(e,`Couldn't load more chats.`)}finally{this.loadingMore.value=!1}}}setSearch(e){this.search.value=e,this.#e.sessions.cancel(),this.#a(e=>this.#e.searchSessions.call(e))}async showArchived(e){this.archived.value=e,await this.load()}listed(e){return this.items.value.filter(t=>!_f(t)||t.id===e)}async create(e={}){if(this.creating.value)return;let t=e.agent===void 0&&e.title===void 0&&!this.archived.value?this.items.value.find(_f):void 0;if(t!==void 0)return t.id;this.creating.value=!0;try{let t=await this.#e.createSession.call(e);return this.#c(vf(t)),t.id}catch(e){this.problem.value=X(e,`Couldn't start a new chat.`);return}finally{this.creating.value=!1}}async rename(e,t){return this.#o(e,{title:t},e=>({...e,title:t}))}async archive(e,t){return this.#o(e,{archived:t},e=>({...e,archived:t}))}async remove(e){let t=this.items.value;this.items.value=t.filter(t=>t.id!==e);try{return await this.#e.deleteSession.call({session:e}),!0}catch(e){return this.items.value=t,this.problem.value=X(e,`Couldn't delete that chat.`),!1}}find(e){return this.items.value.find(t=>t.id===e)}remember(e){this.#c(e)}async#o(e,t,n){let r=this.items.value,i=r.find(t=>t.id===e);i!==void 0&&this.#c(n(i));try{let n=await this.#e.updateSession.call({session:e,...t});return this.#c(vf(n)),!0}catch(e){return this.items.value=r,this.problem.value=X(e,`Couldn't change that chat.`),!1}}#s(e){let t=te(ee(`sessions`,this.search.value)),n=t.filters??[],r={field:`archived`,op:`is`,value:this.archived.value};return h({query:n.some(e=>e.field===`archived`)?t:{...t,filters:[...n,r]}},40,e)}#c(e){let t=this.items.value.filter(t=>t.id!==e.id);if(!(e.archived===this.archived.value&&this.#l(e))){this.items.value=t;return}if((ee(`sessions`,this.search.value).sort??[]).length===0){this.items.value=[e,...t].sort(gf);return}let n=this.items.value.findIndex(t=>t.id===e.id);this.items.value=n<0?[e,...t]:this.items.value.map(t=>t.id===e.id?e:t)}#l(e){let t=(ee(`sessions`,this.search.value).text??``).toLowerCase();return t===``||e.title.toLowerCase().includes(t)}#u(e){e.type===`session-deleted`?this.items.value=this.items.value.filter(t=>t.id!==e.session):e.type===`session`&&(this.items.value.some(t=>t.id===e.session.id)||this.loaded.value)&&this.#c(e.session)}},bf=class{#e;#t;report=new W;text=I(``);constructor(e,t){this.#e=e,this.#t=t}async preview(e){let t=e.trim();t!==``&&(this.text.value=t,await this.report.load(()=>this.#e.previewSelection.call({session:this.#t,text:t}),`Couldn't preview this message.`))}clear(){this.text.value=``,this.report.reset()}},xf={minLength:12,limit:6},Sf=class{#e;#t;#n;#r=``;items=L([]);loading=I(!1);constructor(e,t,n=xf){this.#e=e,this.#t=t,this.#n=n}update(e){let t=e.trim();t.length<this.#n.minLength||t.startsWith(`/`)||t.startsWith(`!`)?this.clear():t!==this.#r&&this.#i(t)}clear(){this.#e.suggest.cancel(),this.items.value=[],this.loading.value=!1,this.#r=``}async#i(e){this.#r=e,this.loading.value=!0;try{let t=await this.#e.suggest.call({session:this.#t,text:e,limit:this.#n.limit});this.items.value=[...t].sort((e,t)=>t.score-e.score),this.loading.value=!1}catch(e){if(Fr(e))return;this.#r=``,this.items.value=[],this.loading.value=!1}}},Cf={delays:[500,1e3,2e3,4e3,8e3,15e3],sleep:e=>new Promise(t=>{setTimeout(t,e)})};async function wf(e,t,n,r=()=>void 0){for(let i=0;n();i++)try{return await e(),!0}catch(e){if(r(e),!n())return!1;await t.sleep(t.delays[Math.min(i,t.delays.length-1)]??1e3)}return!1}var Tf={now:()=>typeof document>`u`||document.visibilityState===`visible`,watch:e=>typeof document>`u`?()=>void 0:(document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)})},Ef={page:50,runsOnOpen:60,typingFor:6e3,presenceEvery:3e3};function Df(e){return{reports:e,undone:e.reduce((e,t)=>e+t.undone.length,0),failed:e.reduce((e,t)=>e+t.failed.length,0),notUndoable:e.reduce((e,t)=>e+t.notUndoable.length,0),kept:e.reduce((e,t)=>e+Of(t),0)}}function Of(e){return(e.kept??[]).reduce((e,t)=>e+t.effects.length,0)}function kf(e,t){return Dn(e,t.name,t.type)}var Af=class{id;#e;#t;#n;#r;#i=new Set;#a=new Map;#o=new Map;#s=new Map;#c=new Set;#l=new Set;#u=0;#d=!1;#f=!1;#p;session=L(void 0);messages=L([]);live=L(new Map);liveCites=L(new Map);runs=L(new Map);approvals=L([]);handlers=L([]);budgets=L([]);deliveries=L(new Map);presence=L([]);controls=L(void 0);state=L(new Map);#m=L(new Map);limits=L(void 0);status=I(`loading`);problem=I(``);stale=I(!1);#h=0;loadingOlder=I(!1);sending=I(!1);pending=L(void 0);stopping=I(!1);awaiting=I(void 0);#g=I(!1);#_=I(0);hasOlder=k(()=>this.#g.value);beginning=k(()=>this.status.value===`ready`&&!this.#g.value);running=k(()=>this.session.value?.status===`running`||this.awaiting.value!==void 0);paused=k(()=>this.session.value?.status===`paused`);spent=k(()=>[...this.runs.value.values()].reduce((e,t)=>e+t.cost,0));spentSince=k(()=>Math.max(0,this.spent.value-this.#_.value));background=k(()=>[...this.runs.value.values()].filter(e=>e.background&&!Kn(e.status)));failures=k(()=>{let e=0;for(let t of[...this.messages.value].reverse())if(!(t.role===`note`||this.undone.value.has(t.turn))){if(t.role===`assistant`&&t.status===`failed`)e++;else break}return e});typing=k(()=>this.presence.value.filter(e=>e.typing&&e.user!==this.#e.me()));notify=k(()=>this.session.value?.participants.find(e=>e.actor===this.#e.me())?.notify??`all`);undone=k(()=>Ye(this.messages.value));lastTurn=k(()=>[...this.messages.value].reverse().find(e=>e.role!==`note`&&!this.undone.value.has(e.turn))?.turn);canUndo=k(()=>this.controls.value?.undoLastTurn??(this.lastTurn.value!==void 0&&!this.running.value));canContinue=k(()=>!this.running.value&&this.controls.value?.continueLastTurn===!0);constructor(e,t,n=Ef){this.id=e,this.#e=t,this.#t=n}async open(){this.#n??=this.#e.events(this.id,e=>{this.#D(e)});let e=this.#e.looking??Tf;this.#p??=e.watch(()=>{this.reportPresence({typing:this.#d&&e.now()})}),this.reportPresence({typing:this.#d}),this.status.value=this.messages.value.length>0?`ready`:`loading`,this.problem.value=``;try{let e=await this.#v();this.loadLimits(),this.loadWaiting(),this.loadControls(),this.#w(e.flatMap(e=>e.runs).slice(-this.#t.runsOnOpen))}catch(e){let t=this.session.value!==void 0;this.status.value=t?`ready`:`error`,this.problem.value=X(e,t?`Couldn't catch up with this chat.`:`Couldn't open this chat.`)}}async#v(){let[e,t]=await Promise.all([this.#e.api.session.call({session:this.id}),this.#e.api.messages.call({session:this.id,limit:this.#t.page})]);this.session.value=e,this.#e.changed(vf(e));let n=[...t.items].reverse();for(let e of this.messages.value)n=Je(n,e);return this.messages.value=n,this.#r=t.cursor,this.#g.value=t.cursor!==void 0,this.status.value=`ready`,n}close(){this.#n?.(),this.#n=void 0;for(let e of this.#o.values())clearTimeout(e);this.#o.clear(),this.#p?.(),this.#p=void 0,(this.#d||this.#f)&&this.#S(!1,!1)}async refresh(){let e=++this.#h;this.stale.value=!0,this.#n??=this.#e.events(this.id,e=>{this.#D(e)}),await wf(()=>this.#y(),this.#e.retry??Cf,()=>e===this.#h&&this.#n!==void 0,e=>{this.problem.value=X(e,`Couldn't catch up with this chat.`),this.session.value===void 0&&(this.status.value=`error`)})&&e===this.#h&&(this.stale.value=!1,this.problem.value=``,this.status.value===`error`&&(this.status.value=`ready`),this.loadLimits())}async#y(){let e=await this.#v(),t=[...this.runs.value.values()].filter(e=>!Kn(e.status)).map(e=>e.id);await Promise.all([this.#b(),this.#w(e.flatMap(e=>e.runs).slice(-this.#t.runsOnOpen),!1,!0),this.#w(t,!0,!0),...[...this.#m.value.keys()].map(e=>this.loadState(e))])}stateOf(e){let t=this.#m.value.get(e);if(t===void 0)return this.loadState(e),{};let n={};for(let e of t.fields){let r=this.state.value.get(kf(t.system,e));r!==void 0&&(n[e.name]=r)}return n}async loadState(e){if(!this.#c.has(e)){this.#c.add(e);try{let{system:t,fields:n}=await this.#e.api.state.call({run:e});this.#O(t,n);let r=new Map(this.#m.value);r.set(e,{system:t,fields:n.map(({name:e,type:t})=>({name:e,type:t}))}),this.#m.value=r}catch{}finally{this.#c.delete(e)}}}async loadOlder(){let e=this.#r;if(!(e===void 0||this.loadingOlder.value)){this.loadingOlder.value=!0;try{let t=await this.#e.api.messages.call({session:this.id,limit:this.#t.page,cursor:e});this.messages.value=it(this.messages.value,t.items),this.#r=t.cursor,this.#g.value=t.cursor!==void 0,this.#w(t.items.flatMap(e=>e.runs))}catch(e){this.problem.value=X(e,`Couldn't load older messages.`)}finally{this.loadingOlder.value=!1}}}async loadWaiting(){try{await this.#b()}catch{}}async#b(){let e=await this.#e.api.waiting.call({session:this.id});this.approvals.value=[...e.approvals].sort((e,t)=>e.createdAt-t.createdAt);let t=this.#e.me();this.handlers.value=this.#x(e.handlers.filter(e=>`user`in e.answerer&&e.answerer.user===t)),this.#w([...e.approvals.map(e=>e.run),...e.handlers.map(e=>e.run)])}async loadLimits(){try{this.limits.value=await this.#e.api.limits.call({session:this.id}),this.#_.value=this.spent.value}catch{}}async send(e){if(this.sending.value||e.parts.length===0)return!1;this.sending.value=!0,this.pending.value={parts:e.parts,at:this.#e.clock()},this.problem.value=``;try{let t=await this.#e.api.send.call({session:this.id,parts:[...e.parts],client:this.#e.client(),...e.replyTo===void 0?{}:{replyTo:e.replyTo},...e.replyAll===!0?{replyAll:!0}:{}});return this.messages.value=Je(this.messages.value,t.message),this.awaiting.value=t.turn,this.#k(),this.reportPresence({typing:!1}),!0}catch(e){return this.problem.value=X(e,`Couldn't send that. Your message is back in the box.`),!1}finally{this.sending.value=!1,this.pending.value=void 0}}async invoke(e,t,n){try{let r=await this.#e.api.invoke.call({session:this.id,fn:e,args:t,...n===void 0?{}:{on:n},client:this.#e.client()});return this.#T(this.runs.value.get(r.run)??pr(r.run,e)),this.awaiting.value=r.turn,this.#k(),this.#w([r.run],!0),r.run}catch(e){this.problem.value=X(e,`Couldn't run that.`);return}}async control(e,t){this.stopping.value=e!==`resume`;try{return this.controls.value=await this.#e.api.control.call({session:this.id,action:e,...t===void 0||t.length===0?{}:{runs:[...t]}}),e===`cancel`&&(this.awaiting.value=void 0,this.loadWaiting()),!0}catch(e){return this.stopping.value=!1,this.problem.value=X(e,`Couldn't stop the turn.`),!1}}async toBackground(e){try{let{accepted:t}=await this.#e.api.background.call({run:e}),n=this.runs.value.get(e);return t&&n!==void 0&&this.#T({...n,background:!0}),t}catch(e){return this.problem.value=X(e,`Couldn't move that to the background.`),!1}}async undoTurn(e){try{let t=await this.#e.api.undoTurn.call({turn:e});for(let e of[...t.undone.map(e=>e.run)]){let t=this.runs.value.get(e);t!==void 0&&this.#T({...t,status:`undone`})}return t}catch(e){this.problem.value=X(e,`Couldn't undo that.`);return}}async loadControls(){try{this.controls.value=await this.#e.api.controls.call({session:this.id})}catch{}}async continueTurn(e){try{return await this.#e.api.continueTurn.call({turn:e}),!0}catch(e){return this.problem.value=X(e,`Couldn't continue that.`),!1}}async continueLast(){let e=this.lastTurn.value;return e!==void 0&&this.continueTurn(e)}async undoLast(){let e=this.lastTurn.value;return e===void 0?void 0:this.undoTurn(e)}turnMessage(e){return this.messages.value.find(t=>t.turn===e&&t.role===`user`)}async retry(e){let t=this.turnMessage(e);return t===void 0||await this.undoTurn(e)===void 0?!1:(await this.#C(),this.send({parts:Ke(t.parts),replyTo:t.replyTo,replyAll:t.replyAll}))}turnsFrom(e){let t=this.messages.value.findIndex(t=>t.id===e);if(t===-1)return[];let n=[];for(let e of this.messages.value.slice(t))e.role!==`note`&&!this.undone.value.has(e.turn)&&!n.includes(e.turn)&&n.push(e.turn);return n.reverse()}async editResend(e,t){let n=this.messages.value.find(t=>t.id===e);if(n===void 0)return;let r=[];for(let t of this.turnsFrom(e)){let e=await this.undoTurn(t);if(e===void 0)return;r.push(e)}return await this.#C(),await this.send({parts:t,replyTo:n.replyTo,replyAll:n.replyAll})?Df(r):void 0}async approve(e,t,n,r,i){let a=this.approvals.value,o=a.find(t=>t.id===e)?.run;this.approvals.value=a.filter(t=>t.id!==e);try{return t&&o!==void 0&&this.#l.add(o),await this.#e.api.approve.call({approval:e,approve:t,remember:n,...r===void 0||r===``?{}:{reason:r},...i===void 0?{}:{answer:i}}),!0}catch(e){return o!==void 0&&this.#l.delete(o),this.approvals.value=a,this.problem.value=X(e,`Couldn't send your answer.`),!1}}#x(e){let t=[];for(let n of e)this.#l.has(n.run)&&ut(n)?this.answer(n.id,!0):t.push(n);return t}async approveAll(e,t,n){let r=this.approvals.value.filter(t=>e.includes(t.id));return(await Promise.all(r.map(e=>this.approve(e.id,t,Qe(e)?n:`once`)))).every(Boolean)}async raiseBudget(e,t){let{setBy:n,...r}=e.budget;try{return await this.#e.api.setBudget.call({...r,maxCost:r.maxCost+t}),this.leaveBudget(e),!0}catch(e){return this.problem.value=X(e,`Couldn't raise the budget.`),!1}}leaveBudget(e){this.budgets.value=this.budgets.value.filter(t=>t.budget.id!==e.budget.id)}async answer(e,t){let n=this.handlers.value;this.handlers.value=n.filter(t=>t.id!==e);try{return await this.#e.api.answer.call({call:e,value:t}),!0}catch(e){return this.handlers.value=n,this.problem.value=X(e,`Couldn't send your answer.`),!1}}async submit(e,t){try{return(await this.#e.api.submit.call({run:e,value:t})).delivery}catch(e){this.problem.value=X(e,`Couldn't submit that.`);return}}async act(e,t,n,r){let{delivery:i}=await this.#e.api.act.call({session:this.id,system:e,action:t,input:n,client:this.#e.client(),...r===void 0?{}:{run:r}});return i}follow(e,t){return new Promise((n,r)=>{let i={status:t,resolve:n,reject:r},a=this.deliveries.value.get(e);a!==void 0&&this.#E(a,i)||this.#s.set(e,[...this.#s.get(e)??[],i])})}async update(e){try{let t=await this.#e.api.updateSession.call({session:this.id,...e});return this.session.value=t,this.#e.changed(vf(t)),e.priority!==void 0&&this.loadLimits(),!0}catch(e){return this.problem.value=X(e,`Couldn't change this chat.`),!1}}reportPresence(e){let t=(this.#e.looking??Tf).now();e.typing===this.#d&&t===this.#f&&(!e.typing||this.#e.clock()-this.#u<this.#t.presenceEvery)||this.#S(e.typing,t)}#S(e,t){this.#d=e,this.#f=t,this.#u=this.#e.clock(),this.#e.api.presence.call({session:this.id,typing:e,focused:t}).catch(()=>void 0)}citesOf(e){return e.citations??this.liveCites.value.get(e.id)??[]}liveOf(e){return this.live.value.get(e.id)}runsOf(e){let t=e.runs.filter(e=>!this.runs.value.has(e));return t.length>0&&this.#w(t),e.runs.flatMap(e=>{let t=this.runs.value.get(e);return t===void 0?[]:[this.shown(t)]})}shown(e){let t=this.handlers.value.some(t=>t.run===e.id);return t===(e.asking===!0)?e:{...e,asking:t}}async ensureRun(e,t=!1){await this.#w([e],t)}async#C(){try{let e=await this.#e.api.messages.call({session:this.id,limit:this.#t.page});this.messages.value=[...e.items].reverse(),this.#r=e.cursor,this.#g.value=e.cursor!==void 0}catch{}}async#w(e,t=!1,n=!1){let r=[...new Set(e)].filter(e=>!this.#i.has(e)&&(t||this.runs.value.get(e)?.createdAt===void 0)),i=[];if(await Promise.all(r.map(async e=>{this.#i.add(e);try{let t=await this.#e.api.run.call({run:e});this.#T(dr(this.runs.value.get(e),t))}catch(e){i.push(e)}finally{this.#i.delete(e)}})),n&&i.length>0)throw i[0]}#T(e){let t=new Map(this.runs.value);t.set(e.id,e),this.runs.value=t}#E(e,t){return t.status(e.status),e.status===`done`?(t.resolve(e.result??null),!0):e.status===`failed`||e.status===`expired`?(t.reject(Error(e.error?.message??(e.status===`expired`?`It expired before the system came online.`:`It failed.`))),!0):!1}#D(e){switch(e.type){case`message`:{let t=this.#a.get(e.message.id);this.#a.delete(e.message.id);let n=t!==void 0&&e.message.status===`streaming`?nt(e.message,t):e.message;this.#M(n),this.messages.value=Je(this.messages.value,n),n.role===`assistant`&&n.turn===this.awaiting.value&&(this.awaiting.value=void 0),this.#w(n.runs);return}case`token`:{let t=this.messages.value.findIndex(t=>t.id===e.message),n=this.messages.value[t];if(this.#j(e.message,{kind:`text`,text:e.text}),n===void 0){this.#a.set(e.message,(this.#a.get(e.message)??``)+e.text);return}let r=[...this.messages.value];r[t]=nt(n,e.text),this.messages.value=r,n.turn===this.awaiting.value&&(this.awaiting.value=void 0);return}case`reasoning`:this.#j(e.message,{kind:`reasoning`,text:e.text});return;case`cite`:{let t=new Map(this.liveCites.value);t.set(e.message,[...(t.get(e.message)??[]).filter(t=>t.index!==e.cite.index),e.cite]),this.liveCites.value=t;return}case`run`:{let t=this.runs.value.get(e.run)??pr(e.run,e.fn);this.#T(lr(t,e.update,this.#e.clock()));let n=e.update.type===`status`&&Kn(e.update.status),r=e.update.type===`result`;(t.createdAt===void 0||n||r)&&this.#w([e.run],n||r),(n||e.update.type===`cost`)&&this.#A(e.run),e.update.type===`status`&&ur(e.update.status)&&(this.awaiting.value=void 0);return}case`controls`:this.controls.value=e.controls,this.stopping.value=!1;return;case`approval`:{let t=this.approvals.value.filter(t=>t.id!==e.approval.id);this.approvals.value=e.approval.status===`pending`?[...t,e.approval].sort((e,t)=>e.createdAt-t.createdAt):t;return}case`handler`:{let t=this.handlers.value.filter(t=>t.id!==e.call.id),n=`user`in e.call.answerer&&e.call.answerer.user===this.#e.me();this.handlers.value=e.call.status===`pending`&&n?[...t,...this.#x([e.call])]:t;return}case`delivery`:{let t=new Map(this.deliveries.value);t.set(e.delivery.id,e.delivery),this.deliveries.value=t;let n=(this.#s.get(e.delivery.id)??[]).filter(t=>!this.#E(e.delivery,t));n.length===0?this.#s.delete(e.delivery.id):this.#s.set(e.delivery.id,n);return}case`budget`:{let{type:t,...n}=e;this.budgets.value=[...this.budgets.value.filter(e=>e.budget.id!==n.budget.id),n];return}case`presence`:this.#N(e.presence);return;case`compare`:return;case`state`:this.#O(e.system,e.fields);return;case`session`:{let t=this.session.value;t!==void 0&&(this.session.value={...t,...e.session}),e.session.status===`idle`&&(this.awaiting.value=void 0,this.stopping.value=!1,this.loadLimits()),this.#e.changed(e.session);return}}}#O(e,t){let n=new Map(this.state.value);for(let r of t){let t=kf(e,r);r.value===void 0?n.delete(t):n.set(t,r.value)}this.state.value=n}#k(){this.controls.value=void 0,this.stopping.value=!1}#A(e){this.approvals.value.some(t=>t.run===e)&&(this.approvals.value=this.approvals.value.filter(t=>t.run!==e)),this.handlers.value.some(t=>t.run===e)&&(this.handlers.value=this.handlers.value.filter(t=>t.run!==e)),this.budgets.value.some(t=>t.run===e)&&(this.budgets.value=this.budgets.value.filter(t=>t.run!==e))}#j(e,t){let n=this.messages.value.find(t=>t.id===e),r=this.live.value.get(e)??(n===void 0?[]:et(n)),i=new Map(this.live.value);i.set(e,$e(r,t)),this.live.value=i}#M(e){let t=this.live.value.get(e.id);if(t===void 0||e.role!==`assistant`)return;if(e.status!==`streaming`){let n=new Map(this.live.value);n.set(e.id,qe(t,e)),this.live.value=n;return}let n=new Set(t.flatMap(e=>e.kind===`runs`?e.runs:[])),r=e.runs.filter(e=>!n.has(e));r.length>0&&this.#j(e.id,{kind:`runs`,runs:r})}#N(e){this.presence.value=[...this.presence.value.filter(t=>t.user!==e.user),e],clearTimeout(this.#o.get(e.user)),e.typing&&this.#o.set(e.user,setTimeout(()=>{this.presence.value=this.presence.value.map(t=>t.user===e.user?{...t,typing:!1}:t)},this.#t.typingFor))}},jf=class{#e;#t=L(new Map);#n=new Map;source={visuals:(e,t,n)=>(this.prepare(e),this.#e.renderers.contributedVisuals(e,t,n))};constructor(e){this.#e=e}visuals(e,t,n){let r=this.#e.renderers.contributedVisuals(e,t,n).map(e=>({name:e.name,label:e.label,icon:Zr(e.icon)?e.icon:`layers`,system:e.system,shape:e.shape,component:O(e.component),props:{system:e.client}}));return Qr(Pe,r,t,n)}prepare(e){let t=this.#n.get(e);if(t!==void 0)return t;let n=(async()=>{try{(await this.#e.api.contributions.call({registry:e})).length>0&&await this.#e.prepare()}catch(t){this.#n.delete(e),console.error(`chat.visuals.contributions-failed`,{registry:e,error:t})}})();return this.#n.set(e,n),n}choice(e){return this.#t.value.get(e)}choose(e,t){this.#t.value=new Map([...this.#t.value,[e,t]])}},Mf=class{#e;#t=[];static available(){return typeof navigator<`u`&&`mediaDevices`in navigator&&typeof navigator.mediaDevices.getUserMedia==`function`&&typeof MediaRecorder<`u`}async start(){let e=await navigator.mediaDevices.getUserMedia({audio:!0});this.#t=[];let t=new MediaRecorder(e);t.ondataavailable=e=>{e.data.size>0&&this.#t.push(e.data)},t.start(),this.#e=t}stop(){let e=this.#e;return e===void 0?Promise.reject(Error(`Not recording.`)):new Promise(t=>{e.onstop=()=>{for(let t of e.stream.getTracks())t.stop();t(new Blob(this.#t,{type:e.mimeType===``?`audio/webm`:e.mimeType}))},e.stop(),this.#e=void 0})}cancel(){let e=this.#e;e!==void 0&&(e.onstop=()=>{for(let t of e.stream.getTracks())t.stop()},e.stop(),this.#e=void 0)}},Nf=class{#e;#t;#n;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}start(){return this.#e.start()}async stop(){let e=await this.#e.stop(),t=await this.#t(e);return(await this.#n.transcribe.call({audio:t})).text}cancel(){this.#e.cancel()}};function Pf(e){let t=Reflect.get(e,`SpeechRecognition`)??Reflect.get(e,`webkitSpeechRecognition`);if(typeof t==`function`)return()=>{let e=Reflect.construct(t,[]);if(!Ff(e))throw Error(`This browser’s speech recognition is not usable.`);return e}}function Ff(e){return typeof e==`object`&&!!e&&typeof Reflect.get(e,`start`)==`function`&&typeof Reflect.get(e,`stop`)==`function`}var If=new Set([`not-allowed`,`service-not-allowed`]),Lf=class{#e;#t;#n=[];#r;#i;constructor(e){this.#e=e}start(e){let t=this.#e();return this.#n=[],this.#r=void 0,t.lang=e??``,t.continuous=!0,t.interimResults=!1,t.onresult=e=>{this.#n=Array.from(e.results).filter(e=>e.isFinal).map(e=>e[0]?.transcript.trim()??``)},t.onend=()=>{this.#i?.()},new Promise((e,n)=>{t.onerror=e=>{this.#r=e.error,If.has(e.error)&&n(new DOMException(`The microphone is blocked.`,`NotAllowedError`))},t.start(),this.#t=t,e()})}stop(){let e=this.#t;return e===void 0?Promise.reject(Error(`Not listening.`)):(this.#t=void 0,new Promise((t,n)=>{this.#i=()=>{this.#i=void 0,this.#r!==void 0&&this.#r!==`no-speech`&&this.#n.length===0?n(Error(`Speech recognition failed (${this.#r}).`)):t(this.#n.filter(e=>e!==``).join(` `))},e.stop()}))}cancel(){this.#i=void 0,this.#t?.abort(),this.#t=void 0}},Rf=class{#e;#t;#n;state=I(`idle`);startedAt=I(0);problem=I(``);constructor(e,t=Date.now){this.#e=e,this.#t=t}can(e){return this.#e[e]!==void 0}async start(e,t){if(this.state.value===`recording`||this.state.value===`transcribing`)return;this.problem.value=``;let n=this.#e[e];if(n===void 0)this.state.value=`failed`,this.problem.value=e===`browser`?`This browser can’t recognise speech. An admin can switch dictation to a model.`:`This browser can’t record audio.`;else try{await n.start(t),this.#n=n,this.startedAt.value=this.#t(),this.state.value=`recording`}catch(e){let t=e instanceof DOMException&&(e.name===`NotAllowedError`||e.name===`SecurityError`);this.state.value=t?`denied`:`failed`,this.problem.value=t?`The microphone is blocked. Allow it in your browser’s site settings to dictate.`:`Couldn't start the microphone.`}}async stop(){let e=this.#n;if(this.state.value===`recording`&&e!==void 0){this.#n=void 0,this.state.value=`transcribing`;try{let t=await e.stop();return this.state.value=`idle`,t}catch(e){this.state.value=`failed`,this.problem.value=X(e,`Couldn't transcribe that.`);return}}}cancel(){this.state.value===`recording`&&this.#n?.cancel(),this.#n=void 0,this.state.value=`idle`}dismiss(){this.problem.value=``,(this.state.value===`denied`||this.state.value===`failed`)&&(this.state.value=`idle`)}};function zf(e=Date.now){return{timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,locale:navigator.language,now:e()}}var Bf=class{listValues;pickers;access;connections;sessions;capabilities;inspector;types;collapse;renderers;mentions;visuals;approvals;#e=L(new Map);#t=new Set;current=I(void 0);#n;#r=new Map;#i=new Map;#a=new Map;#o=new Map;#s;constructor(e){this.#n=e,this.listValues=e.api.listValues,this.pickers=new Ld(e.api),this.access=new bd(e.api),this.connections=new Id(e.api),this.sessions=new yf(e.api,e.userEvents),this.capabilities=new zd(e.api,e.userEvents),this.inspector=new ef(e.api),this.types=new en(t=>e.api.types.call({names:[...t]})),this.collapse=new Wd(e.store),this.mentions=new nf(e.api),this.renderers=new hf({thread:()=>this.current.value===void 0?void 0:this.#r.get(this.current.value),online:e=>this.capabilities.online(e),...e.renderers}),this.visuals=new jf({api:e.api,renderers:this.renderers,prepare:()=>this.prepareRenderers()}),this.approvals=new Os(e.api)}start(){this.sessions.start(),this.capabilities.start()}stop(){this.sessions.stop(),this.capabilities.stop();for(let e of this.#r.values())e.close()}titleOf(e){let t=this.sessions.items.value.find(t=>t.id===e);if(t!==void 0)return t.title===``?void 0:t.title;let n=this.#e.value.get(e);if(n!==void 0)return n===``?void 0:n;let r=Bn.safeParse(e);r.success&&!this.#t.has(e)&&(this.#t.add(e),this.#n.api.session.call({session:r.data}).then(t=>{this.#e.value=new Map([...this.#e.value,[e,t.title]])},()=>void 0))}thread(e){let t=this.#r.get(e);if(t!==void 0)return this.#r.delete(e),this.#r.set(e,t),t;let n=new Af(e,{api:this.#n.api,events:this.#n.sessionEvents,clock:this.#n.clock,client:this.#n.client,me:this.#n.me,changed:e=>{this.sessions.remember(e)},...this.#n.retry===void 0?{}:{retry:this.#n.retry}},this.#n.thread??Ef);this.#r.set(e,n);for(let[t,n]of this.#r){if(this.#r.size<=5)break;t!==e&&t!==this.current.value&&(n.close(),this.#r.delete(t))}return n}async sessionOfRun(e){return(await this.#n.api.run.call({run:e})).session}composer(e){let t=this.#i.get(e);if(t!==void 0)return t;let n=new $d({session:e,store:this.#n.store,api:this.#n.api,capabilities:()=>this.capabilities.value.value,uploads:new Zs(this.#n.api,this.#n.sender,this.#n.previews)});return this.#i.set(e,n),n}suggestions(e){let t=this.#a.get(e);if(t!==void 0)return t;let n=new Sf(this.#n.api,e);return this.#a.set(e,n),n}preview(e){let t=this.#o.get(e);if(t!==void 0)return t;let n=new bf(this.#n.api,e);return this.#o.set(e,n),n}startCompare(e,t){return Gd(this.#n.api,this.thread(e),this.composer(e),t,this.#n.client())}compare(e,t){return new qd({api:this.#n.api,events:this.#n.sessionEvents},e,t)}voice(){if(this.#s===void 0){let e=this.#n.recorder(),t=this.#n.speech?.(),n={...e===void 0?{}:{model:new Nf(e,e=>this.#l(e),this.#n.api)},...t===void 0?{}:{browser:new Lf(t)}};this.#s=Object.keys(n).length===0?null:new Rf(n,this.#n.clock)}return this.#s??void 0}async open(e){let t=this.current.value;t!==void 0&&t!==e&&this.#r.get(t)?.close(),this.current.value=e;let n=this.thread(e);return await Promise.all([n.open(),this.#c(e)]),n}leave(){let e=this.current.value;e!==void 0&&this.#r.get(e)?.close(),this.current.value=void 0}async refresh(){let e=this.current.value;await Promise.all([this.sessions.loaded.value?this.sessions.load():Promise.resolve(),this.#c(e),e===void 0?Promise.resolve():this.thread(e).refresh()])}async prepareRenderers(){this.capabilities.value.value===void 0&&await this.#c(this.current.value)}async#c(e){await this.capabilities.load(e);let t=this.capabilities.value.value;t!==void 0&&this.renderers.sync(t.clients)}#l(e){let t=e.type.includes(`ogg`)?`ogg`:e.type.includes(`mp4`)?`m4a`:`webm`;return Ys(this.#n.api,this.#n.sender,e,`dictation.${t}`,()=>void 0,new AbortController().signal)}},Vf={endpoints:{setup:{method:`GET`,path:`/setup`,ws:`setup`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},createAdmin:{method:`POST`,path:`/createAdmin`,ws:`createAdmin`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`email`,`name`,`password`,`setup`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},signIn:{method:`POST`,path:`/signIn`,ws:`signIn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`email`,`password`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},refresh:{method:`POST`,path:`/refresh`,ws:`refresh`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`refresh`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},redeemSso:{method:`POST`,path:`/redeemSso`,ws:`redeemSso`,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`code`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},signOut:{method:`POST`,path:`/signOut`,ws:`signOut`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},me:{method:`GET`,path:`/me`,ws:`me`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},account:{method:`GET`,path:`/account`,ws:`account`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},capabilities:{method:`POST`,path:`/capabilities`,ws:`capabilities`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},types:{method:`POST`,path:`/types`,ws:`types`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},sessions:{method:`POST`,path:`/sessions`,ws:`sessions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},session:{method:`POST`,path:`/session`,ws:`session`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},createSession:{method:`POST`,path:`/createSession`,ws:`createSession`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`agent`,`systems`,`title`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateSession:{method:`POST`,path:`/updateSession`,ws:`updateSession`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`title`,`systems`,`agent`,`archived`,`priority`,`notify`,`model`,`mode`,`contextor`,`fnMode`,`instructions`,`citations`,`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},deleteSession:{method:`POST`,path:`/deleteSession`,ws:`deleteSession`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},limits:{method:`POST`,path:`/limits`,ws:`limits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},messages:{method:`POST`,path:`/messages`,ws:`messages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},send:{method:`POST`,path:`/send`,ws:`send`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`parts`,`replyTo`,`replyAll`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},compare:{method:`POST`,path:`/compare`,ws:`compare`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`parts`,`variants`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},compareView:{method:`POST`,path:`/compareView`,ws:`compareView`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},chooseVariant:{method:`POST`,path:`/chooseVariant`,ws:`chooseVariant`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`,`variant`,`adopt`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},invoke:{method:`POST`,path:`/invoke`,ws:`invoke`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`fn`,`args`,`on`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},control:{method:`POST`,path:`/control`,ws:`control`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`action`,`runs`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},controls:{method:`POST`,path:`/controls`,ws:`controls`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},presence:{method:`POST`,path:`/presence`,ws:`presence`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`focused`,`typing`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},background:{method:`POST`,path:`/background`,ws:`background`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},undoTurn:{method:`POST`,path:`/undoTurn`,ws:`undoTurn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},continueTurn:{method:`POST`,path:`/continueTurn`,ws:`continueTurn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},tree:{method:`POST`,path:`/tree`,ws:`tree`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`turn`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},run:{method:`POST`,path:`/run`,ws:`run`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},llmCall:{method:`POST`,path:`/llmCall`,ws:`llmCall`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},waiting:{method:`POST`,path:`/waiting`,ws:`waiting`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approve:{method:`POST`,path:`/approve`,ws:`approve`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`approval`,`approve`,`remember`,`reason`,`answer`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},answer:{method:`POST`,path:`/answer`,ws:`answer`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`call`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},act:{method:`POST`,path:`/act`,ws:`act`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`system`,`action`,`input`,`run`,`client`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},submit:{method:`POST`,path:`/submit`,ws:`submit`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},state:{method:`POST`,path:`/state`,ws:`state`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},suggest:{method:`POST`,path:`/suggest`,ws:`suggest`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mentions:{method:`POST`,path:`/mentions`,ws:`mentions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`provider`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mentionHover:{method:`POST`,path:`/mentionHover`,ws:`mentionHover`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`provider`,`target`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resource:{method:`POST`,path:`/resource`,ws:`resource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`want`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},notifications:{method:`POST`,path:`/notifications`,ws:`notifications`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`unread`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},readNotifications:{method:`POST`,path:`/readNotifications`,ws:`readNotifications`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`ids`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pushKey:{method:`GET`,path:`/pushKey`,ws:`pushKey`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},subscribePush:{method:`POST`,path:`/subscribePush`,ws:`subscribePush`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`endpoint`,`keys`,`device`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},upload:{method:`POST`,path:`/upload`,ws:`upload`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`mime`,`size`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},uploaded:{method:`POST`,path:`/uploaded`,ws:`uploaded`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`upload`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},transcribe:{method:`POST`,path:`/transcribe`,ws:`transcribe`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`audio`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systems:{method:`POST`,path:`/systems`,ws:`systems`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},system:{method:`POST`,path:`/system`,ws:`system`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pairings:{method:`POST`,path:`/pairings`,ws:`pairings`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`status`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approvePairing:{method:`POST`,path:`/approvePairing`,ws:`approvePairing`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`pairing`,`approve`,`instance`,`config`,`autoPair`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},createPairingToken:{method:`POST`,path:`/createPairingToken`,ws:`createPairingToken`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`expiresIn`,`autoPair`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},configureSystem:{method:`POST`,path:`/configureSystem`,ws:`configureSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`config`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},enableSystem:{method:`POST`,path:`/enableSystem`,ws:`enableSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`functions`,`renderers`,`context`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},switchItem:{method:`POST`,path:`/switchItem`,ws:`switchItem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`section`,`name`,`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},switchPart:{method:`POST`,path:`/switchPart`,ws:`switchPart`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`section`,`name`,`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeSystem:{method:`POST`,path:`/removeSystem`,ws:`removeSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`keepStore`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},installSystem:{method:`POST`,path:`/installSystem`,ws:`installSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`source`,`config`,`autoStart`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStore:{method:`POST`,path:`/systemStore`,ws:`systemStore`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreMove:{method:`POST`,path:`/systemStoreMove`,ws:`systemStoreMove`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`to`,`runs`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreMoveState:{method:`POST`,path:`/systemStoreMoveState`,ws:`systemStoreMoveState`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreMoveAnswer:{method:`POST`,path:`/systemStoreMoveAnswer`,ws:`systemStoreMoveAnswer`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`answer`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreBackups:{method:`POST`,path:`/systemStoreBackups`,ws:`systemStoreBackups`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemStoreBackupDelete:{method:`POST`,path:`/systemStoreBackupDelete`,ws:`systemStoreBackupDelete`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`backup`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},startSystem:{method:`POST`,path:`/startSystem`,ws:`startSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},stopSystem:{method:`POST`,path:`/stopSystem`,ws:`stopSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},restartSystem:{method:`POST`,path:`/restartSystem`,ws:`restartSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`reason`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},upgradeSystem:{method:`POST`,path:`/upgradeSystem`,ws:`upgradeSystem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`version`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},reimport:{method:`POST`,path:`/reimport`,ws:`reimport`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},configureProvider:{method:`POST`,path:`/configureProvider`,ws:`configureProvider`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},providers:{method:`POST`,path:`/providers`,ws:`providers`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setModelCategory:{method:`POST`,path:`/setModelCategory`,ws:`setModelCategory`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`name`,`description`,`models`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setBudget:{method:`POST`,path:`/setBudget`,ws:`setBudget`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`target`,`period`,`maxCost`,`maxTokens`,`maxCalls`,`maxTime`,`share`,`onLimit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setPriority:{method:`POST`,path:`/setPriority`,ws:`setPriority`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`target`,`default`,`max`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setPolicy:{method:`POST`,path:`/setPolicy`,ws:`setPolicy`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`,`description`,`subject`,`target`,`decision`,`priority`,`expiresAt`,`yields`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setActorSetting:{method:`POST`,path:`/setActorSetting`,ws:`setActorSetting`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`setting`,`actor`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},addUser:{method:`POST`,path:`/addUser`,ws:`addUser`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`email`,`name`,`role`,`groups`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},addGroup:{method:`POST`,path:`/addGroup`,ws:`addGroup`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`about`,`members`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateUser:{method:`POST`,path:`/updateUser`,ws:`updateUser`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`user`,`name`,`role`,`disabled`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setMembership:{method:`POST`,path:`/setMembership`,ws:`setMembership`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`group`,`user`,`member`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSignInPolicy:{method:`POST`,path:`/setSignInPolicy`,ws:`setSignInPolicy`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSignInLimits:{method:`POST`,path:`/setSignInLimits`,ws:`setSignInLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`account`,`address`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setProxyTrust:{method:`POST`,path:`/setProxyTrust`,ws:`setProxyTrust`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`proxies`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemFns:{method:`POST`,path:`/systemFns`,ws:`systemFns`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemParts:{method:`POST`,path:`/systemParts`,ws:`systemParts`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemLogs:{method:`POST`,path:`/systemLogs`,ws:`systemLogs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},models:{method:`POST`,path:`/models`,ws:`models`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`provider`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelCategories:{method:`POST`,path:`/modelCategories`,ws:`modelCategories`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},budgets:{method:`POST`,path:`/budgets`,ws:`budgets`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},priorityRules:{method:`POST`,path:`/priorityRules`,ws:`priorityRules`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resolveLimits:{method:`POST`,path:`/resolveLimits`,ws:`resolveLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`user`,`session`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},policies:{method:`POST`,path:`/policies`,ws:`policies`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},actors:{method:`POST`,path:`/actors`,ws:`actors`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`kind`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},actorSettings:{method:`POST`,path:`/actorSettings`,ws:`actorSettings`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},runs:{method:`POST`,path:`/runs`,ws:`runs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},llmCalls:{method:`POST`,path:`/llmCalls`,ws:`llmCalls`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resources:{method:`POST`,path:`/resources`,ws:`resources`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeRule:{method:`POST`,path:`/removeRule`,ws:`removeRule`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},indexStatus:{method:`POST`,path:`/indexStatus`,ws:`indexStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},browseResources:{method:`POST`,path:`/browseResources`,ws:`browseResources`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`search`,`system`,`family`,`source`,`under`,`form`,`missing`,`group`,`in`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},resourceForms:{method:`POST`,path:`/resourceForms`,ws:`resourceForms`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},readResource:{method:`POST`,path:`/readResource`,ws:`readResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`form`,`section`,`offset`,`maxChars`,`rows`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},convertResource:{method:`POST`,path:`/convertResource`,ws:`convertResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`kind`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},downloadResource:{method:`POST`,path:`/downloadResource`,ws:`downloadResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`form`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},importResource:{method:`POST`,path:`/importResource`,ws:`importResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},renameResource:{method:`POST`,path:`/renameResource`,ws:`renameResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},deleteResource:{method:`POST`,path:`/deleteResource`,ws:`deleteResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextFromResource:{method:`POST`,path:`/contextFromResource`,ws:`contextFromResource`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`sections`,`copy`,`weight`,`tags`,`fns`,`suggestFns`,`inject`,`command`,`visible`,`suggest`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contexts:{method:`POST`,path:`/contexts`,ws:`contexts`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextItem:{method:`POST`,path:`/contextItem`,ws:`contextItem`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},remember:{method:`POST`,path:`/remember`,ws:`remember`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`title`,`scope`,`about`,`question`,`when`,`weight`,`summary`,`tags`,`fns`,`suggestFns`,`inject`,`command`,`visible`,`suggest`,`parent`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateMemory:{method:`POST`,path:`/updateMemory`,ws:`updateMemory`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`title`,`about`,`question`,`when`,`weight`,`summary`,`tags`,`fns`,`suggestFns`,`inject`,`command`,`visible`,`suggest`,`parent`,`name`,`clear`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},forget:{method:`POST`,path:`/forget`,ws:`forget`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},linkContext:{method:`POST`,path:`/linkContext`,ws:`linkContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`from`,`to`,`relation`,`weight`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},unlinkContext:{method:`POST`,path:`/unlinkContext`,ws:`unlinkContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`from`,`toKey`,`relation`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextMetadata:{method:`POST`,path:`/contextMetadata`,ws:`contextMetadata`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setContextStatus:{method:`POST`,path:`/setContextStatus`,ws:`setContextStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`,`action`,`reason`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextReview:{method:`POST`,path:`/contextReview`,ws:`contextReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`kinds`,`systems`,`limit`,`cursor`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mergeContext:{method:`POST`,path:`/mergeContext`,ws:`mergeContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`keep`,`drop`,`reason`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},notDuplicate:{method:`POST`,path:`/notDuplicate`,ws:`notDuplicate`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`,`of`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},reextractContext:{method:`POST`,path:`/reextractContext`,ws:`reextractContext`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},newContextStatus:{method:`POST`,path:`/newContextStatus`,ws:`newContextStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setNewContextStatus:{method:`POST`,path:`/setNewContextStatus`,ws:`setNewContextStatus`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextPlans:{method:`POST`,path:`/contextPlans`,ws:`contextPlans`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contextPlan:{method:`POST`,path:`/contextPlan`,ws:`contextPlan`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`,`format`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},answerPlan:{method:`POST`,path:`/answerPlan`,ws:`answerPlan`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`run`,`answers`,`reasons`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelLimits:{method:`POST`,path:`/modelLimits`,ws:`modelLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`model`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewSelection:{method:`POST`,path:`/previewSelection`,ws:`previewSelection`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setModelLimits:{method:`POST`,path:`/setModelLimits`,ws:`setModelLimits`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`model`,`limits`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewPrompt:{method:`POST`,path:`/previewPrompt`,ws:`previewPrompt`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`,`model`,`count`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelRoles:{method:`POST`,path:`/modelRoles`,ws:`modelRoles`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setModelRole:{method:`POST`,path:`/setModelRole`,ws:`setModelRole`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},clearModelRole:{method:`POST`,path:`/clearModelRole`,ws:`clearModelRole`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`role`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelCalls:{method:`POST`,path:`/modelCalls`,ws:`modelCalls`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`run`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},modelCall:{method:`POST`,path:`/modelCall`,ws:`modelCall`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnMetrics:{method:`POST`,path:`/fnMetrics`,ws:`fnMetrics`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`system`,`days`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnMetricsDays:{method:`POST`,path:`/fnMetricsDays`,ws:`fnMetricsDays`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`days`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mcps:{method:`POST`,path:`/mcps`,ws:`mcps`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mcp:{method:`POST`,path:`/mcp`,ws:`mcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},createMcp:{method:`POST`,path:`/createMcp`,ws:`createMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`slug`,`name`,`instructions`,`rules`,`toolMode`,`user`,`grantees`,`origins`,`enabled`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateMcp:{method:`POST`,path:`/updateMcp`,ws:`updateMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`slug`,`name`,`instructions`,`rules`,`toolMode`,`user`,`grantees`,`origins`,`enabled`,`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},rotateMcpSecret:{method:`POST`,path:`/rotateMcpSecret`,ws:`rotateMcpSecret`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},deleteMcp:{method:`POST`,path:`/deleteMcp`,ws:`deleteMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewMcp:{method:`POST`,path:`/previewMcp`,ws:`previewMcp`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`rules`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},mcpSessions:{method:`POST`,path:`/mcpSessions`,ws:`mcpSessions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`mcp`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pairing:{method:`POST`,path:`/pairing`,ws:`pairing`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`pairing`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},instances:{method:`POST`,path:`/instances`,ws:`instances`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},installPackage:{method:`POST`,path:`/installPackage`,ws:`installPackage`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`zip`,`instance`,`config`,`data`,`autoStart`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeInstance:{method:`POST`,path:`/removeInstance`,ws:`removeInstance`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`keepStore`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},addInstance:{method:`POST`,path:`/addInstance`,ws:`addInstance`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`description`,`config`,`store`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exportSystemData:{method:`POST`,path:`/exportSystemData`,ws:`exportSystemData`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`withSecrets`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},query:{method:`POST`,path:`/query`,ws:`query`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`list`,`query`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},listValues:{method:`POST`,path:`/listValues`,ws:`listValues`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`list`,`field`,`prefix`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fns:{method:`POST`,path:`/fns`,ws:`fns`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`filters`,`sort`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},suggestDecision:{method:`POST`,path:`/suggestDecision`,ws:`suggestDecision`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSuggestDecision:{method:`POST`,path:`/setSuggestDecision`,ws:`setSuggestDecision`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},searchDecisions:{method:`POST`,path:`/searchDecisions`,ws:`searchDecisions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setSearchDecision:{method:`POST`,path:`/setSearchDecision`,ws:`setSearchDecision`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`item`,`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},previewSuggestions:{method:`POST`,path:`/previewSuggestions`,ws:`previewSuggestions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`session`,`text`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},autoPairs:{method:`POST`,path:`/autoPairs`,ws:`autoPairs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},revokeAutoPair:{method:`POST`,path:`/revokeAutoPair`,ws:`revokeAutoPair`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},imageEmbedding:{method:`POST`,path:`/imageEmbedding`,ws:`imageEmbedding`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setImageEmbedding:{method:`POST`,path:`/setImageEmbedding`,ws:`setImageEmbedding`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:`raw`,f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},outsideImages:{method:`POST`,path:`/outsideImages`,ws:`outsideImages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setOutsideImages:{method:`POST`,path:`/setOutsideImages`,ws:`setOutsideImages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`value`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},https:{method:`POST`,path:`/https`,ws:`https`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setHttps:{method:`POST`,path:`/setHttps`,ws:`setHttps`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},accessInfo:{method:`POST`,path:`/accessInfo`,ws:`accessInfo`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},access:{method:`POST`,path:`/access`,ws:`access`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`targets`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setAccess:{method:`POST`,path:`/setAccess`,ws:`setAccess`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`target`,`sharing`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},connectPages:{method:`POST`,path:`/connectPages`,ws:`connectPages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},connect:{method:`POST`,path:`/connect`,ws:`connect`,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`,`key`,`form`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateConnection:{method:`POST`,path:`/updateConnection`,ws:`updateConnection`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`connection`,`settings`,`fns`,`share`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},disconnect:{method:`POST`,path:`/disconnect`,ws:`disconnect`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`connection`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},pick:{method:`POST`,path:`/pick`,ws:`pick`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`source`,`text`,`values`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approvals:{method:`POST`,path:`/approvals`,ws:`approvals`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`runs`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},contributions:{method:`POST`,path:`/contributions`,ws:`contributions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`registry`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemPages:{method:`POST`,path:`/systemPages`,ws:`systemPages`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemInstances:{method:`POST`,path:`/systemInstances`,ws:`systemInstances`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},searchFns:{method:`POST`,path:`/searchFns`,ws:`searchFns`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`match`,`items`,`kinds`,`systems`,`instance`,`visibility`,`types`,`modes`,`effects`,`names`,`filters`,`off`,`statuses`,`returnNotApplicable`,`semanticOver`,`scopes`,`available`,`niches`,`order`,`offset`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnExamples:{method:`POST`,path:`/fnExamples`,ws:`fnExamples`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`query`,`offset`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnFacts:{method:`POST`,path:`/fnFacts`,ws:`fnFacts`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`args`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},fnsOfModelNames:{method:`POST`,path:`/fnsOfModelNames`,ws:`fnsOfModelNames`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`names`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},clientLogs:{method:`POST`,path:`/clientLogs`,ws:`clientLogs`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`entries`,`page`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},autoClassifier:{method:`POST`,path:`/autoClassifier`,ws:`autoClassifier`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setAutoClassifier:{method:`POST`,path:`/setAutoClassifier`,ws:`setAutoClassifier`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`model`,`messages`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exploreRoots:{method:`POST`,path:`/exploreRoots`,ws:`exploreRoots`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exploreList:{method:`POST`,path:`/exploreList`,ws:`exploreList`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`cursor`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},exploreRead:{method:`POST`,path:`/exploreRead`,ws:`exploreRead`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`uri`,`want`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},systemReview:{method:`POST`,path:`/systemReview`,ws:`systemReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},goLive:{method:`POST`,path:`/goLive`,ws:`goLive`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`,`off`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},approveReview:{method:`POST`,path:`/approveReview`,ws:`approveReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`,`off`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},rejectReview:{method:`POST`,path:`/rejectReview`,ws:`rejectReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},decideReview:{method:`POST`,path:`/decideReview`,ws:`decideReview`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`hash`,`approve`,`decline`,`off`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},testCall:{method:`POST`,path:`/testCall`,ws:`testCall`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`args`,`instance`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},refusals:{method:`POST`,path:`/refusals`,ws:`refusals`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`system`,`rule`,`cursor`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},graph:{method:`POST`,path:`/graph`,ws:`graph`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`text`,`filters`,`systems`,`external`,`focus`,`collapse`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},injections:{method:`POST`,path:`/injections`,ws:`injections`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`agent`,`context`,`mode`,`fnMode`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},setInjection:{method:`POST`,path:`/setInjection`,ws:`setInjection`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`agent`,`context`,`on`,`order`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},identity:{method:`GET`,path:`/identity`,ws:`identity`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},setHubName:{method:`POST`,path:`/setHubName`,ws:`setHubName`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},itemVersions:{method:`POST`,path:`/itemVersions`,ws:`itemVersions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`system`,`section`,`name`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},dataSets:{method:`POST`,path:`/dataSets`,ws:`dataSets`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`system`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},records:{method:`POST`,path:`/records`,ws:`records`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`query`,`search`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},record:{method:`POST`,path:`/record`,ws:`record`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},recordTable:{method:`POST`,path:`/recordTable`,ws:`recordTable`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`query`,`search`,`run`,`offset`,`limit`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},saveRecord:{method:`POST`,path:`/saveRecord`,ws:`saveRecord`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`value`,`expect`,`run`,`owner`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},updateRecord:{method:`POST`,path:`/updateRecord`,ws:`updateRecord`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`set`,`expect`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},removeRecord:{method:`POST`,path:`/removeRecord`,ws:`removeRecord`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`type`,`id`,`run`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},recordVersions:{method:`POST`,path:`/recordVersions`,ws:`recordVersions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`type`,`id`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},rowActions:{method:`POST`,path:`/rowActions`,ws:`rowActions`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`types`,`narrow`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},readFn:{method:`POST`,path:`/readFn`,ws:`readFn`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`fn`,`args`,`on`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},export:{method:`GET`,path:`/export`,ws:null,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:`text/csv`,items:!1,p:[],q:[`fn`,`args`,`offset`,`limit`,`format`],b:null,f:[],hasBody:!1,hasHeaders:!1,multi:!1,bodyEnc:null},people:{method:`POST`,path:`/people`,ws:`people`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`filters`,`sort`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},groups:{method:`POST`,path:`/groups`,ws:`groups`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`text`,`filters`,`sort`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},groupMembers:{method:`POST`,path:`/groupMembers`,ws:`groupMembers`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`cursor`,`limit`,`group`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},signInSettings:{method:`POST`,path:`/signInSettings`,ws:`signInSettings`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},checkSsoProvider:{method:`POST`,path:`/checkSsoProvider`,ws:`checkSsoProvider`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`provider`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},testSsoSignIn:{method:`POST`,path:`/testSsoSignIn`,ws:`testSsoSignIn`,httpOnly:!0,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`provider`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`},ssoTestResult:{method:`POST`,path:`/ssoTestResult`,ws:`ssoTestResult`,httpOnly:!1,streamIn:null,itemsIn:!1,streamOut:null,items:!1,p:[],q:[],b:[`test`],f:[],hasBody:!0,hasHeaders:!1,multi:!1,bodyEnc:`json`}},events:{systemLog:{ws:`on.systemLog`,hasParams:!0},session:{ws:`on.session`,hasParams:!0},user:{ws:`on.user`,hasParams:!0}}},Hf={whileDisconnected:`queue`,heartbeat:{interval:3e4,timeout:1e4},backoff:{initial:500,max:15e3}};async function Uf(e,t){let n=await e();return n&&t.reconnect(),n}function Wf(e){let t=wn(()=>{let t=e.token();return`${e.origin.replace(/^http/,`ws`)}/ws${t===``?``:`?access_token=${encodeURIComponent(t)}`}`},Hf),n=e.unauthorized;return{hub:yn({baseUrl:`${e.origin}/api`,manifest:Vf,headers:()=>{let t=e.token();return t===``?{}:{authorization:`Bearer ${t}`}},ws:t,prefer:`ws`,...n===void 0?{}:{unauthorized:()=>Uf(n,t)}}),socket:t}}function Gf(e){return e instanceof hn?e.status:0}function Kf(e){let t=Vf.endpoints[e];return{method:t.method,endpoint:t.path}}function qf(e,t,n=Date.now){let r=(r,i)=>{let a=Kf(r),o=new WeakMap,s=(e,t)=>{let n=typeof e==`object`&&e?o.get(e):void 0;n!==void 0&&(n.status=t)};return e.caller(r,{...i,onStart:e=>{typeof e==`object`&&e&&o.set(e,{at:n(),status:0}),i?.onStart?.(e)},onSuccess:(e,t)=>{s(t,200),i?.onSuccess?.(e,t)},onError:(e,t)=>{s(t,Gf(e)),i?.onError?.(e,t)},onSettled:e=>{let r=typeof e==`object`&&e?e:void 0,s=r===void 0?void 0:o.get(r);r!==void 0&&s!==void 0&&(o.delete(r),t({at:s.at,...a,status:s.status,duration:Math.max(0,Math.round(n()-s.at))})),i?.onSettled?.(e)}})};return{...e,caller:r}}var Jf={wait:5e3,maxWait:3e4,max:500},Yf=4e3,Xf=3e3,Zf=1e3,Qf=`[hidden]`,$f=/token|password|passwd|secret|authorization|cookie|api[-_]?key|private[-_]?key|credential/i,ep=[/(bearer\s+)[\w.~+/=-]+/gi,/\beyJ[\w-]+\.[\w-]+\.[\w-]+/g],tp={log:`info`,info:`info`,warn:`warn`,error:`error`};function np(e){return ep.reduce((e,t)=>e.replace(t,(e,t)=>typeof t==`string`?`${t}${Qf}`:Qf),e)}function rp(e){if(typeof e==`string`)return np(e).slice(0,Zf);if(e instanceof Error)return np(`${e.name}: ${e.message}`).slice(0,Zf);if(e===void 0||typeof e==`function`||typeof e==`symbol`)return String(e);try{return np(JSON.stringify(e,(e,t)=>e!==``&&$f.test(e)?Qf:t)).slice(0,Zf)}catch{return Object.prototype.toString.call(e)}}function ip(e){return e.map(rp).join(` `).slice(0,Yf)}function ap(e){return e.caller(`clientLogs`,{debounce:{wait:Jf.wait,maxWait:Jf.maxWait,accumulate:e=>{let t=e.at(-1);return{entries:e.flatMap(e=>e.entries).slice(-Jf.max),...t?.page===void 0?{}:{page:t.page}}}},retry:{attempts:3}})}function op(e){return e instanceof Error?{message:`${e.name}: ${e.message}`.slice(0,Yf),fields:e.stack===void 0?{}:{stack:e.stack.slice(0,Xf)}}:{message:String(e).slice(0,Yf),fields:{}}}var sp=class{#e;#t;constructor(e){this.#e=e,this.#t=e.clock??Date.now}log(e,t,n={}){let r=Object.fromEntries(Object.entries(n).map(([e,t])=>[e,$f.test(e)?Qf:np(t)]));this.#r({type:`log`,at:this.#t(),level:e,message:np(t).slice(0,Yf),...Object.keys(r).length===0?{}:{fields:r}})}error(e,t){let{message:n,fields:r}=op(e);this.log(`error`,n,{source:t,...r})}traffic(e){this.#r({type:`traffic`,at:e.at,method:e.method.slice(0,16),endpoint:e.endpoint.slice(0,300),status:e.status,duration:e.duration})}watch(e,t=console){let n=e=>{this.error(e.error??e.message,`window`)},r=e=>{this.error(e.reason,`promise`)};e.addEventListener(`error`,n),e.addEventListener(`unhandledrejection`,r);let i=this.#n(t);return()=>{e.removeEventListener(`error`,n),e.removeEventListener(`unhandledrejection`,r),i()}}#n(e){let t=Object.keys(tp).filter(e=>e in tp),n=t.map(t=>[t,Object.getOwnPropertyDescriptor(e,t)]),r=!1;for(let n of t){let t=e[n].bind(e);e[n]=(...e)=>{if(t(...e),!r){r=!0;try{this.log(tp[n],ip(e),{source:`console`})}finally{r=!1}}}}return()=>{for(let[t,r]of n)r===void 0?Reflect.deleteProperty(e,t):Object.defineProperty(e,t,r)}}#r(e){if(!this.#e.signedIn())return;let t={entries:[e],page:this.#e.page().slice(0,300)};this.#e.send.call(t).catch(()=>void 0)}},cp=An.endpoints.createAdmin.cfg.body,lp=An.endpoints.signIn.cfg.body,up=`harness.sign-in`,dp=K({remember:En(),email:q().optional()}),fp=class{#e;#t;#n;remembered;setup=L();loading=I(!0);busy=I(!1);problem=I(``);fields=L({});constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.remembered=(n===void 0?void 0:Br(n,`harness.sign-in`,dp))??{remember:!0}}get needsAdmin(){return this.setup.value?.needsAdmin===!0}get providers(){return this.setup.value?.sso??[]}async finishSso(e){this.busy.value=!0,this.problem.value=``;try{return this.#t.keep(await this.#e.redeemSso.call({code:e},Al),this.remembered.remember),!0}catch(e){return this.problem.value=X(e,`That sign-in didn’t finish. Sign in again.`),!1}finally{this.busy.value=!1}}async load(){this.loading.value=!0,this.problem.value=``;try{this.setup.value=await this.#e.setup.call(Al)}catch(e){this.problem.value=X(e)}finally{this.loading.value=!1}}async submit(e){let t=this.needsAdmin?Z(cp,e):Z(lp,e);if(this.fields.value=t.ok?{}:t.problems,this.problem.value=``,!t.ok)return!1;this.busy.value=!0;try{let t=this.needsAdmin?await this.#e.createAdmin.call({email:e.email,name:e.name,password:e.password,setup:e.setup??``},Al):await this.#e.signIn.call({email:e.email,password:e.password},Al),n=e.remember??!0;return this.#t.keep(t,n),this.#n?.setItem(up,JSON.stringify(n?{remember:n,email:e.email}:{remember:n})),!0}catch(e){return this.problem.value=X(e,`Couldn't sign in. Try again.`),!1}finally{this.busy.value=!1}}},pp=6e4,mp=`harness.refresh`,hp=class{#e=new Map;run(e,t){let n=(this.#e.get(e)??Promise.resolve()).catch(()=>void 0).then(t);return this.#e.set(e,n),n}},gp=class{#e;#t=new hp;constructor(e){this.#e=e?.locks}run(e,t){return this.#e===void 0?this.#t.run(e,t):this.#e.request(e,t).then(e=>e)}},_p=class{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n=Date.now,r=new hp){this.#e=e,this.#t=t,this.#n=n,this.#r=r}start(){this.#a??=S(this.#t.expiresAt,e=>{this.#c(e)},{immediate:!0})}stop(){this.#a?.(),this.#a=void 0,clearTimeout(this.#i)}refresh(e=`due`){let t=this.#t.refreshToken.value;return this.#r.run(mp,async()=>{this.#t.reload();let n=this.#t.refreshToken.value;if(n===``)return!1;if(n!==t||e===`due`&&!this.#s())return!0;try{return this.#t.keep(await this.#e.refresh.call({refresh:n},Al)),!0}catch{return this.#t.forget(),!1}})}recover(){return this.#o??=this.refresh(`refused`).finally(()=>{this.#o=void 0}),this.#o}async signOut(){try{await this.#e.signOut.call()}catch{}this.#t.forget()}#s(){let e=this.#t.expiresAt.value;return e!==void 0&&e-6e4<=this.#n()}#c(e){clearTimeout(this.#i),e!==void 0&&(this.#i=setTimeout(()=>{this.refresh()},Math.max(0,e-pp-this.#n())))}},vp=class{#e;view=new W;constructor(e){this.#e=e}load(){return this.view.load(()=>this.#e.account.call(),`Couldn’t load your account.`,this.view.value.value!==void 0)}},yp=1500,bp=2500,xp=class{state=I(`online`);#e=new Set;#t;#n;#r=!1;constructor(e){this.#t=e.subscribe(e=>{this.#i(e)}),e.status===`offline`&&this.#i(`offline`)}onReconnect(e){return this.#e.add(e),()=>{this.#e.delete(e)}}dispose(){this.#t(),clearTimeout(this.#n)}#i(e){if(e===`offline`){if(this.#r)return;this.#r=!0,clearTimeout(this.#n),this.#n=setTimeout(()=>{this.state.value=`offline`},yp)}else if(this.#r){this.#r=!1,clearTimeout(this.#n);for(let e of this.#e)e();this.state.value===`offline`&&(this.state.value=`back`,this.#n=setTimeout(()=>{this.state.value=`online`},bp))}}},Sp=class{#e;#t;#n;state=I(`off`);busy=I(!1);problem=I(``);constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}async check(){this.#t.supported()?this.#t.permission()===`denied`?this.state.value=`blocked`:this.state.value=await this.#t.current().catch(()=>void 0)===void 0?`off`:`on`:this.state.value=`unsupported`}async enable(){if(this.state.value===`unsupported`)return!1;this.busy.value=!0,this.problem.value=``;try{let{publicKey:e}=await this.#e.pushKey.call(),t=await this.#t.subscribe(e);return t===void 0?(this.state.value=this.#t.permission()===`denied`?`blocked`:`off`,!1):(await this.#e.subscribePush.call({endpoint:t.endpoint,keys:{p256dh:t.keys.p256dh,auth:t.keys.auth},device:this.#n()}),this.state.value=`on`,!0)}catch(e){return this.problem.value=X(e,`Couldn't turn on notifications.`),!1}finally{this.busy.value=!1}}async disable(){this.busy.value=!0;try{await this.#t.unsubscribe(),this.state.value=`off`}finally{this.busy.value=!1}}},Cp={built:`/sw.js`,source:`/sw/sw.ts`};function wp(e){let t=`${e}${`=`.repeat((4-e.length%4)%4)}`.replace(/-/g,`+`).replace(/_/g,`/`),n=atob(t),r=new Uint8Array(new ArrayBuffer(n.length));for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}var Tp=K({endpoint:q(),keys:K({p256dh:q(),auth:q()})}),Ep=class{#e;#t;constructor(e,t){this.#t=t,this.#e=e}supported(){return this.#e.isSecureContext&&`serviceWorker`in this.#e.navigator&&`PushManager`in this.#e&&`Notification`in this.#e}permission(){return Notification.permission}async current(){let e=await(await this.#e.navigator.serviceWorker.getRegistration(this.#t))?.pushManager.getSubscription();return e==null?void 0:Tp.parse(e.toJSON())}async subscribe(e){if(await Notification.requestPermission()!==`granted`)return;let t=await this.#e.navigator.serviceWorker.register(this.#t,{type:`module`,scope:`/`});await this.#e.navigator.serviceWorker.ready;let n=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:wp(e)});return Tp.parse(n.toJSON())}async unsubscribe(){await(await(await this.#e.navigator.serviceWorker.getRegistration(this.#t))?.pushManager.getSubscription())?.unsubscribe()}},Dp=class{#e;view=L(void 0);loading=new U;saving=new U;authority=k(()=>this.view.value?.on===!0&&this.view.value.source===`own`?ln.der:void 0);constructor(e){this.#e=e}async load(){let e=await this.loading.run(()=>this.#e.https.call({}),`Couldn't read the hub's secure connection.`);e.ok&&(this.view.value=e.value)}async set(e){let t=await this.saving.run(()=>this.#e.setHttps.call({on:e}),`Couldn't save the setting.`);return t.ok&&(this.view.value=t.value),t}};function Op(e,t){let n=new URL(t,e);return n.protocol=`http:`,n.toString()}var kp=class{#e;#t;#n=[];state=I(`browser`);sheetOpen=I(!1);secure;constructor(e){this.#e=e,this.secure=e.secure(),this.#r(),this.#n.push(e.onPrompt(e=>{this.#t=e,this.#r()}),e.onChange(()=>{this.#t=void 0,this.#r()}))}get offered(){return this.state.value===`ready`||this.state.value===`ios`}#r(){let e=this.#e;this.state.value=e.standalone()?`installed`:e.secure()?this.#t===void 0?e.ios()?`ios`:`browser`:`ready`:`insecure`}async install(){if(this.state.value===`ios`)return this.sheetOpen.value=!0,`sheet`;let e=this.#t;if(this.state.value!==`ready`||e===void 0)return`unavailable`;this.#t=void 0,await e.prompt();let{outcome:t}=await e.userChoice;return this.#r(),t}stop(){for(let e of this.#n.splice(0))e()}},Ap=[`standalone`,`window-controls-overlay`,`minimal-ui`,`fullscreen`],jp=class{#e;constructor(e){this.#e=e}standalone(){return this.#e.navigator.standalone===!0||Ap.some(e=>this.#e.matchMedia(`(display-mode: ${e})`).matches)}secure(){return this.#e.isSecureContext}ios(){let e=this.#e.navigator;return/iPhone|iPad|iPod/.test(e.userAgent)||/Macintosh/.test(e.userAgent)&&e.maxTouchPoints>1}onPrompt(e){let t=t=>{Mp(t)&&(t.preventDefault(),e(t))};return this.#e.addEventListener(`beforeinstallprompt`,t),()=>{this.#e.removeEventListener(`beforeinstallprompt`,t)}}onChange(e){let t=Ap.map(e=>this.#e.matchMedia(`(display-mode: ${e})`));for(let n of t)n.addEventListener(`change`,e);return this.#e.addEventListener(`appinstalled`,e),()=>{for(let n of t)n.removeEventListener(`change`,e);this.#e.removeEventListener(`appinstalled`,e)}}};function Mp(e){return`prompt`in e&&typeof e.prompt==`function`&&`userChoice`in e}async function Np(e,t){if(e.isSecureContext&&`serviceWorker`in e.navigator)try{await e.navigator.serviceWorker.register(t,{type:`module`,scope:`/`})}catch{}}var Pp=`harness.session`,Fp=ir.pick({access:!0,refresh:!0,user:!0}).extend({expiresAt:On,remember:En().optional()}),Ip=`harness.alive`;function Lp(e){return{alive:()=>e.cookie.split(`;`).some(e=>e.trim()===`${Ip}=1`),set:()=>{e.cookie=`${Ip}=1; Path=/; SameSite=Lax`},clear:()=>{e.cookie=`${Ip}=; Path=/; Max-Age=0; SameSite=Lax`}}}var Rp=class{#e;#t;#n;#r;constructor(e,t=Date.now,n,r){this.#e=e,this.#t=t,this.#r=r,this.#n=Ur(e,Pp,Fp.optional(),void 0),this.#n.value?.remember===!1&&r!==void 0&&!r.alive()&&(this.#n.value=void 0),n?.(e=>{(e===null||e===`harness.session`)&&this.reload()})}accessToken=k(()=>this.#n.value?.access??``);refreshToken=k(()=>this.#n.value?.refresh??``);user=k(()=>this.#n.value?.user);signedIn=k(()=>this.#n.value!==void 0);expiresAt=k(()=>this.#n.value?.expiresAt);remembered=k(()=>this.#n.value?.remember!==!1);keep(e,t){let n=t??this.#n.value?.remember??!0;t===!1&&this.#r?.set(),this.#n.value={access:e.access,refresh:e.refresh,user:e.user,expiresAt:this.#t()+e.expiresIn,...n?{}:{remember:!1}}}forget(){this.#n.value=void 0}reload(){let e=Br(this.#e,Pp,Fp);(e?.access!==this.#n.value?.access||e?.refresh!==this.#n.value?.refresh)&&(this.#n.value=e)}},zp=class{#e;query=L({});facets=L([]);list;groups=L(new Map);folders=L(new Map);selected=L(new Set);uploads=L([]);acting=new U;importing=new U;selectedCount=k(()=>this.selected.value.size);#t=0;#n;#r;#i=new Map;#a=new Map;#o=0;constructor(e){this.#e=e,this.list=new f({fetch:async(t,n,r)=>{let i=await e.api.browse.call(h(t,r,n));return this.facets.value=n===void 0?i.facets:d(this.facets.value,i.facets),i},key:e=>e.uri,failure:`Couldn't load resources.`,limit:60},{})}start(){return this.#n??=this.#e.events(()=>{clearTimeout(this.#r),this.#r=setTimeout(()=>{this.refresh()},500)}),()=>{this.stop()}}stop(){this.#n?.(),this.#n=void 0,clearTimeout(this.#r)}async show(e){this.query.value=e,this.#o++,this.selected.value=new Set,await this.list.load(_(e)),e.view===`groups`&&e.in===void 0&&await this.#s(e)}async refresh(){let e=this.query.value;await Promise.all([this.list.refresh(),...e.view===`groups`&&e.in===void 0?[this.#s(e,!0)]:[]])}async#s(e,t=!1){let n=this.#o,r=new Map;await Promise.all(this.facets.value.map(async n=>{let i=(t?this.groups.value.get(n.value):void 0)??new W;r.set(n.value,i),await i.load(()=>this.#e.api.browseGroup.call(me(e,n)),`Couldn't load this group.`,t)})),n===this.#o&&(this.groups.value=r)}async openFolder(e,t=!1){let n=this.folders.value.get(e);if(n!==void 0&&!t)return;let r=n??new W;n===void 0&&(this.folders.value=new Map([...this.folders.value,[e,r]])),await r.load(async()=>(await this.#e.api.browseGroup.call(p(this.query.value,e))).facets,`Couldn't load the folders.`)}peek(e){let t=`${e.uri}@${e.stat.version}`,n=this.#a.get(t);if(n!==void 0)return n;let r=new W;return this.#a.set(t,r),r.load(()=>this.#c(e),``,!0),r}async#c(e){let t=$r(e.stat);if(e.forms?.includes(`thumbnail`)===!0)return{kind:`image`,url:(await this.#e.api.download.call({uri:e.uri,form:`thumbnail`})).url};if(t===`image`)return{kind:`image`,url:(await this.#e.api.download.call({uri:e.uri})).url};if(t===`code`||t===`document`||t===`data`||t===`table`||t===`web`){let t=await this.#e.api.read.call({uri:e.uri,maxChars:400});return t.text.trim()===``?{kind:`none`}:{kind:`text`,text:t.text}}return{kind:`none`}}toggle(e){let t=new Set(this.selected.value);t.has(e)?t.delete(e):t.add(e),this.selected.value=t}toggleAll(){let e=this.list.items.value.map(e=>e.uri);this.selected.value=e.every(e=>this.selected.value.has(e))?new Set:new Set(e)}clearSelection(){this.selected.value=new Set}async importUrl(e){let t=await this.importing.run(()=>this.#e.api.importResource.call({url:e}),`Couldn't import that address.`);return t.ok&&this.list.refresh(),t}async refetch(e){let t=e.flatMap(e=>{let t=mt(e);return t===void 0?[]:[{url:t,name:e.stat.name}]}),n=await this.acting.run(()=>Promise.all(t.map(e=>this.#e.api.importResource.call(e))),`Couldn't fetch that again.`);if(n.ok)return this.list.refresh(),n.value.length}async upload(e){await Promise.all(e.map(e=>this.#l(e))),this.list.refresh()}async#l(e){let t=++this.#t,n=new AbortController;this.#i.set(t,n),this.#u({id:t,name:e.name,size:e.size,status:`uploading`,progress:0});try{let r=e.type===``?`application/octet-stream`:e.type,{url:i,upload:a}=await this.#e.api.upload.call({name:e.name,mime:r,size:e.size});await this.#e.sender.put(i,e,e=>{this.#d(t,{progress:e})},n.signal),this.#d(t,{status:`importing`,progress:1});let o=await this.#e.api.uploaded.call({upload:a}),s=await this.#e.api.importResource.call({content:o,name:e.name});this.#d(t,{status:`done`,uri:s.uri})}catch(n){this.#d(t,{status:`failed`,problem:X(n,`Couldn't upload ${e.name}.`)})}finally{this.#i.delete(t)}}dismissUpload(e){this.#i.get(e)?.abort(),this.uploads.value=this.uploads.value.filter(t=>t.id!==e)}#u(e){this.uploads.value=[...this.uploads.value,e]}#d(e,t){this.uploads.value=this.uploads.value.map(n=>n.id===e?{...n,...t}:n)}async rename(e,t){let n=await this.acting.run(()=>this.#e.api.rename.call({uri:e,name:t}),`Couldn't rename it.`);return n.ok&&this.list.refresh(),n.ok}async remove(e){let t=await this.acting.run(async()=>{let t=await Promise.all(e.map(e=>this.#e.api.remove.call({uri:e})));return{deleted:t.filter(e=>e.deleted).length,kept:t.filter(e=>!e.deleted).length}},`Couldn't delete that.`);if(t.ok)return this.selected.value=new Set([...this.selected.value].filter(t=>!e.includes(t))),await this.list.load(),t.value}async makeContext(e){let t=await this.acting.run(async()=>(await Promise.all(e.map(e=>this.#e.api.contextFrom.call({uri:e,copy:`live`})))).flatMap(e=>[...e.created,...e.updated]),`Couldn't make context from that.`);return t.ok?t.value:void 0}async downloadUrl(e){let t=await this.acting.run(()=>this.#e.api.download.call({uri:e}),`Couldn't start the download.`);return t.ok?t.value.url:void 0}async make(e,t){let n=await this.acting.run(()=>Promise.all(e.map(e=>this.#e.api.convert.call({uri:e,kind:t}))),`Couldn't make that.`);return n.ok&&this.list.refresh(),n.ok}},Bp=class{#e;#t=new Map;at=L(``);roots=new W;file=new W;constructor(e){this.#e=e}async open(e,t){let n=`${e}/${t}`;(this.at.value!==n||this.roots.value.value===void 0)&&(this.at.value=n,this.#t.clear(),this.file.reset(),await this.roots.load(()=>this.#e.exploreRoots.call({system:e,instance:t}),`Couldn't list ${n}'s folders.`))}folder(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=new f({fetch:(e,t)=>this.#e.exploreList.call({uri:e,...t===void 0?{}:{cursor:t}}),key:e=>e.uri,failure:`Couldn't list this folder.`,limit:200},e);return this.#t.set(e,n),n.load(),n}peek(e){let t=ar.safeParse(e);return t.success?this.#t.get(t.data):void 0}async read(e){e===void 0?this.file.reset():this.file.value.value?.stat.uri!==e&&await this.file.load(()=>this.#e.exploreRead.call({uri:e,want:[`text`]}),`Couldn't read this file.`)}refresh(e){this.#t.get(e)?.load()}},Vp=class{#e;found=new W;constructor(e){this.#e=e}async search(e){let t=e.trim();t===``?this.found.reset():await this.found.load(async()=>(await this.#e.find.call({search:t,limit:8})).items,`Couldn't search resources.`)}},Hp={as:`text`,form:`raw`},Up={as:`url`},$={as:`none`},Wp={svg:{preview:{draws:`svg`,reads:Up},source:`code`},mermaid:{preview:{draws:`diagram`,reads:Hp},source:`code`},markdown:{preview:{draws:`markdown`,reads:Hp},source:`code`},html:{preview:{draws:`html`,reads:Hp},source:`code`},csv:{preview:{draws:`table`,reads:Hp},source:`code`},tsv:{preview:{draws:`table`,reads:Hp},source:`code`},excel:{preview:{draws:`table`,reads:{as:`version`,form:`table`}}},ods:{preview:{draws:`table`,reads:{as:`version`,form:`table`}}},pdf:{preview:{draws:`pdf`,reads:Up}},docx:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},pptx:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},odt:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},rtf:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}}},notebook:{preview:{draws:`markdown`,reads:{as:`text`,form:`markdown`}},source:`code`},json:{preview:{draws:`json`,reads:Hp},source:`code`},jsonl:{preview:{draws:`json`,reads:Hp},source:`code`},text:{source:`text`}},Gp={document:{source:`text`},code:{source:`code`},image:{preview:{draws:`image`,reads:Up}},table:{preview:{draws:`table`,reads:{as:`version`,form:`table`}}},audio:{preview:{draws:`audio`,reads:Up}},video:{preview:{draws:`video`,reads:Up}},web:{preview:{draws:`html`,reads:Hp},source:`code`},data:{source:`code`},archive:{preview:{draws:`folder`,reads:$}},folder:{preview:{draws:`folder`,reads:$}},other:{preview:{draws:`binary`,reads:$}}},Kp=[`markdown`,`table`,`pages`,`code`,`text`,`description`,`ocr`,`transcript`],qp={markdown:{draws:`markdown`,reads:{as:`text`,form:`markdown`}},text:{draws:`text`,reads:{as:`text`,form:`text`}},code:{draws:`code`,reads:{as:`text`,form:`code`}},pages:{draws:`pages`,reads:{as:`version`,form:`pages`}},table:{draws:`table`,reads:{as:`version`,form:`table`}},description:{draws:`markdown`,reads:{as:`text`,form:`description`}},ocr:{draws:`text`,reads:{as:`text`,form:`ocr`}},transcript:{draws:`text`,reads:{as:`text`,form:`transcript`}},thumbnail:{draws:`image`,reads:{as:`url`}}};function Jp(e){return e.as===`text`?e.form===`raw`?void 0:e.form:e.as===`version`?e.form:void 0}function Yp(e,t){let n=t.preview;return e===`thumbnail`||n===void 0?e===`thumbnail`:Jp(n.reads)===e||n.reads.as===`text`&&n.reads.form===`raw`&&qp[e].draws===n.draws}function Xp(e,t,n=[],r=[]){let i=$r(e),a=e.mime?.startsWith(`image/svg`)===!0?Wp.svg:void 0,o=(e.format===void 0?void 0:Wp[e.format])??a??Gp[i],s=ti(e.format)||`text`,c=new Set(t),l=[],u=r.find(e=>e.mode===`replace`);if(u!==void 0)l.push({id:`preview`,label:`Preview`,draws:`system`,reads:$,system:u.system});else if(o.preview!==void 0){let e=Jp(o.preview.reads),t=e===void 0?void 0:n.find(t=>t.kind===e);e===void 0||c.has(e)?l.push({id:`preview`,label:`Preview`,...o.preview,...e===void 0?{}:{form:e}}):l.push(t===void 0?{id:`preview`,label:`Preview`,draws:`binary`,reads:$}:{id:`preview`,label:`Preview`,draws:`offer`,reads:$,form:t.kind,offer:t})}o.source!==void 0&&l.push({id:`source`,label:l.length===0?`Text`:`Source`,draws:o.source,reads:Hp,...o.source===`code`?{language:s}:{}});for(let e of r.filter(e=>e.mode===`tab`))l.push({id:`system:${e.system}`,label:e.label,draws:`system`,reads:$,system:e.system});let d=[...Kp,...t.filter(e=>!Kp.includes(e))];for(let e of d){if(Yp(e,o))continue;if(c.has(e)){l.push({id:e,label:ei[e],...qp[e],form:e,...e===`code`?{language:s}:{}});continue}let t=n.find(t=>t.kind===e);t!==void 0&&l.push({id:e,label:ei[e],draws:`offer`,reads:$,form:e,offer:t})}return l.push({id:`info`,label:`Info`,draws:`info`,reads:$}),{family:i,modes:l,initial:l[0]?.id??`info`}}function Zp(e,t){let n={id:`info`,label:`Info`,draws:`info`,reads:$};return e.modes.find(e=>e.id===t)??e.modes.find(t=>t.id===e.initial)??n}function Qp(e){switch(e.as){case`text`:return`text:${e.form}`;case`url`:return`url`;case`version`:return`version:${e.form}`;case`none`:return`none`}}function $p(e){return e.value}var em=2e5;I(0);var tm=class{#e;uri=L(void 0);section=L(void 0);opened=new W;asked=I(void 0);#t=new Map;#n=I(0);making=new U;contexting=new U;plan;mode;systemViewers;constructor(e){this.#e=e,this.systemViewers=k(()=>{$p(e.systems.version);let t=this.opened.value.value?.stat.format;return t===void 0?[]:e.systems.viewers(t)}),this.plan=k(()=>{let e=this.opened.value.value;if(e===void 0)return;let t=this.systemViewers.value.map(e=>({system:e.system,mode:e.mode,label:e.label}));return Xp(e.stat,e.forms.map(e=>e.kind),e.offers,t)}),this.mode=k(()=>this.plan.value===void 0?void 0:Zp(this.plan.value,this.asked.value))}async open(e,t){let n=this.uri.value===e;n||(this.#t.clear(),this.#n.value++),this.uri.value=e,this.section.value=t,await this.opened.load(()=>this.#r(e),`Couldn't open this resource.`,n&&this.opened.value.value!==void 0)}close(){this.uri.value=void 0,this.opened.reset(),this.#t.clear(),this.#n.value++}async#r(e){try{let t=await this.#e.api.forms.call({uri:e});return{stat:t.record.stat,record:t.record,forms:t.forms,offers:t.offers,links:t.record.links,from:`library`,text:void 0}}catch(t){try{let t=await this.#e.api.systemRead.call({uri:e,want:[`text`,`links`]}),n=t.text!==void 0&&`inline`in t.text?t.text.inline:void 0;return{stat:t.stat,record:void 0,forms:[],offers:[],links:t.links??[],from:`system`,text:n}}catch{throw t}}}load(e){$p(this.#n);let t=this.uri.value,n=this.opened.value.value;if(e.as===`none`||t===void 0||n===void 0)return;let r=Qp(e),i=this.#t.get(r);if(i!==void 0)return i;let a=new W;return this.#t.set(r,a),a.load(()=>this.#i(t,n,e),e.as===`url`?`Couldn't load this file.`:`Couldn't read this.`),a}async#i(e,t,n){switch(n.as){case`text`:if(t.from===`system`){let n=t.text??``;return{as:`text`,result:{uri:e,form:`raw`,text:n,offset:0,total:n.length,truncated:!1,forms:[],offers:[]}}}return{as:`text`,result:await this.#e.api.read.call({uri:e,form:n.form,maxChars:em})};case`url`:if(t.from===`system`)throw Error(`This system resource has no download.`);return{as:`url`,download:await this.#e.api.download.call({uri:e})};case`version`:{let t=await this.#e.api.download.call({uri:e,form:n.form}),r=await this.#e.fetch(t.url);if(!r.ok)throw Error(`The download answered ${r.status}.`);return{as:`version`,version:kn.parse(await r.json())}}}}retry(e){this.#t.delete(Qp(e)),this.#n.value++}text(e){let t=this.load(e)?.value.value;return t?.as===`text`?t.result:void 0}download(e){let t=this.load(e)?.value.value;return t?.as===`url`?t.download:void 0}version(e){let t=this.load(e)?.value.value;return t?.as===`version`?t.version:void 0}async downloadUrl(e){let t=this.uri.value;if(t===void 0)return;let n=await this.making.run(()=>this.#e.api.download.call({uri:t,...e===void 0?{}:{form:e}}),`Couldn't start the download.`);return n.ok?n.value:void 0}async make(e){let t=this.uri.value;if(t===void 0)return!1;let n=await this.making.run(()=>this.#e.api.convert.call({uri:t,kind:e}),`Couldn't make that.`);return n.ok&&await this.open(t,this.section.value),n.ok}async makeContext(){let e=this.uri.value;if(e===void 0)return;let t=await this.contexting.run(()=>this.#e.api.contextFrom.call({uri:e,copy:`live`}),`Couldn't make context from this.`);return t.ok?t.value:void 0}changed(e){e.uri===this.uri.value&&(this.#t.clear(),this.#n.value++,this.open(e.uri,this.section.value))}systemView(e){let t=this.opened.value.value,n=this.uri.value;if(t===void 0||n===void 0)return;let r=this.#e;return{stat:t.stat,...this.section.value===void 0?{}:{section:this.section.value},forms:t.forms.map(e=>e.kind),text:async e=>t.from===`system`?t.text??``:(await r.api.read.call({uri:n,form:e??`raw`,maxChars:em})).text,bytes:async()=>{if(t.from===`system`)return new Uint8Array;let e=await r.api.download.call({uri:n});return new Uint8Array(await(await r.fetch(e.url)).arrayBuffer())},system:r.systems.client(e)}}},nm=class{#e;browser;explorer;constructor(e){this.#e=e,this.browser=new zp({api:e.api,events:e.events,sender:e.sender}),this.explorer=new Bp(e.api)}search(){return new Vp(this.#e.api)}viewer(){let e=new tm({api:this.#e.api,fetch:this.#e.fetch,systems:this.#e.systems}),t=this.#e.events(t=>{e.changed(t)});return this.#e.prepare(),xe()!==void 0&&Oe(t),{store:e,stop:t}}},rm=[`active`,`hidden`,`not_applicable`,`pending_approval`,`pending_removal`],im={active:`ok`,hidden:`neutral`,not_applicable:`neutral`,pending_approval:`warn`,pending_removal:`danger`,pending_plan:`accent`},am={person:`A person`,system:`A system`,research:`Research`};function om(e,t){let n=(e.filters??[]).filter(e=>e.field===t),[r]=n;return n.length===1&&r!==void 0&&r.op===`is`&&typeof r.value==`string`?r.value:void 0}function sm(e,t,n){let r=(e.filters??[]).filter(e=>e.field!==t),i=n===void 0?r:[...r,{field:t,op:`is`,value:n}],{filters:a,...o}=e;return i.length===0?o:{...o,filters:i}}function cm(e){return new Map(e.map(e=>[String(e.value),e.count]))}function lm(e){return e.sort?.[0]?.field===`lastModified`}var um={approve:{label:`Approve`,icon:`check`,from:[`pending_approval`],danger:!1,done:`Approved`},hide:{label:`Hide`,icon:`eye-off`,from:[`active`,`not_applicable`,`pending_approval`,`pending_removal`,`pending_plan`],danger:!1,done:`Hidden`},restore:{label:`Restore`,icon:`undo`,from:[`hidden`,`not_applicable`,`pending_removal`],danger:!1,done:`Restored`},confirm_removal:{label:`Confirm removal`,icon:`trash`,from:[`pending_removal`],danger:!0,done:`Removed`}};function dm(e,t){return e.origin?.type===`memory`&&t.me!==void 0&&e.origin.author===t.me}function fm(e,t){return t.admin||dm(e,t)}function pm(e,t,n){return um[t].from.includes(e.status)?n.admin||dm(e,n)&&(t===`hide`||t===`restore`):!1}function mm(e,t){return Wn.flatMap(n=>{let r=e.filter(e=>pm(e,n,t)).map(e=>e.name),i=um[n];return r.length===0?[]:[{action:n,label:i.label,icon:i.icon,danger:i.danger,names:r}]})}function hm(e,t,n){let r=`${um[e].done} ${t.toLocaleString()}`;return n===0?r:`${r} · ${n.toLocaleString()} left as ${n===1?`it was`:`they were`}`}function gm(e){return e===void 0?``:`${Math.round(Math.min(1,Math.max(0,e))*100)}% alike`}function _m(e){let t=[];if(e.duplicate!==void 0){let n=gm(e.duplicate.similarity);t.push({key:`duplicate`,label:`Possible duplicate`,tone:`warn`,icon:`copy`,title:`May say the same as ${e.duplicate.of}${n===``?``:` (${n})`}: ${e.duplicate.reason}`})}if(e.contradiction!==void 0&&t.push({key:`contradiction`,label:`Contradiction`,tone:`danger`,icon:`warning`,title:`Its answer may disagree with ${e.contradiction.of}: ${e.contradiction.reason}`}),e.metadataStale===!0&&t.push({key:`stale`,label:`Metadata out of date`,tone:`neutral`,icon:`clock`,title:`Its text changed since its question was written; it is filled in again in the background.`}),e.split?.from!==void 0)t.push({key:`split`,label:`Split out`,tone:`accent`,icon:`tree`,title:`Made from ${e.split.from}, which answered several questions.`});else if(e.split?.into!==void 0&&e.split.into.length>0){let n=e.split.into.length;t.push({key:`split`,label:`Split into ${n}`,tone:`accent`,icon:`tree`,title:`It answered several questions, so it was split into ${n} items, one per question.`})}return t}function vm(e){return e.statusReason??ym[e.status]}var ym={active:`In use: searched, suggested and loaded.`,hidden:`Switched off: left out of every selection and search.`,not_applicable:`Ruled out by a plan’s answer; a model sees it only when it has an answer and asks for it.`,pending_approval:`New from a system or a resource; not searched or loaded until an admin approves it.`,pending_removal:`Its source dropped it; it keeps working until an admin confirms the removal.`,pending_plan:`An open question in a plan, with no answer yet.`},bm={duplicate:{label:`Duplicates`,about:`Items that may answer the same question as a newer one. Merge them, keep both, or hide the older.`},contradiction:{label:`Contradictions`,about:`Items whose answers to the same question may disagree. Hide the one that is wrong, or edit it.`},pending_approval:{label:`Waiting for approval`,about:`New context from systems and resources. It is not searched or loaded until it is approved.`},pending_removal:{label:`Waiting for removal`,about:`Items their source dropped. They keep working until the removal is confirmed.`}};function xm(e){let t=new Set;return e.filter(e=>{if(e.kind!==`contradiction`||e.other===void 0)return!0;let n=[e.item.name,e.other.name].sort().join(`|`);return!t.has(n)&&(t.add(n),!0)})}function Sm(e){if(e===void 0)return 0;let{duplicate:t,contradiction:n,pending_approval:r,pending_removal:i}=e.counts;return t+n+r+i-(e.items.length-xm(e.items).length)}var Cm={active:{label:`Active`,about:`New context from systems and resources is in use at once.`},pending_approval:{label:`Pending approval`,about:`An admin approves each new item in Review before it is used.`},hidden:{label:`Hidden`,about:`New items start switched off; an admin restores the ones to use.`}},wm={question:`Question`,when:`When`,askedBy:`Asked by`,validUntil:`Valid until`};function Tm(e,t){return e!==void 0&&e<=t}function Em(e){return new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}function Dm(e){return[...e].sort((e,t)=>t.at-e.at)}function Om(e,t){return e.from===void 0?t[e.status]:`${t[e.from]} → ${t[e.status]}`}var km=class{#e;statusCounts=new W;askerCounts=new W;queue=new W;setting=new W;acting=new U;saving=new U;busyKey=I(``);#t=!1;constructor(e){this.#e=e}async load(e){this.#t=e,await Promise.all([this.loadCounts(!1),...e?[this.loadQueue(!1),this.setting.load(()=>this.#e.newStatus.call({}),`Couldn't load the setting.`)]:[]])}async loadCounts(e=!0){await Promise.all([this.statusCounts.load(async()=>cm(await this.#e.values.call({list:`contexts`,field:`status`,limit:20})),`Couldn't count the statuses.`,e),this.askerCounts.load(async()=>cm(await this.#e.values.call({list:`contexts`,field:`askedBy`,limit:20})),`Couldn't count who asked.`,e)])}async loadQueue(e=!0){await this.queue.load(()=>this.#e.review.call({limit:100}),`Couldn't load Review.`,e)}changed(){this.loadCounts(),this.#t&&this.loadQueue()}async setStatus(e,t=``){return this.#n(t,()=>this.#e.setStatus.call(e),`Couldn't change those items.`)}async merge(e,t=``){return this.#n(t,()=>this.#e.merge.call(e),`Couldn't merge them.`)}async notDuplicate(e,t=``){return this.#n(t,async()=>(await this.#e.notDuplicate.call(e)).ok,`Couldn't clear that flag.`)}async saveSetting(e){let t=await this.saving.run(()=>this.#e.setNewStatus.call({value:e}),`Couldn't change the setting.`);return t.ok&&this.setting.set(t.value),t}async#n(e,t,n){this.busyKey.value=e;let r=await this.acting.run(t,n);return this.busyKey.value=``,r.ok&&await Promise.all([this.loadCounts(),...this.#t?[this.loadQueue()]:[]]),r}},Am=class{#e;list=new W;open=new W;answering=new U;busyQuestion=I(``);deeper=I([]);#t=!1;constructor(e){this.#e=e}async loadList(e=!1){this.#t=!0,await this.list.load(()=>this.#e.plans.call({}),`Couldn't load the plans.`,e)}async show(e){let t=this.open.value.value?.run===e;t||(this.open.reset(),this.deeper.value=[]),await this.open.load(()=>this.#e.plan.call({run:e}),`Couldn't load the plan.`,t)}close(){this.open.reset(),this.deeper.value=[]}async markdown(e){try{return(await this.#e.plan.call({run:e,format:`markdown`})).markdown}catch{return}}async answer(e,t){let n={run:e,...t.answer===void 0?{}:{answers:[t.answer]},...t.reason===void 0?{}:{reasons:[t.reason]}};this.busyQuestion.value=t.answer?.question??t.reason?.question??``;let r=await this.answering.run(()=>this.#e.answerPlan.call(n),`Couldn't save that answer.`);return this.busyQuestion.value=``,r.ok&&(this.open.value.value?.run===e&&this.open.set({run:e,plan:r.value.plan}),this.deeper.value=r.value.deeper,this.#t&&this.loadList(!0)),r}changed(){this.#t&&this.loadList(!0);let e=this.open.value.value?.run;e!==void 0&&!this.answering.busy.value&&this.show(e)}},jm=class{#e;name=I(void 0);view=new W;metadata=new W;reextracting=new U;choiceTargets=I(new Map);linking=new U;unlinking=new U;forgetting=new U;saving=new U;constructor(e){this.#e=e}async open(e){let t=this.name.value===e&&this.view.value.value!==void 0;t||(this.view.reset(),this.metadata.reset(),this.choiceTargets.value=new Map),this.name.value=e,await Promise.all([this.view.load(()=>this.#e.item.call({name:e}),`Couldn't load this context item.`,t),this.metadata.load(()=>this.#e.metadata.call({name:e}),`Couldn't load its metadata.`,t)]),await this.#t(e)}async#t(e){let t=[...new Set(this.view.value.value?.record.decl.choices?.map(e=>e.to)??[])];if(t.length===0)this.choiceTargets.value=new Map;else try{let n=await this.#e.list.call({query:{filters:[{field:`name`,op:`in`,values:t}]},limit:Math.min(t.length,200)});this.name.value===e&&(this.choiceTargets.value=new Map(n.items.map(e=>[e.name,e])))}catch{}}close(){this.name.value=void 0,this.view.reset(),this.metadata.reset(),this.choiceTargets.value=new Map}touches(e){let t=this.view.value.value;return this.name.value===void 0||t===void 0?!1:this.name.value===e||t.backlinks.some(t=>t.from===e)||t.links.some(t=>t.to.kind===`context`&&t.to.name===e)}async reload(){let e=this.name.value;e!==void 0&&await this.open(e)}async addLink(e){let t=this.name.value;if(t===void 0)return{ok:!1,problem:`No context item is open.`};let n=ue(e,t);if(!n.ok)return this.linking.problem.value=n.problem,n;let r=await this.linking.run(()=>this.#e.link.call({from:t,to:n.value.to,relation:n.value.relation,weight:n.value.weight}),`Couldn't add that link.`);return r.ok&&await this.reload(),r}async removeLink(e){let t=await this.unlinking.run(async()=>(await this.#e.unlink.call({from:e.from,toKey:e.toKey,relation:e.relation})).ok,`Couldn't remove that link.`);return t.ok&&await this.reload(),t}async forget(){let e=this.name.value;if(e===void 0)return{ok:!1,problem:`No context item is open.`};let t=await this.forgetting.run(async()=>(await this.#e.forget.call({name:e})).ok,`Couldn't forget this memory.`);return t.ok&&await this.reload(),t}async reextract(){let e=this.name.value;if(e===void 0)return{ok:!1,problem:`No context item is open.`};let t=await this.reextracting.run(()=>this.#e.reextract.call({names:[e]}),`Couldn't fill its metadata again.`);return t.ok&&await this.reload(),t}async edit(e){let t=this.view.value.value;if(t?.record.origin?.type!==`memory`)return{ok:!1,problem:`Only a memory can be edited.`};let n=ce(t.record.name,e);if(!n.ok)return this.saving.problem.value=n.problem,n;let r=await this.saving.run(async()=>(await this.#e.updateMemory.call(n.value)).name,`Couldn't save this memory.`);return r.ok&&await this.open(r.value),r}},Mm=class{#e;list;item;review;plans;remembering=new U;making=new U;#t=0;#n;constructor(e){this.#e=e,this.list=new f({fetch:(t,n,r)=>e.api.list.call({...t,limit:r,...n===void 0?{}:{cursor:n}}),key:e=>e.name,failure:`Couldn't load the context.`,limit:50},{}),this.item=new jm(e.api),this.review=new km(e.api),this.plans=new Am(e.api)}async show(e){this.list.loaded.value&&JSON.stringify(e)===JSON.stringify(this.list.filter.value)?await this.list.refresh():await this.list.load(e)}follow(){this.#t++,this.#n??=this.#e.events(e=>{this.changed(e)});let e=!1,t=()=>{e||(e=!0,this.#t--,this.#t===0&&(this.#n?.(),this.#n=void 0))};return xe()!==void 0&&Oe(t),t}changed(e){this.list.refresh(),this.review.changed(),this.plans.changed(),this.item.touches(e)&&this.item.reload()}async remember(e){let t=ne(e);if(!t.ok)return this.remembering.problem.value=t.problem,t;let n=await this.remembering.run(async()=>(await this.#e.api.remember.call(t.value)).name,`Couldn't remember that.`);return n.ok&&this.list.refresh(),n}async fromResource(e){let t=await this.making.run(()=>this.#e.api.fromResource.call(e),`Couldn't make context from that resource.`);return t.ok&&this.list.refresh(),t}},Nm=class{#e;#t;#n;name=I(void 0);about=new W;facts=new W;examples=L([]);examplesTotal=I(0);examplesNext=I(void 0);examplesLoading=I(!1);examplesProblem=I(``);#r=0;constructor(e,t){this.#e=e,this.#t=t}async open(e){let t=this.name.value===e;t||this.close(),this.name.value=e,this.#n??=this.#t(e=>{this.#o(e)}),await Promise.all([this.#i(e,t),this.#a(e,t),t?Promise.resolve():this.moreExamples()])}close(){this.#n?.(),this.#n=void 0,this.name.value=void 0,this.about.reset(),this.facts.reset(),this.#r++,this.examples.value=[],this.examplesTotal.value=0,this.examplesNext.value=void 0,this.examplesLoading.value=!1,this.examplesProblem.value=``}async moreExamples(){let e=this.name.value,t=this.examples.value.length===0?0:this.examplesNext.value;if(e===void 0||t===void 0||this.examplesLoading.value)return;let n=++this.#r;this.examplesLoading.value=!0,this.examplesProblem.value=``;try{let r=await this.#e.fnExamples.call({fn:e,offset:t,limit:5});if(n!==this.#r)return;this.examples.value=[...this.examples.value,...r.items],this.examplesTotal.value=r.total,this.examplesNext.value=r.next}catch(e){n===this.#r&&(this.examplesProblem.value=X(e,`Couldn't load its examples.`))}finally{n===this.#r&&(this.examplesLoading.value=!1)}}async#i(e,t){await this.about.load(async()=>(await this.#e.searchFns.call({names:[e],items:[`fn`],available:!1,limit:1})).items.find(t=>t.name===e),`Couldn't load this fn.`,t)}async#a(e,t){await this.facts.load(()=>this.#e.fnFacts.call({fn:e}),`Couldn't load this fn's facts.`,t)}#o(e){let t=this.name.value;e.type===`fn`&&t!==void 0&&e.fn===t&&this.#a(t,!0)}},Pm=class{#e;known=L(new Map);#t=new Set;constructor(e){this.#e=e}fnOf(e){return fn(e,e=>this.known.value.get(e))}async resolve(e){let t=[...new Set(e)].filter(e=>un(e)&&!this.#t.has(e));if(t.length!==0){for(let e of t)this.#t.add(e);try{let e=await this.#e.fnsOfModelNames.call({names:t});this.known.value=new Map([...this.known.value,...Object.entries(e)])}catch{for(let e of t)this.#t.delete(e)}}}},Fm=`harness.hubName`,Im=class{#e;#t;#n;#r;#i;identity=L(void 0);name=k(()=>this.identity.value?.name??this.#r??`fnloom`);source=k(()=>this.identity.value?.source);version=k(()=>this.identity.value?.version??``);saving=new U;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n,this.#r=n===void 0?void 0:Br(n,Fm,dn)}async load(){try{this.#o(await this.#e.identity.call(Al))}catch{}}start(){this.#i??=this.#t(e=>{this.#a(e)})}stop(){this.#i?.(),this.#i=void 0}async rename(e){let t=await this.saving.run(()=>this.#e.setHubName.call({name:e}),`Couldn't save the name.`);return t.ok&&this.#o(t.value),t}#a(e){e.type===`identity`&&this.#o(e.identity)}#o(e){this.identity.value=e;try{this.#n?.setItem(Fm,JSON.stringify(e.name))}catch{}}},Lm={setting:`Set here.`,env:`From the hub’s FNLOOM_NAME setting.`,default:`The default name.`};function Rm(e){let t=dn.safeParse(e);return t.success?{ok:!0,name:t.data}:{ok:!1,problem:e.trim()===``?`Give the hub a name.`:`Keep it to one line of at most 40 characters.`}}var zm=class{#e;view=L(void 0);value=k(()=>this.view.value?.value??`ask`);saving=new U;constructor(e){this.#e=e}async load(){try{this.view.value=await this.#e.outsideImages.call({})}catch{}}async set(e){let t=await this.saving.run(()=>this.#e.setOutsideImages.call({value:e}),`Couldn't save the setting.`);return t.ok&&(this.view.value=t.value),t}clear(){this.view.value=void 0}},Bm=class{#e;page=new W;#t;constructor(e){this.#e=e}async show(e){let t=this.#t!==void 0&&JSON.stringify(e)===JSON.stringify(this.#t)&&this.page.value.value!==void 0;this.#t=e,await this.page.load(()=>this.#e.graph.call(e),`Couldn't load the graph.`,t)}async refresh(){this.#t!==void 0&&await this.show(this.#t)}},Vm=class{#e;run=new W;tree=new W;approval=L(void 0);acting=new U;id=L(void 0);branch=k(()=>this.id.value===void 0?void 0:re(this.tree.value.value,this.id.value));constructor(e){this.#e=e}async open(e){this.id.value!==e&&(this.id.value=e,this.run.reset(),this.tree.reset(),this.approval.value=void 0),await this.#t(e,!1)}async refresh(){let e=this.id.value;e!==void 0&&await this.#t(e,!0)}async decide(e,t,n){let r=this.approval.value;if(r===void 0)return!1;let i=await this.acting.run(()=>this.#e.approve.call({approval:r.id,approve:e,remember:`once`,...t===``?{}:{reason:t},...n===void 0?{}:{answer:n}}),`Couldn't send your answer.`);return i.ok&&(this.approval.value=void 0,this.refresh()),i.ok}async undo(){let e=this.run.value.value;if(e===void 0)return{ok:!1,problem:`The run has not loaded yet.`};let t=await this.acting.run(()=>this.#e.undoTurn.call({turn:e.turn}),`Couldn't undo it.`);return t.ok&&await this.refresh(),t}async background(){let e=this.run.value.value;if(e===void 0)return{ok:!1,problem:`The run has not loaded yet.`};let t=await this.acting.run(async()=>(await this.#e.background.call({run:e.id})).accepted,`Couldn't move it to the background.`);return t.ok&&this.refresh(),t}async#t(e,t){await this.run.load(()=>this.#e.run.call({run:e}),`Couldn't load this run.`,t);let n=this.run.value.value;n!==void 0&&n.id===e&&this.id.value===e&&await Promise.all([this.tree.load(()=>this.#e.tree.call({turn:n.turn}),`Couldn't load what it called.`,t||this.tree.value.value!==void 0),this.#n(n)])}async#n(e){if(e.status!==`awaiting-approval`)this.approval.value=void 0;else try{let t=await this.#e.approvals.call({runs:[e.id]});this.id.value===e.id&&(this.approval.value=t.find(t=>t.run===e.id&&t.status===`pending`))}catch{this.id.value===e.id&&(this.approval.value=void 0)}}},Hm=class{#e;sets;constructor(e){this.#e=e,this.sets=new f({fetch:async(e,t,n)=>this.#e.dataSets.call({limit:n,...t===void 0?{}:{cursor:t},...e.text===``?{}:{text:e.text},...e.system===void 0?{}:{system:e.system}}),key:e=>e.type,failure:`Couldn't load the stored data.`,limit:50},{text:``,system:void 0})}async rowActions(e){return this.#e.rowActions.call(e)}async findRecords(e){return this.#e.records.call(e)}async readFn(e,t){return this.#e.readFn.call({fn:e,args:{...t}})}async exportCsv(e){let t=await this.#e.exportCsv.call(e);return new Response(t).blob()}records(){return new Um(this.#e)}},Um=class{#e;table=new W;shown=L(void 0);#t;record=new W;versions=L([]);versionsNext=I(void 0);versionsLoading=I(!1);versionsProblem=I(``);saving=new U;constructor(e){this.#e=e}async show(e){let t=this.#t!==void 0&&JSON.stringify(this.#t)===JSON.stringify(e)&&this.table.value.value!==void 0;this.#t!==void 0&&this.#t.type!==e.type&&(this.table.reset(),this.shown.value=void 0),this.#t=e,await this.table.load(()=>this.#e.recordTable.call(e),`Couldn't load these records.`,t),this.#t===e&&this.table.problem.value===``&&(this.shown.value=e)}async open(e,t){let n=this.record.value.value?.id===t;await Promise.all([this.record.load(async()=>(await this.#e.record.call({type:e,id:t})).record,`Couldn't load this record.`,n),this.#r(e,t,!0)])}close(){this.record.reset(),this.versions.value=[],this.versionsNext.value=void 0,this.versionsProblem.value=``}async moreVersions(){let e=this.record.value.value;e!==void 0&&this.versionsNext.value!==void 0&&await this.#r(e.type,e.id,!1)}async save(e,t,n,r){let i=await this.saving.run(()=>this.#e.saveRecord.call({type:e,value:t,...n===void 0?{}:{id:n},...r===void 0?{}:{expect:r}}),`Couldn't save this record.`);if(i.ok)return this.record.value.value?.id===i.value.id&&(this.record.set(i.value),this.#r(e,i.value.id,!0)),await this.#n(),i.value}async window(e){return this.#e.recordTable.call(e)}follow(e){this.record.value.value?.id===e.id&&(this.record.set(e),this.#r(e.type,e.id,!0))}async remove(e,t){let n=await this.saving.run(()=>this.#e.removeRecord.call({type:e,id:t}),`Couldn't remove this record.`);return!n.ok||!n.value.removed?!1:(this.close(),await this.#n(),!0)}async#n(){let e=this.#t;e!==void 0&&await this.table.load(()=>this.#e.recordTable.call(e),`Couldn't load these records.`,!0)}async#r(e,t,n){this.versionsLoading.value=!0,this.versionsProblem.value=``;try{let r=n?void 0:this.versionsNext.value,i=await this.#e.recordVersions.call({type:e,id:t,limit:20,...r===void 0?{}:{cursor:r}});this.versions.value=n?i.items:[...this.versions.value,...i.items],this.versionsNext.value=i.cursor}catch{this.versionsProblem.value=`Couldn't load this record's history.`}finally{this.versionsLoading.value=!1}}},Wm=class{#e;#t;list=new W;nav=k(()=>ki(this.list.value.value??[]));constructor(e){this.#e=e}get hub(){return this.#e.hub}async load(e=!1){await this.list.load(()=>this.#e.api.systemPages.call({}),`Couldn’t load the systems’ pages.`,e)}async refresh(){this.#e.api.systemPages.invalidate(),await this.load(!0)}start(){this.#t===void 0&&(this.#t=this.#e.events(e=>{this.#n(e)}))}stop(){this.#t?.(),this.#t=void 0}clear(){this.stop(),this.list.reset()}page(e,t){return this.list.value.value?.find(n=>n.system===e&&n.segment===t)}#n(e){e.type===`capabilities`&&this.refresh()}},Gm=`harness.theme`,Km=Xn([`system`,`light`,`dark`]),qm=`(prefers-color-scheme: dark)`,Jm=class{choice;#e=I(!1);#t;constructor(e){this.choice=Ur(e.store,Gm,Km,`system`);let t=e.media(qm);this.#e.value=t.matches;let n=e=>{this.#e.value=e.matches};t.addEventListener(`change`,n);let r=S(this.theme,t=>{e.root.dataset.theme=t},{immediate:!0,flush:`sync`});this.#t=()=>{t.removeEventListener(`change`,n),r()}}theme=k(()=>this.choice.value===`system`?this.#e.value?`dark`:`light`:this.choice.value);dispose(){this.#t()}},Ym={duration:5e3,max:4},Xm=class{#e;#t=new Map;#n=L([]);#r=1;constructor(e=Ym){this.#e=e}get items(){return this.#n.value}push(e){let t=this.#r++,n={view:{id:t,tone:e.tone??`neutral`,title:e.title,...e.body===void 0?{}:{body:e.body},...e.action===void 0?{}:{action:e.action.label}},run:e.action?.run,duration:e.duration??this.#e.duration,timer:void 0};for(this.#t.set(t,n),this.#i(n);this.#t.size>this.#e.max;){let e=this.#t.keys().next();if(e.done===!0)break;this.dismiss(e.value)}return this.#a(),t}ok(e,t){return this.push({tone:`ok`,title:e,...t===void 0?{}:{body:t}})}error(e,t){return this.push({tone:`danger`,title:e,...t===void 0?{}:{body:t}})}dismiss(e){let t=this.#t.get(e);t!==void 0&&(clearTimeout(t.timer),this.#t.delete(e),this.#a())}act(e){let t=this.#t.get(e);this.dismiss(e),t?.run?.()}hold(e){let t=this.#t.get(e);t!==void 0&&(clearTimeout(t.timer),t.timer=void 0)}release(e){let t=this.#t.get(e);t!==void 0&&t.timer===void 0&&this.#i(t)}#i(e){e.duration>0&&(e.timer=setTimeout(()=>{this.dismiss(e.view.id)},e.duration))}#a(){this.#n.value=Array.from(this.#t.values(),e=>e.view)}};function Zm(e){return e.connection.onReconnect(()=>{e.session.signedIn.value&&(e.inbox.refresh(),e.chat.refresh(),e.pages.refresh(),e.admin.systems.list.value.value!==void 0&&e.admin.systems.load(!0))})}function Qm(e){let t=new Rp(e.localStorage,Date.now,Vr(e),Lp(e.document)),{hub:n}=Wf({origin:e.location.origin,token:()=>t.accessToken.value,unauthorized:()=>o.recover()}),r=new sp({send:ap(n),signedIn:()=>t.signedIn.value,page:()=>e.location.pathname});r.watch(e);let i=qf(n,e=>{r.traffic(e)}),a=Kl(i,()=>t.user.value?.id),o=new _p(a.auth,t,Date.now,new gp(e.navigator)),s=new xp(a.connection),c=new he(a.notifications,a.userEvents),l=new Bf({api:a.chat,userEvents:a.userEvents,sessionEvents:a.sessionEvents,store:e.localStorage,sender:new Ol,clock:Date.now,client:()=>zf(),me:()=>t.user.value?.id,recorder:()=>Mf.available()?new Mf:void 0,speech:()=>Pf(e),renderers:{share:async()=>{(await ni(async()=>{let{shareChatModules:e}=await import(`./shared-Bc4GJbiE.js`);return{shareChatModules:e}},__vite__mapDeps([0,1,2,3,4]))).shareChatModules()}}}),u=new _l({api:a.admin,chat:a.chat,userEvents:a.userEvents,systemLogs:a.systemLogs,sender:new Ol,probe:new Ss((t,n)=>e.fetch(t,n))}),d=l.renderers.runtime;d.register(yd);let f=new nm({api:a.resources,events:a.resourceEvents,sender:new Ol,fetch:(t,n)=>e.fetch(t,n),systems:{viewers:e=>d.resourceViewers(e),client:e=>d.systemClient(e),version:l.renderers.version},prepare:()=>l.prepareRenderers()}),p=new Wm({api:a.pages,events:a.userEvents,hub:i});return Zm({session:t,connection:s,inbox:c,chat:l,admin:u,pages:p}),{session:t,identity:new Im(a.identity,a.userEvents,e.localStorage),outsideImages:new zm(a.outsideImages),keeper:o,theme:new Jm({store:e.localStorage,media:t=>e.matchMedia(t),root:e.document.documentElement}),layout:new Hr(e.localStorage),toasts:new Xm,inbox:c,connection:s,chat:l,admin:u,signInForm:()=>new fp(a.auth,t,e.localStorage),account:new vp(a.auth),resources:f,context:new Mm({api:a.context,events:a.contextEvents}),fns:new Nm(a.fns,a.userEvents),fnNotices:new Zt(a.fns),modelNames:new Pm(a.fns),graph:()=>new Bm(a.graph),runPage:()=>new Vm(a.chat),data:new Hm(a.data),pages:p,itemVersions:e=>a.data.itemVersions.call(e),logs:r,push:new Sp(a.notifications,new Ep(e,Cp.built),()=>e.navigator.userAgent),install:new kp(new jp(e)),https:new Dp(a.https)}}var $m={name:`harness-scopes`,type:`light`,fg:`#000000`,bg:`#ffffff`,settings:[]},eh=[[`comment`,`comment`],[`punctuation.definition.comment`,`comment`],[`string`,`string`],[`punctuation.definition.string`,`string`],[`constant.numeric`,`number`],[`constant.language`,`literal`],[`support.constant`,`literal`],[`constant.character`,`literal`],[`keyword.operator`,`plain`],[`keyword`,`keyword`],[`storage`,`keyword`]];function th(e){for(let t of[...e].reverse()){let e=eh.find(([e])=>t===e||t.startsWith(`${e}.`));if(e!==void 0)return e[1]}return`plain`}function nh(e){let t=[],n=(e,n)=>{let r=t.at(-1);r?.kind===e?t[t.length-1]={kind:e,text:r.text+n}:n!==``&&t.push({kind:e,text:n})};return e.forEach((e,t)=>{t>0&&n(`plain`,`
3
3
  `);for(let t of e)if(t.explanation===void 0)n(`plain`,t.content);else for(let e of t.explanation)n(th(e.scopes.map(e=>e.scopeName)),e.content)}),t}var rh={async core(){let[{createHighlighterCore:e},{createJavaScriptRegexEngine:t}]=await Promise.all([ni(()=>import(`./core-DdF778CY.js`),__vite__mapDeps([5,1])),ni(()=>import(`./engine-javascript-C30F4iNc.js`),[])]);return e({themes:[$m],langs:[],engine:t({forgiving:!0})})},async languages(){let{bundledLanguages:e,bundledLanguagesAlias:t}=await ni(async()=>{let{bundledLanguages:e,bundledLanguagesAlias:t}=await import(`./langs-CVIiVMBh.js`);return{bundledLanguages:e,bundledLanguagesAlias:t}},__vite__mapDeps([6,7]));return new Map([...Object.entries(t),...Object.entries(e)])}},ih=class{#e;#t;#n;#r;#i=new Map;#a=new Set;constructor(e=rh,t=Et){this.#e=e,this.#t=t}tokens(e,t){let n=this.#r;if(n===void 0||!this.#a.has(t))return this.#t.tokens(e,t);try{return nh(n.codeToTokensBase(e,{lang:t,theme:$m.name??``,includeExplanation:`scopeName`}))}catch{return this.#t.tokens(e,t)}}prepare(e){if(this.#a.has(e))return Promise.resolve(!1);let t=this.#i.get(e);if(t!==void 0)return t;let n=this.#o(e).catch(()=>!1);return this.#i.set(e,n),n}knows(e){return this.#a.has(e)||this.#t.knows(e)}async#o(e){let t=(await this.#e.languages()).get(e);if(t===void 0)return!1;this.#n??=this.#e.core();let n=await this.#n;return await n.loadLanguage(t),this.#r=n,this.#a.add(e),!0}},ah=/<svg\b[^>]*>/,oh=/viewBox="\s*[-\d.]+[\s,]+[-\d.]+[\s,]+([\d.]+)[\s,]+([\d.]+)\s*"/,sh=/\s(?:width|height)="[^"]*"/g;function ch(e){let t=ah.exec(e)?.[0],n=t===void 0?void 0:oh.exec(t);if(t===void 0||n==null)return e;let[,r=`0`,i=`0`]=n,a=t.replace(sh,``).replace(/^<svg/,`<svg width="${r}" height="${i}"`);return e.replace(t,a)}function lh(e,t,n){t.style.color=`var(${n})`,e.clearRect(0,0,1,1),e.fillStyle=getComputedStyle(t).color,e.fillRect(0,0,1,1);let[r=0,i=0,a=0,o=0]=e.getImageData(0,0,1,1).data;return o===0?void 0:`#${[r,i,a].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}var uh=[`--bg`,`--surface-2`,`--border-strong`,`--text`,`--text-dim`,`--accent`],dh=()=>{if(typeof document>`u`)return;let e=document.createElement(`canvas`).getContext(`2d`,{willReadFrequently:!0});if(e===null)return;let t=document.createElement(`span`);document.body.append(t);try{let[n,r,i,a,o,s]=uh.map(n=>lh(e,t,n)),c=getComputedStyle(document.documentElement).getPropertyValue(`--font`).trim();return n===void 0||r===void 0||i===void 0||a===void 0||o===void 0||s===void 0||c===``?void 0:{font:c,background:n,surface:r,border:i,text:a,muted:o,accent:s}}finally{t.remove()}};function fh(e,t){return{theme:`base`,fontFamily:e.font,themeVariables:{darkMode:t,fontFamily:e.font,fontSize:`14px`,background:e.background,primaryColor:e.surface,primaryBorderColor:e.border,primaryTextColor:e.text,secondaryColor:e.surface,secondaryBorderColor:e.border,secondaryTextColor:e.text,tertiaryColor:e.background,tertiaryBorderColor:e.border,tertiaryTextColor:e.text,mainBkg:e.surface,nodeBorder:e.border,nodeTextColor:e.text,lineColor:e.muted,textColor:e.text,clusterBkg:e.background,clusterBorder:e.border,edgeLabelBackground:e.background,titleColor:e.text,noteBkgColor:e.surface,noteBorderColor:e.accent,noteTextColor:e.text,actorBorder:e.border,actorBkg:e.surface}}}var ph=async()=>(await ni(async()=>{let{default:e}=await import(`./mermaid.core-BNF3dRf5.js`);return{default:e}},__vite__mapDeps([8,9,10,11,12,13,14,15,16,1,7,17,18,19,20,21,22,23]))).default,mh=class{languages=[`mermaid`];#e;#t;#n;#r=Promise.resolve();#i=0;constructor(e=ph,t=dh){this.#e=e,this.#t=t}render(e,t,n){let r=this.#r.then(()=>this.#a(e,n));return this.#r=r.catch(()=>void 0),r}async#a(e,t){this.#n??=this.#e();let n=await this.#n,r=this.#t();n.initialize({startOnLoad:!1,securityLevel:`strict`,...r===void 0?{theme:t?`dark`:`default`}:fh(r,t)}),this.#i+=1;try{let{svg:t}=await n.render(`harness-diagram-${this.#i}`,e);return{ok:!0,value:ch(t)}}catch(e){return{ok:!1,problem:e instanceof Error?e.message:String(e)}}}},hh={light:`#f9fafb`,dark:`#0c0d10`};function gh(e,t){let n=e instanceof Element?e.closest(`a[href]`):null;if(!(n instanceof HTMLAnchorElement)||n.target!==``||n.hasAttribute(`download`))return;let r=new URL(n.href,t);return(r.protocol===`http:`||r.protocol===`https:`)&&r.origin!==t?r.toString():void 0}function _h(e,t){let n=n=>{if(n.defaultPrevented||n.button!==0||!t())return;let r=gh(n.target,e.location.origin);r!==void 0&&(n.preventDefault(),e.open(r,`_blank`,`noopener,noreferrer`))};return e.document.addEventListener(`click`,n),()=>{e.document.removeEventListener(`click`,n)}}function vh(e,t){return S(t,t=>{for(let t of e.querySelectorAll(`meta[name="theme-color"]`))t.remove();let n=e.createElement(`meta`);n.name=`theme-color`,n.content=hh[t],e.head.append(n)},{immediate:!0})}var yh=Qm(window),bh=n(ms);bh.config.errorHandler=e=>{yh.logs.error(e,`vue`),console.error(e)},bh.provide(an,yh).provide(Ot,new ih).provide(bt,new mh).provide(ht,new gt).use(hs(yh.session,ae())).mount(`#app`),Np(window,Cp.built),_h(window,()=>yh.install.state.value===`installed`),vh(document,yh.theme.theme);export{Oc as $,Sd as A,ga as At,Zl as B,Ri as Bt,xm as C,Gs as Ct,of as D,Do as Dt,Of as E,Lo as Et,jd as F,pa as Ft,vc as G,Ai as Gt,il as H,Fi as Ht,Pd as I,fa as It,Vc as J,ji as Jt,Jc as K,Pi as Kt,Ad as L,Hi as Lt,xd as M,Sa as Mt,Ed as N,va as Nt,af as O,co as Ot,Md as P,xa as Pt,xc as Q,Cd as R,zi as Rt,vm as S,Qs as St,Op as T,rs as Tt,tl as U,Mi as Ut,el as V,Vi as Vt,nl as W,Ii as Wt,qc as X,jc as Y,Ti as Yt,Sc as Z,Tm as _,fc as _t,rm as a,Tc as at,gm as b,sc as bt,ym as c,Rc as ct,mm as d,ic as dt,Dc as et,Om as f,Q as ft,_m as g,cc as gt,Dm as h,oc as ht,wm as i,Ec as it,Fd as j,ha as jt,wd as k,no as kt,im as l,Lc as lt,om as m,ac as mt,Rm as n,Kc as nt,Cm as o,wc as ot,Em as p,uc as pt,kc as q,Oi as qt,am as r,Mc as rt,bm as s,Cc as st,Lm as t,Uc as tt,hm as u,Xc as ut,Sm as v,dc as vt,sm as w,Us as wt,lm as x,tc as xt,fm as y,pc as yt,ld as z,Bi as zt};
4
- //# sourceMappingURL=index-OZS2EluT.js.map
4
+ //# sourceMappingURL=index-Uz-h2M5K.js.map