@lunora/studio 1.0.0-alpha.381 → 1.0.0-alpha.382

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/mount.mjs +1 -1
  3. package/dist/packem_chunks/AdvisorHealthPanel.mjs +1 -1
  4. package/dist/packem_chunks/ApiTab.mjs +1 -1
  5. package/dist/packem_chunks/AuditPanel.mjs +1 -1
  6. package/dist/packem_chunks/DeploymentHealthPanel.mjs +1 -1
  7. package/dist/packem_chunks/ExportImportPanel.mjs +1 -1
  8. package/dist/packem_chunks/FileBrowser.mjs +1 -1
  9. package/dist/packem_chunks/FunctionRunner.mjs +1 -1
  10. package/dist/packem_chunks/FunctionStatsPanel.mjs +1 -1
  11. package/dist/packem_chunks/HealthPanel.mjs +1 -1
  12. package/dist/packem_chunks/InsightsPanel.mjs +1 -1
  13. package/dist/packem_chunks/LogsPanel.mjs +1 -1
  14. package/dist/packem_chunks/MailPanel.mjs +1 -1
  15. package/dist/packem_chunks/MetricsPanel.mjs +1 -1
  16. package/dist/packem_chunks/NotificationsPanel.mjs +1 -1
  17. package/dist/packem_chunks/PitrPanel.mjs +1 -1
  18. package/dist/packem_chunks/SchemaViewer.mjs +1 -1
  19. package/dist/packem_chunks/SecurityAdvisorPanel.mjs +1 -1
  20. package/dist/packem_chunks/SettingsPanel.mjs +1 -1
  21. package/dist/packem_chunks/SqlEditorPanel.mjs +1 -1
  22. package/dist/packem_chunks/TableEditor.mjs +1 -1
  23. package/dist/packem_chunks/agents-panel.mjs +1 -1
  24. package/dist/packem_chunks/ai-usage-panel.mjs +1 -1
  25. package/dist/packem_chunks/analytics-panel.mjs +1 -1
  26. package/dist/packem_chunks/architecture-panel.mjs +1 -1
  27. package/dist/packem_chunks/assistant-panel.mjs +2 -2
  28. package/dist/packem_chunks/auth-audit-panel.mjs +1 -1
  29. package/dist/packem_chunks/auth-config-panel.mjs +1 -1
  30. package/dist/packem_chunks/auth-sessions-panel.mjs +1 -1
  31. package/dist/packem_chunks/containers-panel.mjs +1 -1
  32. package/dist/packem_chunks/dashboards-panel.mjs +1 -1
  33. package/dist/packem_chunks/evals-panel.mjs +1 -1
  34. package/dist/packem_chunks/fanout-panel.mjs +1 -1
  35. package/dist/packem_chunks/flags-panel.mjs +1 -1
  36. package/dist/packem_chunks/issues-panel.mjs +1 -1
  37. package/dist/packem_chunks/kv-browser.mjs +1 -1
  38. package/dist/packem_chunks/log-drains-panel.mjs +1 -1
  39. package/dist/packem_chunks/migrations-route.mjs +1 -1
  40. package/dist/packem_chunks/organizations-panel.mjs +1 -1
  41. package/dist/packem_chunks/payments-panel.mjs +1 -1
  42. package/dist/packem_chunks/permissions-panel.mjs +1 -1
  43. package/dist/packem_chunks/privacy-requests-panel.mjs +1 -1
  44. package/dist/packem_chunks/queues-panel.mjs +1 -1
  45. package/dist/packem_chunks/reactors-panel.mjs +1 -1
  46. package/dist/packem_chunks/rls-panel.mjs +1 -1
  47. package/dist/packem_chunks/schedule-panel.mjs +1 -1
  48. package/dist/packem_chunks/storage-rules-panel.mjs +1 -1
  49. package/dist/packem_chunks/subscriptions-panel.mjs +1 -1
  50. package/dist/packem_chunks/sync-client-panel.mjs +1 -1
  51. package/dist/packem_chunks/traces-panel.mjs +1 -1
  52. package/dist/packem_chunks/users-panel.mjs +1 -1
  53. package/dist/packem_chunks/vector-browser.mjs +1 -1
  54. package/dist/packem_chunks/workflows-panel.mjs +1 -1
  55. package/dist/packem_shared/ApiDocsPanel-BZNuHTR8.mjs +2 -0
  56. package/dist/packem_shared/{ApiReferencePanel-CQxU1Ocx.mjs → ApiReferencePanel-DDvLw7c1.mjs} +1 -1
  57. package/dist/packem_shared/{CommandPalette-BZCHLpst.mjs → CommandPalette-BjHFgNA6.mjs} +1 -1
  58. package/dist/packem_shared/{DEFAULT_AUTO_REFRESH_MS-B9kGlqXE.mjs → DEFAULT_AUTO_REFRESH_MS-jK7srdI4.mjs} +1 -1
  59. package/dist/packem_shared/{DataBrowser-CkVOu6py.mjs → DataBrowser-Dp8ayK1S.mjs} +1 -1
  60. package/dist/packem_shared/{GlobalDataBrowser-l2ECwXCm.mjs → GlobalDataBrowser-VehUMwUK.mjs} +1 -1
  61. package/dist/packem_shared/{HomePanel-c7as4tvl.mjs → HomePanel-D5-wWLAj.mjs} +1 -1
  62. package/dist/packem_shared/{MigrationsPanel-BQol4Un1.mjs → MigrationsPanel-CTd2YSSk.mjs} +1 -1
  63. package/dist/packem_shared/{OpenRpcReferencePanel-BFDG91tn.mjs → OpenRpcReferencePanel-dXFl95w8.mjs} +1 -1
  64. package/dist/packem_shared/{ScheduledJobs-Du8ZGL7v.mjs → ScheduledJobs-DPQHuiy6.mjs} +1 -1
  65. package/dist/packem_shared/Studio-CrfDOmdv.mjs +1 -0
  66. package/dist/packem_shared/{StudioApp-CsyDnrg2.mjs → StudioApp-DKBDIF7N.mjs} +1 -1
  67. package/dist/packem_shared/{advisor-view-gtf_DhUU.mjs → advisor-view-y9c2z5w1.mjs} +1 -1
  68. package/dist/packem_shared/{assistant-provider-Dw0roZh3.mjs → assistant-provider-b2GtJb5K.mjs} +1 -1
  69. package/dist/packem_shared/{data-grid-B5m1OosL.mjs → data-grid-GQLHcpMI.mjs} +1 -1
  70. package/dist/packem_shared/{diagram-export-panel-Vdt-DZnO.mjs → diagram-export-panel-miFPsocM.mjs} +1 -1
  71. package/dist/packem_shared/{error-alert-3AR_-s_s.mjs → error-alert-BxCd81tw.mjs} +1 -1
  72. package/dist/packem_shared/{grid-features-Drvfswwy.mjs → grid-features-Cdy2nWxA.mjs} +2 -2
  73. package/dist/packem_shared/{home-panel-TpxiaHgB.mjs → home-panel-BlvQ0xK2.mjs} +1 -1
  74. package/dist/packem_shared/{internal-hIuTpSbx.mjs → internal-BT5tH08j.mjs} +1 -1
  75. package/dist/packem_shared/{log-line-CYJQf6P-.mjs → log-line-BmYn49u1.mjs} +1 -1
  76. package/dist/packem_shared/{recording-client-z4CBi0y8.mjs → recording-client-D_-eNapT.mjs} +1 -1
  77. package/dist/packem_shared/{reference-view-DENugPcj.mjs → reference-view-CRtrtDMy.mjs} +3 -3
  78. package/dist/packem_shared/{schema-diagram-CtVPhOGj.mjs → schema-diagram-Dbs7-jSJ.mjs} +1 -1
  79. package/dist/packem_shared/{sql-result-table-DCwooMGW.mjs → sql-result-table-BuOHHoFG.mjs} +1 -1
  80. package/dist/packem_shared/{studio-DZlpp4Vx.mjs → studio-CwelGawN.mjs} +1 -1
  81. package/dist/packem_shared/{table-list-sidebar-Bfmg04MD.mjs → table-list-sidebar-Cw7ll9yK.mjs} +1 -1
  82. package/dist/packem_shared/{use-admin-query-CaOm4JS3.mjs → use-admin-query-DMnTt_hg.mjs} +1 -1
  83. package/dist/packem_shared/{use-admin-spec-CK7mk3Ui.mjs → use-admin-spec-Cokw73Ks.mjs} +1 -1
  84. package/dist/packem_shared/use-assistant-rpc-DLsuqTPB.mjs +1 -0
  85. package/dist/packem_shared/{use-async-submit-D0r7-m2J.mjs → use-async-submit-CBFJevkc.mjs} +1 -1
  86. package/dist/packem_shared/{use-auth-config-DameIc6y.mjs → use-auth-config-xzSMjhOV.mjs} +1 -1
  87. package/dist/packem_shared/{use-open-trace-BJKMJjeS.mjs → use-open-trace-trRfFb77.mjs} +1 -1
  88. package/dist/standalone/{chunk-F2DVDJV6.js → chunk-26XOFIV4.js} +1 -1
  89. package/dist/standalone/{chunk-MTBY4GXM.js → chunk-2AKEF2E6.js} +1 -1
  90. package/dist/standalone/chunk-2BX4MJK6.js +1 -0
  91. package/dist/standalone/{chunk-XBHRAFJA.js → chunk-2DDDI4IG.js} +1 -1
  92. package/dist/standalone/{chunk-Z4BLDRDD.js → chunk-2YQF4QCI.js} +1 -1
  93. package/dist/standalone/{chunk-SBQT2ZSX.js → chunk-3CDQYHJX.js} +1 -1
  94. package/dist/standalone/{chunk-FKOAI6VV.js → chunk-3CHHMX6A.js} +1 -1
  95. package/dist/standalone/{chunk-YL5ZAR3P.js → chunk-3CUQWI5A.js} +1 -1
  96. package/dist/standalone/{chunk-7MQQPZQC.js → chunk-3DIKPPNZ.js} +1 -1
  97. package/dist/standalone/{chunk-WVURFBJS.js → chunk-3JLFCEXX.js} +1 -1
  98. package/dist/standalone/{chunk-FPODRWDZ.js → chunk-3SRQFKDT.js} +1 -1
  99. package/dist/standalone/{chunk-ML6YSDEQ.js → chunk-4EZ3YMBU.js} +1 -1
  100. package/dist/standalone/{chunk-SADHW6WJ.js → chunk-4NRWZ3IK.js} +1 -1
  101. package/dist/standalone/{chunk-3QNDJXLL.js → chunk-4UDH2YI4.js} +1 -1
  102. package/dist/standalone/{chunk-AY4DPAPO.js → chunk-57JJA4FO.js} +1 -1
  103. package/dist/standalone/{chunk-K7GU4AIX.js → chunk-6HVMODID.js} +1 -1
  104. package/dist/standalone/{chunk-I7PUGF3D.js → chunk-6XU2QUI3.js} +1 -1
  105. package/dist/standalone/{chunk-HBEZGCPB.js → chunk-73WXN7SZ.js} +1 -1
  106. package/dist/standalone/{chunk-I626YY7T.js → chunk-75LZZADZ.js} +1 -1
  107. package/dist/standalone/{chunk-4TGALJHR.js → chunk-7MM2SI65.js} +1 -1
  108. package/dist/standalone/{chunk-AWFFXR6S.js → chunk-A27GQYC7.js} +1 -1
  109. package/dist/standalone/{chunk-W3WGVJNJ.js → chunk-AE4LQOKG.js} +1 -1
  110. package/dist/standalone/{chunk-2VGEYQJ5.js → chunk-AMX5BC24.js} +1 -1
  111. package/dist/standalone/{chunk-JXUU3BD2.js → chunk-CAEQ6OOD.js} +1 -1
  112. package/dist/standalone/{chunk-UUOEHNMP.js → chunk-CCJUOPWR.js} +1 -1
  113. package/dist/standalone/{chunk-4YEGXH2V.js → chunk-CHYLD556.js} +1 -1
  114. package/dist/standalone/{chunk-WDR3BJ2C.js → chunk-CLZSERWW.js} +1 -1
  115. package/dist/standalone/{chunk-IMM6HPPD.js → chunk-CNPADLAP.js} +1 -1
  116. package/dist/standalone/{chunk-XOLTLG4I.js → chunk-D3YEERHT.js} +1 -1
  117. package/dist/standalone/{chunk-3NYU3CCO.js → chunk-D57SW6H5.js} +1 -1
  118. package/dist/standalone/{chunk-GCYQOJYI.js → chunk-DLF6VPZK.js} +1 -1
  119. package/dist/standalone/{chunk-NPZG7XK5.js → chunk-EFJ5SREG.js} +1 -1
  120. package/dist/standalone/{chunk-VGKDC2OQ.js → chunk-EG45XFL3.js} +1 -1
  121. package/dist/standalone/{chunk-RAJ327CY.js → chunk-EI2FSTI3.js} +1 -1
  122. package/dist/standalone/{chunk-KQVY73EU.js → chunk-F4ZN2DRL.js} +3 -3
  123. package/dist/standalone/{chunk-DELDS72W.js → chunk-F7SJ4DOF.js} +1 -1
  124. package/dist/standalone/{chunk-ZZA6VQDG.js → chunk-FNWWGQVC.js} +1 -1
  125. package/dist/standalone/{chunk-NQ727GVM.js → chunk-FOXLEMWC.js} +1 -1
  126. package/dist/standalone/{chunk-337EJGCU.js → chunk-G62WODKV.js} +1 -1
  127. package/dist/standalone/{chunk-2KREOMPV.js → chunk-GMKV6EAQ.js} +1 -1
  128. package/dist/standalone/{chunk-V4JKKAAZ.js → chunk-GTW3JPQQ.js} +1 -1
  129. package/dist/standalone/{chunk-XSFGXEYO.js → chunk-GWJ57WD2.js} +1 -1
  130. package/dist/standalone/{chunk-MICDQTTJ.js → chunk-HFDKQBIZ.js} +1 -1
  131. package/dist/standalone/{chunk-WONKLAKW.js → chunk-HVKGOO4E.js} +1 -1
  132. package/dist/standalone/{chunk-JELTLAEP.js → chunk-I4AZTCAA.js} +1 -1
  133. package/dist/standalone/{chunk-274SZA4F.js → chunk-I4EVK4EW.js} +1 -1
  134. package/dist/standalone/{chunk-76D454G5.js → chunk-JEYIP5MS.js} +1 -1
  135. package/dist/standalone/{chunk-XEIJUQ4B.js → chunk-JI4WZ5K5.js} +1 -1
  136. package/dist/standalone/{chunk-MGYRQPAY.js → chunk-JNB2EV3N.js} +1 -1
  137. package/dist/standalone/{chunk-ZBLG4UAV.js → chunk-JR66YIA4.js} +1 -1
  138. package/dist/standalone/{chunk-RPRNYCFT.js → chunk-KB75JASP.js} +1 -1
  139. package/dist/standalone/{chunk-5NPU6VPX.js → chunk-KNZGU3CE.js} +1 -1
  140. package/dist/standalone/{chunk-OVPS52RO.js → chunk-KS2ZCKZ2.js} +1 -1
  141. package/dist/standalone/{chunk-WU2ST74V.js → chunk-L645XKP6.js} +1 -1
  142. package/dist/standalone/{chunk-QCG2G6IF.js → chunk-LAQNOLYC.js} +1 -1
  143. package/dist/standalone/{chunk-EVUVQB4Q.js → chunk-M2X2UFAA.js} +1 -1
  144. package/dist/standalone/{chunk-AE3ABYCE.js → chunk-MSW4QPCU.js} +1 -1
  145. package/dist/standalone/{chunk-X474JV2D.js → chunk-N36AT4CI.js} +1 -1
  146. package/dist/standalone/{chunk-ELWBGGS7.js → chunk-NCDS5OJ4.js} +1 -1
  147. package/dist/standalone/{chunk-O65QTRXU.js → chunk-NIHVUGDE.js} +1 -1
  148. package/dist/standalone/{chunk-VTTS5L36.js → chunk-NLRCYQUM.js} +1 -1
  149. package/dist/standalone/{chunk-UOFMFYZ7.js → chunk-NX6JHCY5.js} +2 -2
  150. package/dist/standalone/{chunk-2DKLUTH2.js → chunk-OKDHAG2Y.js} +1 -1
  151. package/dist/standalone/{chunk-LHQFTCOS.js → chunk-OYO74NM4.js} +1 -1
  152. package/dist/standalone/{chunk-Q7KRCKCE.js → chunk-PBHKQULL.js} +1 -1
  153. package/dist/standalone/{chunk-GDAZWXQW.js → chunk-PFIATRRO.js} +1 -1
  154. package/dist/standalone/{chunk-66IUCD6W.js → chunk-PSPK6BZ2.js} +1 -1
  155. package/dist/standalone/{chunk-NDIEUO4N.js → chunk-QKWIY6JW.js} +1 -1
  156. package/dist/standalone/{chunk-YTLKHICM.js → chunk-QLMDHJMC.js} +1 -1
  157. package/dist/standalone/{chunk-KXUK7CSR.js → chunk-QQ4LEH7V.js} +1 -1
  158. package/dist/standalone/{chunk-ZZ6ZCOD4.js → chunk-QQENKHRS.js} +1 -1
  159. package/dist/standalone/{chunk-RK3HQKPW.js → chunk-QT3W5POL.js} +1 -1
  160. package/dist/standalone/{chunk-A2LKDNNA.js → chunk-QTG3KGNJ.js} +1 -1
  161. package/dist/standalone/{chunk-DWKKQ75U.js → chunk-ROHVLVGW.js} +1 -1
  162. package/dist/standalone/{chunk-5QK3ZHNZ.js → chunk-RQHLJCG7.js} +1 -1
  163. package/dist/standalone/{chunk-OOUGGYHQ.js → chunk-RRDXY56O.js} +1 -1
  164. package/dist/standalone/{chunk-MULFKWTQ.js → chunk-RWEEBORY.js} +1 -1
  165. package/dist/standalone/{chunk-MNXXIISC.js → chunk-RY6I3E2K.js} +1 -1
  166. package/dist/standalone/{chunk-DJPK4PZV.js → chunk-S3LW4HCF.js} +1 -1
  167. package/dist/standalone/{chunk-O4SDDSDL.js → chunk-S63YTOR5.js} +1 -1
  168. package/dist/standalone/{chunk-KVQ2GMJR.js → chunk-SGIW3B4R.js} +1 -1
  169. package/dist/standalone/{chunk-LYNQHGQ4.js → chunk-SOKPPTFJ.js} +1 -1
  170. package/dist/standalone/{chunk-4E6DQHFK.js → chunk-SOTNC2VE.js} +1 -1
  171. package/dist/standalone/{chunk-OJO6ERJ4.js → chunk-TMIYU26C.js} +1 -1
  172. package/dist/standalone/{chunk-D2LGOQ32.js → chunk-TY5MXKUY.js} +1 -1
  173. package/dist/standalone/{chunk-UFFUDDK7.js → chunk-VTAHI7AZ.js} +1 -1
  174. package/dist/standalone/{chunk-JQBZDS6X.js → chunk-VX6ZBLXB.js} +1 -1
  175. package/dist/standalone/{chunk-ZPQFM3A7.js → chunk-WD6TOMHJ.js} +1 -1
  176. package/dist/standalone/{chunk-ZHZHI6KX.js → chunk-WHIWJD5H.js} +1 -1
  177. package/dist/standalone/{chunk-QOK2UU3L.js → chunk-WUK2O2KI.js} +1 -1
  178. package/dist/standalone/{chunk-NYLSD5LR.js → chunk-XEZ7LEII.js} +1 -1
  179. package/dist/standalone/{chunk-4W7SB3SF.js → chunk-YFZFL4XI.js} +1 -1
  180. package/dist/standalone/{chunk-OR4RO6V4.js → chunk-YIVDW4BV.js} +1 -1
  181. package/dist/standalone/{chunk-5MIJ3KEK.js → chunk-Z7HICJ3Z.js} +1 -1
  182. package/dist/standalone/chunk-ZBXY4FVL.js +14 -0
  183. package/dist/standalone/studio.js +1 -1
  184. package/package.json +2 -2
  185. package/dist/packem_shared/ApiDocsPanel-sEDqUNQq.mjs +0 -2
  186. package/dist/packem_shared/Studio-BmbkaUrx.mjs +0 -1
  187. package/dist/packem_shared/use-assistant-rpc-AKu8hvPm.mjs +0 -1
  188. package/dist/standalone/chunk-A4F3YMBV.js +0 -1
  189. package/dist/standalone/chunk-AQ6LY5RO.js +0 -14
  190. /package/dist/standalone/{chunk-VJQP4ARP.js → chunk-ITS5LMYJ.js} +0 -0
@@ -1 +1 @@
1
- import{c as we}from"react/compiler-runtime";import{ShardInput as Ze}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{S as Ke,T as Pe}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{B as Fe}from"../packem_shared/badge-r_5B4LHP.mjs";import{c as Ge,d as ze,b as Be,a as De,C as je}from"../packem_shared/card-By2O8ULa.mjs";import{E as et}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as ke}from"../packem_shared/input-CXhxesPC.mjs";import{useT as Oe}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{c as Le,d as Ae,b as $e,f as Ce}from"../packem_shared/internal-hIuTpSbx.mjs";import{c as Qe}from"../packem_shared/utils-bhneXptQ.mjs";import{useState as _,useRef as Ue,useEffect as qe}from"react";import{u as tt}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{u as lt}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{ADMIN_FUNCTIONS as Me}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{r as st}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{S as at}from"../packem_shared/schema-diagram-CtVPhOGj.mjs";import{useNavigate as nt}from"@tanstack/react-router";import{B as ye}from"../packem_shared/button-q0UYSmrn.mjs";import{L as Ee}from"../packem_shared/label-DKFzyHq6.mjs";import{jsx as l,jsxs as p,Fragment as Ve}from"react/jsx-runtime";const ot=Le(Me.listTables),it=Le(Me.listTableIndexes),rt=Le(Me.readTablePage),dt=Le(Me.describeTables),ct={},Ye=[],mt=n=>{const e=we(74),{initialShardKey:m,initialTable:a}=n,t=lt(),[s,c]=_("graph"),{queryShardKey:d,setShardKey:r,shardKey:g}=tt(m),[o,u]=_(""),[i,v]=_(null),[f,O]=_(null);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S={},e[0]=S):S=e[0];const[G,y]=_(S);let L;e[1]===Symbol.for("react.memo_cache_sentinel")?(L={},e[1]=L):L=e[1];const[$,z]=_(L),[T,C]=_(null);let A;e[2]===Symbol.for("react.memo_cache_sentinel")?(A={},e[2]=A):A=e[2];const[F,pe]=_(A);let te;e[3]===Symbol.for("react.memo_cache_sentinel")?(te={},e[3]=te):te=e[3];const[E,M]=_(te),[w,ge]=_(null),[B,ce]=_(null);let le;e[4]===Symbol.for("react.memo_cache_sentinel")?(le={},e[4]=le):le=e[4];const[J,Ne]=_(le),[W,me]=_(null),be=Ue(0);let D;e[5]!==t?(D=async h=>{be.current=be.current+1;const x=be.current;O(null);try{const N=await t.query(ot,{},Ae(h));if(x!==be.current)return;st(h),v(N),y({}),z({}),C(null),pe(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h}))),M(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h})))}catch(N){const k=N;if(x!==be.current)return;v(null),O($e(k))}},e[5]=t,e[6]=D):D=e[6];const j=D;let se;e[7]!==t?(se=async()=>{ce(null);try{ge(await t.listGlobalTables())}catch(h){const x=h;ge(null),ce($e(x))}},e[7]=t,e[8]=se):se=e[8];const ue=se;let R,ae;e[9]!==d||e[10]!==j||e[11]!==ue?(R=()=>{Ce(j(d)),Ce(ue())},ae=[j,ue,d],e[9]=d,e[10]=j,e[11]=ue,e[12]=R,e[13]=ae):(R=e[12],ae=e[13]),qe(R,ae);let K;e[14]!==t||e[15]!==G||e[16]!==T||e[17]!==d?(K=async h=>{if(T===h){C(null);return}C(h);const x=`${d}:${h}`;if(G[x]!==void 0)return;const[N,k]=await Promise.allSettled([t.query(rt,{limit:1,offset:0,table:h},Ae(d)),t.query(it,{table:h},Ae(d))]);N.status==="fulfilled"?y(I=>({...I,[x]:N.value.columns})):O($e(N.reason)),k.status==="fulfilled"&&z(I=>({...I,[x]:k.value.indexes}))},e[14]=t,e[15]=G,e[16]=T,e[17]=d,e[18]=K):K=e[18];const ne=K;let oe;e[19]!==t||e[20]!==J||e[21]!==W?(oe=async h=>{if(W===h){me(null);return}if(me(h),J[h]===void 0)try{const x=await t.readGlobalTablePage({limit:1,offset:0,table:h});Ne(N=>({...N,[h]:x.columns}))}catch(x){ce($e(x))}},e[19]=t,e[20]=J,e[21]=W,e[22]=oe):oe=e[22];const fe=oe,X=Ue(void 0);let Q,U;e[23]!==a||e[24]!==i||e[25]!==ne?(Q=()=>{a===void 0||i===null||X.current===a||i.some(h=>h.name===a)&&(X.current=a,Ce(ne(a)))},U=[a,i,ne],e[23]=a,e[24]=i,e[25]=ne,e[26]=Q,e[27]=U):(Q=e[26],U=e[27]),qe(Q,U);let ie;e[28]!==t?(ie=async(h,x,N)=>{const[k,I]=await Promise.all([Promise.allSettled([t.query(dt,{tables:[...x,...N]},Ae(h))]),Promise.all(N.map(async H=>{const Se=await Promise.allSettled([t.readGlobalTablePage({limit:1,offset:0,table:H})]),Re=Se[0].status==="fulfilled"?Se[0].value:void 0;return{columns:Re?.columns??[],refs:Re?.refs??{},table:H}}))]),he=k[0].status==="fulfilled"?k[0].value?.columnsByTable??{}:{},_e=k[0].status==="rejected",Ie=new Map(I.map(ut)),q=[...x,...N].map(H=>{const Se=he[H]??[];return[H,Se.length>0?Se:Ie.get(H)??[]]});pe(H=>({...H,[h]:Object.fromEntries(q)})),M(H=>({...H,[h]:_e}))},e[28]=t,e[29]=ie):ie=e[29];const V=ie;let re,Y;e[30]!==B||e[31]!==w||e[32]!==V||e[33]!==d||e[34]!==F||e[35]!==i||e[36]!==s?(re=()=>{s!=="graph"||i===null||w===null&&B===null||F[d]!==void 0||Ce(V(d,i.map(ft),(w??[]).map(ht)))},Y=[s,i,w,B,d,F,V],e[30]=B,e[31]=w,e[32]=V,e[33]=d,e[34]=F,e[35]=i,e[36]=s,e[37]=re,e[38]=Y):(re=e[37],Y=e[38]),qe(re,Y);const P=F[d]??ct;let Z;if(e[39]!==P||e[40]!==w||e[41]!==i){let h;e[43]!==P?(h=I=>({columns:P[I.name]??Ye,name:I.name,tier:"shard"}),e[43]=P,e[44]=h):h=e[44];const x=(i??[]).map(h);let N;e[45]!==P?(N=I=>({columns:P[I.name]??Ye,name:I.name,tier:"global"}),e[45]=P,e[46]=N):N=e[46];const k=(w??[]).map(N);Z=[...x,...k],e[39]=P,e[40]=w,e[41]=i,e[42]=Z}else Z=e[42];const b=Z;let ee;if(e[47]!==o||e[48]!==i){const h=o.trim().toLowerCase();ee=(i??[]).filter(x=>x.name.toLowerCase().includes(h)),e[47]=o,e[48]=i,e[49]=ee}else ee=e[49];const de=ee;let xe;if(e[50]!==w||e[51]!==o){const h=o.trim().toLowerCase();xe=(w??[]).filter(x=>x.name.toLowerCase().includes(h)),e[50]=w,e[51]=o,e[52]=xe}else xe=e[52];const Te=xe;let ve;return e[53]!==G||e[54]!==b||e[55]!==f||e[56]!==T||e[57]!==Te||e[58]!==de||e[59]!==J||e[60]!==B||e[61]!==W||e[62]!==w||e[63]!==$||e[64]!==j||e[65]!==r||e[66]!==E||e[67]!==g||e[68]!==o||e[69]!==i||e[70]!==ne||e[71]!==fe||e[72]!==s?(ve={columns:G,diagramTables:b,error:f,expanded:T,filteredGlobalTables:Te,filteredTables:de,globalColumns:J,globalError:B,globalExpanded:W,globalTables:w,indexes:$,refresh:j,setShardKey:r,setTableFilter:u,setView:c,shardColumnsError:E,shardKey:g,tableFilter:o,tables:i,toggle:ne,toggleGlobal:fe,view:s},e[53]=G,e[54]=b,e[55]=f,e[56]=T,e[57]=Te,e[58]=de,e[59]=J,e[60]=B,e[61]=W,e[62]=w,e[63]=$,e[64]=j,e[65]=r,e[66]=E,e[67]=g,e[68]=o,e[69]=i,e[70]=ne,e[71]=fe,e[72]=s,e[73]=ve):ve=e[73],ve};function ut(n){const{columns:e,refs:m,table:a}=n;return[a,e.map(t=>{const s=m[t];return s===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:s,type:"id"}})]}function ft(n){return n.name}function ht(n){return n.name}const pt="/__lunora/schema-edit",gt=async n=>{const e=await fetch(pt,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"},method:"POST"}),m=await e.json();return m.needsMigration===!0?{kind:"needs-migration",message:m.message??"This edit needs a migration."}:e.ok&&m.tables!==void 0?{diagnostics:m.diagnostics??[],kind:"ok",tables:m.tables}:{kind:"error",message:m.error??`schema edit failed (${String(e.status)})`}},bt=n=>{const e=we(32),{hasTables:m,mode:a,onAddColumn:t,onAddIndex:s,onAddTable:c,onDestructive:d}=n,r=Oe(),g=a==="addTable"?"default":"outline";let o;e[0]!==r?(o=r("Add table"),e[0]=r,e[1]=o):o=e[1];let u;e[2]!==c||e[3]!==g||e[4]!==o?(u=l(ye,{"data-testid":"sc-editor-add-table",onClick:c,size:"xs",type:"button",variant:g,children:o}),e[2]=c,e[3]=g,e[4]=o,e[5]=u):u=e[5];const i=!m,v=a==="addColumn"?"default":"outline";let f;e[6]!==r?(f=r("Add column"),e[6]=r,e[7]=f):f=e[7];let O;e[8]!==t||e[9]!==i||e[10]!==v||e[11]!==f?(O=l(ye,{"data-testid":"sc-editor-add-column",disabled:i,onClick:t,size:"xs",type:"button",variant:v,children:f}),e[8]=t,e[9]=i,e[10]=v,e[11]=f,e[12]=O):O=e[12];const S=!m,G=a==="addIndex"?"default":"outline";let y;e[13]!==r?(y=r("Add index"),e[13]=r,e[14]=y):y=e[14];let L;e[15]!==s||e[16]!==y||e[17]!==S||e[18]!==G?(L=l(ye,{"data-testid":"sc-editor-add-index",disabled:S,onClick:s,size:"xs",type:"button",variant:G,children:y}),e[15]=s,e[16]=y,e[17]=S,e[18]=G,e[19]=L):L=e[19];const $=!m,z=a==="destructive"?"default":"ghost";let T;e[20]!==r?(T=r("Rename / drop / change type…"),e[20]=r,e[21]=T):T=e[21];let C;e[22]!==d||e[23]!==$||e[24]!==z||e[25]!==T?(C=l(ye,{"data-testid":"sc-editor-destructive",disabled:$,onClick:d,size:"xs",type:"button",variant:z,children:T}),e[22]=d,e[23]=$,e[24]=z,e[25]=T,e[26]=C):C=e[26];let A;return e[27]!==L||e[28]!==C||e[29]!==u||e[30]!==O?(A=p("div",{className:"flex flex-wrap gap-2",children:[u,O,L,C]}),e[27]=L,e[28]=C,e[29]=u,e[30]=O,e[31]=A):A=e[31],A},xt=n=>{const e=we(28),{onOpenMigrations:m,result:a}=n,t=Oe();if(a===null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[0]=o):o=e[0],o}if(a.kind==="error"){let o;return e[1]!==a.message?(o=l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:a.message}),e[1]=a.message,e[2]=o):o=e[2],o}if(a.kind==="needs-migration"){let o;e[3]!==a.message||e[4]!==t?(o=a.message===""?t("This edit changes stored data and must go through a migration. Review the migration before applying."):a.message,e[3]=a.message,e[4]=t,e[5]=o):o=e[5];let u;e[6]!==o?(u=l("p",{className:"text-sm text-warning",role:"alert",children:o}),e[6]=o,e[7]=u):u=e[7];let i;e[8]!==t?(i=t("Open Migrations"),e[8]=t,e[9]=i):i=e[9];let v;e[10]!==m||e[11]!==i?(v=l(ye,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:m,size:"xs",type:"button",variant:"outline",children:i}),e[10]=m,e[11]=i,e[12]=v):v=e[12];let f;return e[13]!==u||e[14]!==v?(f=p("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[u,v]}),e[13]=u,e[14]=v,e[15]=f):f=e[15],f}if(a.diagnostics.length===0){let o;return e[16]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[16]=o):o=e[16],o}let s;e[17]!==t?(s=t("Codegen reported diagnostics:"),e[17]=t,e[18]=s):s=e[18];let c;e[19]!==s?(c=l("p",{className:"text-sm text-destructive",role:"alert",children:s}),e[19]=s,e[20]=c):c=e[20];let d;e[21]!==a.diagnostics?(d=a.diagnostics.map(vt),e[21]=a.diagnostics,e[22]=d):d=e[22];let r;e[23]!==d?(r=l("ul",{className:"flex flex-col gap-0.5",children:d}),e[23]=d,e[24]=r):r=e[24];let g;return e[25]!==c||e[26]!==r?(g=p("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[c,r]}),e[25]=c,e[26]=r,e[27]=g):g=e[27],g};function vt(n){return l("li",{className:"font-mono text-[11px] text-destructive",children:n},n)}const yt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.bigint()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],Ct="v.string()",Nt=n=>n.split(",").map(e=>e.trim()).filter(e=>e!==""),Tt=n=>{const e=we(83),{onApplied:m,tableNames:a}=n,t=Oe(),s=nt(),[c,d]=_(null),[r,g]=_(!1),[o,u]=_(null),[i,v]=_(""),[f,O]=_(""),[S,G]=_(Ct),[y,L]=_(a[0]??""),[$,z]=_(""),[T,C]=_(""),[A,F]=_(!1);let pe;e[0]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>{d(null),v(""),O(""),z(""),C(""),F(!1)},e[0]=pe):pe=e[0];const te=pe;let E;e[1]!==m?(E=async q=>{g(!0),u(null);try{const H=await gt(q);u(H),H.kind==="ok"&&(m(H.tables),te())}catch(H){const Se=H;u({kind:"error",message:Se instanceof Error?Se.message:String(Se)})}g(!1)},e[1]=m,e[2]=E):E=e[2];const M=E;let w;e[3]!==M||e[4]!==i?(w=()=>{Ce(M({kind:"addTable",table:i.trim()}))},e[3]=M,e[4]=i,e[5]=w):w=e[5];const ge=w;let B;e[6]!==f||e[7]!==M||e[8]!==y||e[9]!==S?(B=()=>{Ce(M({column:f.trim(),kind:"addOptionalColumn",table:y,validator:S}))},e[6]=f,e[7]=M,e[8]=y,e[9]=S,e[10]=B):B=e[10];const ce=B;let le;e[11]!==T||e[12]!==$||e[13]!==M||e[14]!==y||e[15]!==A?(le=()=>{Ce(M({fields:Nt(T),kind:"addIndex",name:$.trim(),table:y,unique:A}))},e[11]=T,e[12]=$,e[13]=M,e[14]=y,e[15]=A,e[16]=le):le=e[16];const J=le;let Ne;e[17]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>{u(null),d("addTable")},e[17]=Ne):Ne=e[17];const W=Ne;let me;e[18]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{u(null),d("addColumn")},e[18]=me):me=e[18];const be=me;let D;e[19]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{u(null),d("addIndex")},e[19]=D):D=e[19];const j=D;let se;e[20]!==t?(se=()=>{d("destructive"),u({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=se):se=e[21];const ue=se;let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=q=>{v(q.target.value)},e[22]=R):R=e[22];const ae=R;let K;e[23]===Symbol.for("react.memo_cache_sentinel")?(K=q=>{O(q.target.value)},e[23]=K):K=e[23];const ne=K;let oe;e[24]===Symbol.for("react.memo_cache_sentinel")?(oe=q=>{G(q.target.value)},e[24]=oe):oe=e[24];const fe=oe;let X;e[25]===Symbol.for("react.memo_cache_sentinel")?(X=q=>{L(q.target.value)},e[25]=X):X=e[25];const Q=X;let U;e[26]===Symbol.for("react.memo_cache_sentinel")?(U=q=>{z(q.target.value)},e[26]=U):U=e[26];const ie=U;let V;e[27]===Symbol.for("react.memo_cache_sentinel")?(V=q=>{C(q.target.value)},e[27]=V):V=e[27];const re=V;let Y;e[28]===Symbol.for("react.memo_cache_sentinel")?(Y=q=>{F(q.target.checked)},e[28]=Y):Y=e[28];const P=Y;let Z;e[29]!==s?(Z=()=>{Ce(s({to:"/migrations"}))},e[29]=s,e[30]=Z):Z=e[30];const b=Z;let ee;e[31]!==t?(ee=t("Edit schema"),e[31]=t,e[32]=ee):ee=e[32];let de;e[33]!==ee?(de=l(Ge,{children:ee}),e[33]=ee,e[34]=de):de=e[34];let xe;e[35]!==t?(xe=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=xe):xe=e[36];let Te;e[37]!==xe?(Te=l(ze,{children:xe}),e[37]=xe,e[38]=Te):Te=e[38];let ve;e[39]!==de||e[40]!==Te?(ve=p(Be,{children:[de,Te]}),e[39]=de,e[40]=Te,e[41]=ve):ve=e[41];const h=a.length>0;let x;e[42]!==c||e[43]!==ue||e[44]!==h?(x=l(bt,{hasTables:h,mode:c,onAddColumn:be,onAddIndex:j,onAddTable:W,onDestructive:ue}),e[42]=c,e[43]=ue,e[44]=h,e[45]=x):x=e[45];let N;e[46]!==r||e[47]!==c||e[48]!==ge||e[49]!==t||e[50]!==i?(N=c==="addTable"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(ke,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:ae,value:i})]}),l(ye,{"data-testid":"sc-editor-table-apply",disabled:r||i.trim()==="",onClick:ge,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[46]=r,e[47]=c,e[48]=ge,e[49]=t,e[50]=i,e[51]=N):N=e[51];let k;e[52]!==r||e[53]!==f||e[54]!==c||e[55]!==ce||e[56]!==t||e[57]!==a||e[58]!==y||e[59]!==S?(k=c==="addColumn"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:Q,value:y,children:a.map(St)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(ke,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:ne,value:f})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:fe,value:S,children:yt.map(wt)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(ye,{"data-testid":"sc-editor-column-apply",disabled:r||f.trim()===""||y==="",onClick:ce,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[52]=r,e[53]=f,e[54]=c,e[55]=ce,e[56]=t,e[57]=a,e[58]=y,e[59]=S,e[60]=k):k=e[60];let I;e[61]!==r||e[62]!==T||e[63]!==$||e[64]!==c||e[65]!==J||e[66]!==t||e[67]!==a||e[68]!==y||e[69]!==A?(I=c==="addIndex"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:Q,value:y,children:a.map(_t)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(ke,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:ie,value:$})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(ke,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:re,value:T})]}),p(Ee,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:A,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:P,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(ye,{"data-testid":"sc-editor-index-apply",disabled:r||$.trim()===""||T.trim()==="",onClick:J,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[61]=r,e[62]=T,e[63]=$,e[64]=c,e[65]=J,e[66]=t,e[67]=a,e[68]=y,e[69]=A,e[70]=I):I=e[70];let he;e[71]!==b||e[72]!==o?(he=l(xt,{onOpenMigrations:b,result:o}),e[71]=b,e[72]=o,e[73]=he):he=e[73];let _e;e[74]!==x||e[75]!==N||e[76]!==k||e[77]!==I||e[78]!==he?(_e=p(De,{children:[x,N,k,I,he]}),e[74]=x,e[75]=N,e[76]=k,e[77]=I,e[78]=he,e[79]=_e):_e=e[79];let Ie;return e[80]!==ve||e[81]!==_e?(Ie=p(je,{"data-testid":"sc-editor",size:"sm",children:[ve,_e]}),e[80]=ve,e[81]=_e,e[82]=Ie):Ie=e[82],Ie};function St(n){return l("option",{value:n,children:n},n)}function wt(n){return l("option",{value:n.validator,children:n.label},n.validator)}function _t(n){return l("option",{value:n,children:n},n)}const He=[],Et=n=>{const e=we(5),{open:m}=n,a=m&&"rotate-90";let t;e[0]!==a?(t=Qe("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",a),e[0]=a,e[1]=t):t=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=l("path",{d:"m9 6 6 6-6 6"}),e[2]=s):s=e[2];let c;return e[3]!==t?(c=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:s}),e[3]=t,e[4]=c):c=e[4],c},Je=n=>{const e=we(20),{children:m,expanded:a,name:t,onToggle:s,rowCount:c,rowTestId:d,toggleTestId:r}=n;let g;e[0]!==a?(g=l(Et,{open:a}),e[0]=a,e[1]=g):g=e[1];let o;e[2]!==t?(o=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=o):o=e[3];let u;e[4]!==c?(u=p("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",c,")"]}),e[4]=c,e[5]=u):u=e[5];let i;e[6]!==a||e[7]!==s||e[8]!==g||e[9]!==o||e[10]!==u||e[11]!==r?(i=p("button",{"aria-expanded":a,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":r,onClick:s,type:"button",children:[g,o," ",u]}),e[6]=a,e[7]=s,e[8]=g,e[9]=o,e[10]=u,e[11]=r,e[12]=i):i=e[12];let v;e[13]!==m||e[14]!==a?(v=a&&l("div",{className:"px-3 pb-3 ps-8",children:m}),e[13]=m,e[14]=a,e[15]=v):v=e[15];let f;return e[16]!==d||e[17]!==i||e[18]!==v?(f=p("li",{className:"border-t border-border/60 first:border-t-0","data-testid":d,children:[i,v]}),e[16]=d,e[17]=i,e[18]=v,e[19]=f):f=e[19],f},We=n=>{const e=we(5),{columns:m,testId:a}=n;let t;e[0]!==m?(t=m.map(kt),e[0]=m,e[1]=t):t=e[1];let s;return e[2]!==t||e[3]!==a?(s=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":a,children:t}),e[2]=t,e[3]=a,e[4]=s):s=e[4],s},It=n=>{const e=we(10),{heading:m,indexes:a,testId:t}=n;let s;e[0]!==m?(s=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:m}),e[0]=m,e[1]=s):s=e[1];let c;e[2]!==a?(c=a.map(At),e[2]=a,e[3]=c):c=e[3];let d;e[4]!==c||e[5]!==t?(d=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:c}),e[4]=c,e[5]=t,e[6]=d):d=e[6];let r;return e[7]!==s||e[8]!==d?(r=p("div",{className:"pt-3",children:[s,d]}),e[7]=s,e[8]=d,e[9]=r):r=e[9],r},Xe=n=>Qe("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",n?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Qt=n=>{const e=we(85),{initialShardKey:m,initialTable:a,schemaEditable:t}=n,s=Oe();let c;e[0]!==m||e[1]!==a?(c={initialShardKey:m,initialTable:a},e[0]=m,e[1]=a,e[2]=c):c=e[2];const{columns:d,diagramTables:r,error:g,expanded:o,filteredGlobalTables:u,filteredTables:i,globalColumns:v,globalError:f,globalExpanded:O,globalTables:S,indexes:G,refresh:y,setShardKey:L,setTableFilter:$,setView:z,shardColumnsError:T,shardKey:C,tableFilter:A,tables:F,toggle:pe,toggleGlobal:te,view:E}=mt(c);let M;e[3]!==z?(M=()=>{z("list")},e[3]=z,e[4]=M):M=e[4];const w=M;let ge;e[5]!==z?(ge=()=>{z("graph")},e[5]=z,e[6]=ge):ge=e[6];const B=ge;let ce;e[7]!==$?(ce=b=>{$(b.target.value)},e[7]=$,e[8]=ce):ce=e[8];const le=ce;let J;e[9]!==y||e[10]!==C?(J=b=>{Ce(y(C))},e[9]=y,e[10]=C,e[11]=J):J=e[11];const Ne=J;let W;e[12]!==F?(W=F??[],e[12]=F,e[13]=W):W=e[13];let me;e[14]!==W?(me=W.map($t),e[14]=W,e[15]=me):me=e[15];const be=me;let D;e[16]!==L||e[17]!==C?(D=l(Ze,{onChange:L,testId:"sc-shard-input",value:C}),e[16]=L,e[17]=C,e[18]=D):D=e[18];let j;e[19]!==s?(j=s("Schema view"),e[19]=s,e[20]=j):j=e[20];const se=E==="graph",ue=E==="graph";let R;e[21]!==ue?(R=Xe(ue),e[21]=ue,e[22]=R):R=e[22];let ae;e[23]!==s?(ae=s("Graph"),e[23]=s,e[24]=ae):ae=e[24];let K;e[25]!==B||e[26]!==se||e[27]!==R||e[28]!==ae?(K=l("button",{"aria-selected":se,className:R,"data-testid":"sc-view-graph",onClick:B,role:"tab",type:"button",children:ae}),e[25]=B,e[26]=se,e[27]=R,e[28]=ae,e[29]=K):K=e[29];const ne=E==="list",oe=E==="list";let fe;e[30]!==oe?(fe=Xe(oe),e[30]=oe,e[31]=fe):fe=e[31];let X;e[32]!==s?(X=s("Table list"),e[32]=s,e[33]=X):X=e[33];let Q;e[34]!==w||e[35]!==ne||e[36]!==fe||e[37]!==X?(Q=l("button",{"aria-selected":ne,className:fe,"data-testid":"sc-view-list",onClick:w,role:"tab",type:"button",children:X}),e[34]=w,e[35]=ne,e[36]=fe,e[37]=X,e[38]=Q):Q=e[38];let U;e[39]!==K||e[40]!==Q||e[41]!==j?(U=p("div",{"aria-label":j,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[K,Q]}),e[39]=K,e[40]=Q,e[41]=j,e[42]=U):U=e[42];let ie;e[43]!==U||e[44]!==D?(ie=p("div",{className:"flex flex-wrap items-center gap-3",children:[D,U]}),e[43]=U,e[44]=D,e[45]=ie):ie=e[45];let V;e[46]!==Ne||e[47]!==t||e[48]!==be?(V=t===!0&&l(Tt,{onApplied:Ne,tableNames:be}),e[46]=Ne,e[47]=t,e[48]=be,e[49]=V):V=e[49];let re;e[50]!==le||e[51]!==s||e[52]!==A||e[53]!==E?(re=E==="list"&&l(ke,{"aria-label":s("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:le,placeholder:s("Filter tables"),value:A}),e[50]=le,e[51]=s,e[52]=A,e[53]=E,e[54]=re):re=e[54];let Y;e[55]!==r||e[56]!==g||e[57]!==f||e[58]!==T||e[59]!==C||e[60]!==E?(Y=E==="graph"&&p("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),l(at,{columnsError:T[C]===!0,tables:r,testIdPrefix:"sc-graph"})]}),e[55]=r,e[56]=g,e[57]=f,e[58]=T,e[59]=C,e[60]=E,e[61]=Y):Y=e[61];let P;e[62]!==d||e[63]!==g||e[64]!==o||e[65]!==u||e[66]!==i||e[67]!==v||e[68]!==f||e[69]!==O||e[70]!==S||e[71]!==G||e[72]!==C||e[73]!==s||e[74]!==F||e[75]!==pe||e[76]!==te||e[77]!==E?(P=E==="list"&&p("div",{className:"flex flex-col gap-4",children:[p(je,{"data-testid":"sc-shard-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"shard"}),l(Ge,{children:s("Shard tables")}),F!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:i.length})]}),l(ze,{children:Pe.shard.hint})]}),p(De,{children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),F!==null&&F.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:s("No tables in this shard.")}),F!==null&&F.length>0&&i.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:s("No tables match your filter.")}),i.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:i.map(b=>{const ee=`${C}:${b.name}`,de=G[ee]??[];return p(Je,{expanded:o===b.name,name:b.name,onToggle:()=>{Ce(pe(b.name))},rowCount:b.rowCount,rowTestId:`sc-table-${b.name}`,toggleTestId:`sc-toggle-${b.name}`,children:[l(We,{columns:d[ee]??He,testId:`sc-columns-${b.name}`}),de.length>0&&l(It,{heading:s("Indexes"),indexes:de,testId:`sc-indexes-${b.name}`})]},b.name)})})]})]}),p(je,{"data-testid":"sc-global-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"global"}),l(Ge,{children:s("Global tables (D1)")}),S!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:u.length})]}),l(ze,{children:Pe.global.hint})]}),p(De,{children:[f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),S!==null&&S.length===0&&l(et,{description:Pe.global.hint,testId:"sc-global-empty",title:s("No global tables.")}),S!==null&&S.length>0&&u.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:s("No tables match your filter.")}),u.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:u.map(b=>l(Je,{expanded:O===b.name,name:b.name,onToggle:()=>{Ce(te(b.name))},rowCount:b.rowCount,rowTestId:`sc-global-table-${b.name}`,toggleTestId:`sc-global-toggle-${b.name}`,children:l(We,{columns:v[b.name]??He,testId:`sc-global-columns-${b.name}`})},b.name))})]})]})]}),e[62]=d,e[63]=g,e[64]=o,e[65]=u,e[66]=i,e[67]=v,e[68]=f,e[69]=O,e[70]=S,e[71]=G,e[72]=C,e[73]=s,e[74]=F,e[75]=pe,e[76]=te,e[77]=E,e[78]=P):P=e[78];let Z;return e[79]!==ie||e[80]!==V||e[81]!==re||e[82]!==Y||e[83]!==P?(Z=p("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[ie,V,re,Y,P]}),e[79]=ie,e[80]=V,e[81]=re,e[82]=Y,e[83]=P,e[84]=Z):Z=e[84],Z};function kt(n){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:n},n)}function At(n){return p("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:n.name}),l(Fe,{variant:"outline",children:n.type}),n.unique===!0&&l(Fe,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:n.fields.join(", ")})]},`${n.type}:${n.name}`)}function $t(n){return n.name}export{Qt as SchemaViewer};
1
+ import{c as we}from"react/compiler-runtime";import{ShardInput as Ze}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{S as Ke,T as Pe}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{B as Fe}from"../packem_shared/badge-r_5B4LHP.mjs";import{c as Ge,d as ze,b as Be,a as De,C as je}from"../packem_shared/card-By2O8ULa.mjs";import{E as et}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as ke}from"../packem_shared/input-CXhxesPC.mjs";import{useT as Oe}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{d as Le,g as Ae,b as $e,f as Ce}from"../packem_shared/internal-BT5tH08j.mjs";import{c as Qe}from"../packem_shared/utils-bhneXptQ.mjs";import{useState as _,useRef as Ue,useEffect as qe}from"react";import{u as tt}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{u as lt}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{ADMIN_FUNCTIONS as Me}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{r as st}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{S as at}from"../packem_shared/schema-diagram-Dbs7-jSJ.mjs";import{useNavigate as nt}from"@tanstack/react-router";import{B as ye}from"../packem_shared/button-q0UYSmrn.mjs";import{L as Ee}from"../packem_shared/label-DKFzyHq6.mjs";import{jsx as l,jsxs as p,Fragment as Ve}from"react/jsx-runtime";const ot=Le(Me.listTables),it=Le(Me.listTableIndexes),rt=Le(Me.readTablePage),dt=Le(Me.describeTables),ct={},Ye=[],mt=n=>{const e=we(74),{initialShardKey:m,initialTable:a}=n,t=lt(),[s,c]=_("graph"),{queryShardKey:d,setShardKey:r,shardKey:g}=tt(m),[o,u]=_(""),[i,v]=_(null),[f,O]=_(null);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S={},e[0]=S):S=e[0];const[G,y]=_(S);let L;e[1]===Symbol.for("react.memo_cache_sentinel")?(L={},e[1]=L):L=e[1];const[$,z]=_(L),[T,C]=_(null);let A;e[2]===Symbol.for("react.memo_cache_sentinel")?(A={},e[2]=A):A=e[2];const[F,pe]=_(A);let te;e[3]===Symbol.for("react.memo_cache_sentinel")?(te={},e[3]=te):te=e[3];const[E,M]=_(te),[w,ge]=_(null),[B,ce]=_(null);let le;e[4]===Symbol.for("react.memo_cache_sentinel")?(le={},e[4]=le):le=e[4];const[J,Ne]=_(le),[W,me]=_(null),be=Ue(0);let D;e[5]!==t?(D=async h=>{be.current=be.current+1;const x=be.current;O(null);try{const N=await t.query(ot,{},Ae(h));if(x!==be.current)return;st(h),v(N),y({}),z({}),C(null),pe(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h}))),M(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h})))}catch(N){const k=N;if(x!==be.current)return;v(null),O($e(k))}},e[5]=t,e[6]=D):D=e[6];const j=D;let se;e[7]!==t?(se=async()=>{ce(null);try{ge(await t.listGlobalTables())}catch(h){const x=h;ge(null),ce($e(x))}},e[7]=t,e[8]=se):se=e[8];const ue=se;let R,ae;e[9]!==d||e[10]!==j||e[11]!==ue?(R=()=>{Ce(j(d)),Ce(ue())},ae=[j,ue,d],e[9]=d,e[10]=j,e[11]=ue,e[12]=R,e[13]=ae):(R=e[12],ae=e[13]),qe(R,ae);let K;e[14]!==t||e[15]!==G||e[16]!==T||e[17]!==d?(K=async h=>{if(T===h){C(null);return}C(h);const x=`${d}:${h}`;if(G[x]!==void 0)return;const[N,k]=await Promise.allSettled([t.query(rt,{limit:1,offset:0,table:h},Ae(d)),t.query(it,{table:h},Ae(d))]);N.status==="fulfilled"?y(I=>({...I,[x]:N.value.columns})):O($e(N.reason)),k.status==="fulfilled"&&z(I=>({...I,[x]:k.value.indexes}))},e[14]=t,e[15]=G,e[16]=T,e[17]=d,e[18]=K):K=e[18];const ne=K;let oe;e[19]!==t||e[20]!==J||e[21]!==W?(oe=async h=>{if(W===h){me(null);return}if(me(h),J[h]===void 0)try{const x=await t.readGlobalTablePage({limit:1,offset:0,table:h});Ne(N=>({...N,[h]:x.columns}))}catch(x){ce($e(x))}},e[19]=t,e[20]=J,e[21]=W,e[22]=oe):oe=e[22];const fe=oe,X=Ue(void 0);let Q,U;e[23]!==a||e[24]!==i||e[25]!==ne?(Q=()=>{a===void 0||i===null||X.current===a||i.some(h=>h.name===a)&&(X.current=a,Ce(ne(a)))},U=[a,i,ne],e[23]=a,e[24]=i,e[25]=ne,e[26]=Q,e[27]=U):(Q=e[26],U=e[27]),qe(Q,U);let ie;e[28]!==t?(ie=async(h,x,N)=>{const[k,I]=await Promise.all([Promise.allSettled([t.query(dt,{tables:[...x,...N]},Ae(h))]),Promise.all(N.map(async H=>{const Se=await Promise.allSettled([t.readGlobalTablePage({limit:1,offset:0,table:H})]),Re=Se[0].status==="fulfilled"?Se[0].value:void 0;return{columns:Re?.columns??[],refs:Re?.refs??{},table:H}}))]),he=k[0].status==="fulfilled"?k[0].value?.columnsByTable??{}:{},_e=k[0].status==="rejected",Ie=new Map(I.map(ut)),q=[...x,...N].map(H=>{const Se=he[H]??[];return[H,Se.length>0?Se:Ie.get(H)??[]]});pe(H=>({...H,[h]:Object.fromEntries(q)})),M(H=>({...H,[h]:_e}))},e[28]=t,e[29]=ie):ie=e[29];const V=ie;let re,Y;e[30]!==B||e[31]!==w||e[32]!==V||e[33]!==d||e[34]!==F||e[35]!==i||e[36]!==s?(re=()=>{s!=="graph"||i===null||w===null&&B===null||F[d]!==void 0||Ce(V(d,i.map(ft),(w??[]).map(ht)))},Y=[s,i,w,B,d,F,V],e[30]=B,e[31]=w,e[32]=V,e[33]=d,e[34]=F,e[35]=i,e[36]=s,e[37]=re,e[38]=Y):(re=e[37],Y=e[38]),qe(re,Y);const P=F[d]??ct;let Z;if(e[39]!==P||e[40]!==w||e[41]!==i){let h;e[43]!==P?(h=I=>({columns:P[I.name]??Ye,name:I.name,tier:"shard"}),e[43]=P,e[44]=h):h=e[44];const x=(i??[]).map(h);let N;e[45]!==P?(N=I=>({columns:P[I.name]??Ye,name:I.name,tier:"global"}),e[45]=P,e[46]=N):N=e[46];const k=(w??[]).map(N);Z=[...x,...k],e[39]=P,e[40]=w,e[41]=i,e[42]=Z}else Z=e[42];const b=Z;let ee;if(e[47]!==o||e[48]!==i){const h=o.trim().toLowerCase();ee=(i??[]).filter(x=>x.name.toLowerCase().includes(h)),e[47]=o,e[48]=i,e[49]=ee}else ee=e[49];const de=ee;let xe;if(e[50]!==w||e[51]!==o){const h=o.trim().toLowerCase();xe=(w??[]).filter(x=>x.name.toLowerCase().includes(h)),e[50]=w,e[51]=o,e[52]=xe}else xe=e[52];const Te=xe;let ve;return e[53]!==G||e[54]!==b||e[55]!==f||e[56]!==T||e[57]!==Te||e[58]!==de||e[59]!==J||e[60]!==B||e[61]!==W||e[62]!==w||e[63]!==$||e[64]!==j||e[65]!==r||e[66]!==E||e[67]!==g||e[68]!==o||e[69]!==i||e[70]!==ne||e[71]!==fe||e[72]!==s?(ve={columns:G,diagramTables:b,error:f,expanded:T,filteredGlobalTables:Te,filteredTables:de,globalColumns:J,globalError:B,globalExpanded:W,globalTables:w,indexes:$,refresh:j,setShardKey:r,setTableFilter:u,setView:c,shardColumnsError:E,shardKey:g,tableFilter:o,tables:i,toggle:ne,toggleGlobal:fe,view:s},e[53]=G,e[54]=b,e[55]=f,e[56]=T,e[57]=Te,e[58]=de,e[59]=J,e[60]=B,e[61]=W,e[62]=w,e[63]=$,e[64]=j,e[65]=r,e[66]=E,e[67]=g,e[68]=o,e[69]=i,e[70]=ne,e[71]=fe,e[72]=s,e[73]=ve):ve=e[73],ve};function ut(n){const{columns:e,refs:m,table:a}=n;return[a,e.map(t=>{const s=m[t];return s===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:s,type:"id"}})]}function ft(n){return n.name}function ht(n){return n.name}const pt="/__lunora/schema-edit",gt=async n=>{const e=await fetch(pt,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"},method:"POST"}),m=await e.json();return m.needsMigration===!0?{kind:"needs-migration",message:m.message??"This edit needs a migration."}:e.ok&&m.tables!==void 0?{diagnostics:m.diagnostics??[],kind:"ok",tables:m.tables}:{kind:"error",message:m.error??`schema edit failed (${String(e.status)})`}},bt=n=>{const e=we(32),{hasTables:m,mode:a,onAddColumn:t,onAddIndex:s,onAddTable:c,onDestructive:d}=n,r=Oe(),g=a==="addTable"?"default":"outline";let o;e[0]!==r?(o=r("Add table"),e[0]=r,e[1]=o):o=e[1];let u;e[2]!==c||e[3]!==g||e[4]!==o?(u=l(ye,{"data-testid":"sc-editor-add-table",onClick:c,size:"xs",type:"button",variant:g,children:o}),e[2]=c,e[3]=g,e[4]=o,e[5]=u):u=e[5];const i=!m,v=a==="addColumn"?"default":"outline";let f;e[6]!==r?(f=r("Add column"),e[6]=r,e[7]=f):f=e[7];let O;e[8]!==t||e[9]!==i||e[10]!==v||e[11]!==f?(O=l(ye,{"data-testid":"sc-editor-add-column",disabled:i,onClick:t,size:"xs",type:"button",variant:v,children:f}),e[8]=t,e[9]=i,e[10]=v,e[11]=f,e[12]=O):O=e[12];const S=!m,G=a==="addIndex"?"default":"outline";let y;e[13]!==r?(y=r("Add index"),e[13]=r,e[14]=y):y=e[14];let L;e[15]!==s||e[16]!==y||e[17]!==S||e[18]!==G?(L=l(ye,{"data-testid":"sc-editor-add-index",disabled:S,onClick:s,size:"xs",type:"button",variant:G,children:y}),e[15]=s,e[16]=y,e[17]=S,e[18]=G,e[19]=L):L=e[19];const $=!m,z=a==="destructive"?"default":"ghost";let T;e[20]!==r?(T=r("Rename / drop / change type…"),e[20]=r,e[21]=T):T=e[21];let C;e[22]!==d||e[23]!==$||e[24]!==z||e[25]!==T?(C=l(ye,{"data-testid":"sc-editor-destructive",disabled:$,onClick:d,size:"xs",type:"button",variant:z,children:T}),e[22]=d,e[23]=$,e[24]=z,e[25]=T,e[26]=C):C=e[26];let A;return e[27]!==L||e[28]!==C||e[29]!==u||e[30]!==O?(A=p("div",{className:"flex flex-wrap gap-2",children:[u,O,L,C]}),e[27]=L,e[28]=C,e[29]=u,e[30]=O,e[31]=A):A=e[31],A},xt=n=>{const e=we(28),{onOpenMigrations:m,result:a}=n,t=Oe();if(a===null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[0]=o):o=e[0],o}if(a.kind==="error"){let o;return e[1]!==a.message?(o=l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:a.message}),e[1]=a.message,e[2]=o):o=e[2],o}if(a.kind==="needs-migration"){let o;e[3]!==a.message||e[4]!==t?(o=a.message===""?t("This edit changes stored data and must go through a migration. Review the migration before applying."):a.message,e[3]=a.message,e[4]=t,e[5]=o):o=e[5];let u;e[6]!==o?(u=l("p",{className:"text-sm text-warning",role:"alert",children:o}),e[6]=o,e[7]=u):u=e[7];let i;e[8]!==t?(i=t("Open Migrations"),e[8]=t,e[9]=i):i=e[9];let v;e[10]!==m||e[11]!==i?(v=l(ye,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:m,size:"xs",type:"button",variant:"outline",children:i}),e[10]=m,e[11]=i,e[12]=v):v=e[12];let f;return e[13]!==u||e[14]!==v?(f=p("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[u,v]}),e[13]=u,e[14]=v,e[15]=f):f=e[15],f}if(a.diagnostics.length===0){let o;return e[16]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[16]=o):o=e[16],o}let s;e[17]!==t?(s=t("Codegen reported diagnostics:"),e[17]=t,e[18]=s):s=e[18];let c;e[19]!==s?(c=l("p",{className:"text-sm text-destructive",role:"alert",children:s}),e[19]=s,e[20]=c):c=e[20];let d;e[21]!==a.diagnostics?(d=a.diagnostics.map(vt),e[21]=a.diagnostics,e[22]=d):d=e[22];let r;e[23]!==d?(r=l("ul",{className:"flex flex-col gap-0.5",children:d}),e[23]=d,e[24]=r):r=e[24];let g;return e[25]!==c||e[26]!==r?(g=p("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[c,r]}),e[25]=c,e[26]=r,e[27]=g):g=e[27],g};function vt(n){return l("li",{className:"font-mono text-[11px] text-destructive",children:n},n)}const yt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.bigint()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],Ct="v.string()",Nt=n=>n.split(",").map(e=>e.trim()).filter(e=>e!==""),Tt=n=>{const e=we(83),{onApplied:m,tableNames:a}=n,t=Oe(),s=nt(),[c,d]=_(null),[r,g]=_(!1),[o,u]=_(null),[i,v]=_(""),[f,O]=_(""),[S,G]=_(Ct),[y,L]=_(a[0]??""),[$,z]=_(""),[T,C]=_(""),[A,F]=_(!1);let pe;e[0]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>{d(null),v(""),O(""),z(""),C(""),F(!1)},e[0]=pe):pe=e[0];const te=pe;let E;e[1]!==m?(E=async q=>{g(!0),u(null);try{const H=await gt(q);u(H),H.kind==="ok"&&(m(H.tables),te())}catch(H){const Se=H;u({kind:"error",message:Se instanceof Error?Se.message:String(Se)})}g(!1)},e[1]=m,e[2]=E):E=e[2];const M=E;let w;e[3]!==M||e[4]!==i?(w=()=>{Ce(M({kind:"addTable",table:i.trim()}))},e[3]=M,e[4]=i,e[5]=w):w=e[5];const ge=w;let B;e[6]!==f||e[7]!==M||e[8]!==y||e[9]!==S?(B=()=>{Ce(M({column:f.trim(),kind:"addOptionalColumn",table:y,validator:S}))},e[6]=f,e[7]=M,e[8]=y,e[9]=S,e[10]=B):B=e[10];const ce=B;let le;e[11]!==T||e[12]!==$||e[13]!==M||e[14]!==y||e[15]!==A?(le=()=>{Ce(M({fields:Nt(T),kind:"addIndex",name:$.trim(),table:y,unique:A}))},e[11]=T,e[12]=$,e[13]=M,e[14]=y,e[15]=A,e[16]=le):le=e[16];const J=le;let Ne;e[17]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>{u(null),d("addTable")},e[17]=Ne):Ne=e[17];const W=Ne;let me;e[18]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{u(null),d("addColumn")},e[18]=me):me=e[18];const be=me;let D;e[19]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{u(null),d("addIndex")},e[19]=D):D=e[19];const j=D;let se;e[20]!==t?(se=()=>{d("destructive"),u({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=se):se=e[21];const ue=se;let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=q=>{v(q.target.value)},e[22]=R):R=e[22];const ae=R;let K;e[23]===Symbol.for("react.memo_cache_sentinel")?(K=q=>{O(q.target.value)},e[23]=K):K=e[23];const ne=K;let oe;e[24]===Symbol.for("react.memo_cache_sentinel")?(oe=q=>{G(q.target.value)},e[24]=oe):oe=e[24];const fe=oe;let X;e[25]===Symbol.for("react.memo_cache_sentinel")?(X=q=>{L(q.target.value)},e[25]=X):X=e[25];const Q=X;let U;e[26]===Symbol.for("react.memo_cache_sentinel")?(U=q=>{z(q.target.value)},e[26]=U):U=e[26];const ie=U;let V;e[27]===Symbol.for("react.memo_cache_sentinel")?(V=q=>{C(q.target.value)},e[27]=V):V=e[27];const re=V;let Y;e[28]===Symbol.for("react.memo_cache_sentinel")?(Y=q=>{F(q.target.checked)},e[28]=Y):Y=e[28];const P=Y;let Z;e[29]!==s?(Z=()=>{Ce(s({to:"/migrations"}))},e[29]=s,e[30]=Z):Z=e[30];const b=Z;let ee;e[31]!==t?(ee=t("Edit schema"),e[31]=t,e[32]=ee):ee=e[32];let de;e[33]!==ee?(de=l(Ge,{children:ee}),e[33]=ee,e[34]=de):de=e[34];let xe;e[35]!==t?(xe=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=xe):xe=e[36];let Te;e[37]!==xe?(Te=l(ze,{children:xe}),e[37]=xe,e[38]=Te):Te=e[38];let ve;e[39]!==de||e[40]!==Te?(ve=p(Be,{children:[de,Te]}),e[39]=de,e[40]=Te,e[41]=ve):ve=e[41];const h=a.length>0;let x;e[42]!==c||e[43]!==ue||e[44]!==h?(x=l(bt,{hasTables:h,mode:c,onAddColumn:be,onAddIndex:j,onAddTable:W,onDestructive:ue}),e[42]=c,e[43]=ue,e[44]=h,e[45]=x):x=e[45];let N;e[46]!==r||e[47]!==c||e[48]!==ge||e[49]!==t||e[50]!==i?(N=c==="addTable"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(ke,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:ae,value:i})]}),l(ye,{"data-testid":"sc-editor-table-apply",disabled:r||i.trim()==="",onClick:ge,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[46]=r,e[47]=c,e[48]=ge,e[49]=t,e[50]=i,e[51]=N):N=e[51];let k;e[52]!==r||e[53]!==f||e[54]!==c||e[55]!==ce||e[56]!==t||e[57]!==a||e[58]!==y||e[59]!==S?(k=c==="addColumn"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:Q,value:y,children:a.map(St)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(ke,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:ne,value:f})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:fe,value:S,children:yt.map(wt)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(ye,{"data-testid":"sc-editor-column-apply",disabled:r||f.trim()===""||y==="",onClick:ce,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[52]=r,e[53]=f,e[54]=c,e[55]=ce,e[56]=t,e[57]=a,e[58]=y,e[59]=S,e[60]=k):k=e[60];let I;e[61]!==r||e[62]!==T||e[63]!==$||e[64]!==c||e[65]!==J||e[66]!==t||e[67]!==a||e[68]!==y||e[69]!==A?(I=c==="addIndex"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:Q,value:y,children:a.map(_t)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(ke,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:ie,value:$})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(ke,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:re,value:T})]}),p(Ee,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:A,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:P,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(ye,{"data-testid":"sc-editor-index-apply",disabled:r||$.trim()===""||T.trim()==="",onClick:J,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[61]=r,e[62]=T,e[63]=$,e[64]=c,e[65]=J,e[66]=t,e[67]=a,e[68]=y,e[69]=A,e[70]=I):I=e[70];let he;e[71]!==b||e[72]!==o?(he=l(xt,{onOpenMigrations:b,result:o}),e[71]=b,e[72]=o,e[73]=he):he=e[73];let _e;e[74]!==x||e[75]!==N||e[76]!==k||e[77]!==I||e[78]!==he?(_e=p(De,{children:[x,N,k,I,he]}),e[74]=x,e[75]=N,e[76]=k,e[77]=I,e[78]=he,e[79]=_e):_e=e[79];let Ie;return e[80]!==ve||e[81]!==_e?(Ie=p(je,{"data-testid":"sc-editor",size:"sm",children:[ve,_e]}),e[80]=ve,e[81]=_e,e[82]=Ie):Ie=e[82],Ie};function St(n){return l("option",{value:n,children:n},n)}function wt(n){return l("option",{value:n.validator,children:n.label},n.validator)}function _t(n){return l("option",{value:n,children:n},n)}const He=[],Et=n=>{const e=we(5),{open:m}=n,a=m&&"rotate-90";let t;e[0]!==a?(t=Qe("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",a),e[0]=a,e[1]=t):t=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=l("path",{d:"m9 6 6 6-6 6"}),e[2]=s):s=e[2];let c;return e[3]!==t?(c=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:s}),e[3]=t,e[4]=c):c=e[4],c},Je=n=>{const e=we(20),{children:m,expanded:a,name:t,onToggle:s,rowCount:c,rowTestId:d,toggleTestId:r}=n;let g;e[0]!==a?(g=l(Et,{open:a}),e[0]=a,e[1]=g):g=e[1];let o;e[2]!==t?(o=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=o):o=e[3];let u;e[4]!==c?(u=p("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",c,")"]}),e[4]=c,e[5]=u):u=e[5];let i;e[6]!==a||e[7]!==s||e[8]!==g||e[9]!==o||e[10]!==u||e[11]!==r?(i=p("button",{"aria-expanded":a,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":r,onClick:s,type:"button",children:[g,o," ",u]}),e[6]=a,e[7]=s,e[8]=g,e[9]=o,e[10]=u,e[11]=r,e[12]=i):i=e[12];let v;e[13]!==m||e[14]!==a?(v=a&&l("div",{className:"px-3 pb-3 ps-8",children:m}),e[13]=m,e[14]=a,e[15]=v):v=e[15];let f;return e[16]!==d||e[17]!==i||e[18]!==v?(f=p("li",{className:"border-t border-border/60 first:border-t-0","data-testid":d,children:[i,v]}),e[16]=d,e[17]=i,e[18]=v,e[19]=f):f=e[19],f},We=n=>{const e=we(5),{columns:m,testId:a}=n;let t;e[0]!==m?(t=m.map(kt),e[0]=m,e[1]=t):t=e[1];let s;return e[2]!==t||e[3]!==a?(s=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":a,children:t}),e[2]=t,e[3]=a,e[4]=s):s=e[4],s},It=n=>{const e=we(10),{heading:m,indexes:a,testId:t}=n;let s;e[0]!==m?(s=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:m}),e[0]=m,e[1]=s):s=e[1];let c;e[2]!==a?(c=a.map(At),e[2]=a,e[3]=c):c=e[3];let d;e[4]!==c||e[5]!==t?(d=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:c}),e[4]=c,e[5]=t,e[6]=d):d=e[6];let r;return e[7]!==s||e[8]!==d?(r=p("div",{className:"pt-3",children:[s,d]}),e[7]=s,e[8]=d,e[9]=r):r=e[9],r},Xe=n=>Qe("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",n?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Qt=n=>{const e=we(85),{initialShardKey:m,initialTable:a,schemaEditable:t}=n,s=Oe();let c;e[0]!==m||e[1]!==a?(c={initialShardKey:m,initialTable:a},e[0]=m,e[1]=a,e[2]=c):c=e[2];const{columns:d,diagramTables:r,error:g,expanded:o,filteredGlobalTables:u,filteredTables:i,globalColumns:v,globalError:f,globalExpanded:O,globalTables:S,indexes:G,refresh:y,setShardKey:L,setTableFilter:$,setView:z,shardColumnsError:T,shardKey:C,tableFilter:A,tables:F,toggle:pe,toggleGlobal:te,view:E}=mt(c);let M;e[3]!==z?(M=()=>{z("list")},e[3]=z,e[4]=M):M=e[4];const w=M;let ge;e[5]!==z?(ge=()=>{z("graph")},e[5]=z,e[6]=ge):ge=e[6];const B=ge;let ce;e[7]!==$?(ce=b=>{$(b.target.value)},e[7]=$,e[8]=ce):ce=e[8];const le=ce;let J;e[9]!==y||e[10]!==C?(J=b=>{Ce(y(C))},e[9]=y,e[10]=C,e[11]=J):J=e[11];const Ne=J;let W;e[12]!==F?(W=F??[],e[12]=F,e[13]=W):W=e[13];let me;e[14]!==W?(me=W.map($t),e[14]=W,e[15]=me):me=e[15];const be=me;let D;e[16]!==L||e[17]!==C?(D=l(Ze,{onChange:L,testId:"sc-shard-input",value:C}),e[16]=L,e[17]=C,e[18]=D):D=e[18];let j;e[19]!==s?(j=s("Schema view"),e[19]=s,e[20]=j):j=e[20];const se=E==="graph",ue=E==="graph";let R;e[21]!==ue?(R=Xe(ue),e[21]=ue,e[22]=R):R=e[22];let ae;e[23]!==s?(ae=s("Graph"),e[23]=s,e[24]=ae):ae=e[24];let K;e[25]!==B||e[26]!==se||e[27]!==R||e[28]!==ae?(K=l("button",{"aria-selected":se,className:R,"data-testid":"sc-view-graph",onClick:B,role:"tab",type:"button",children:ae}),e[25]=B,e[26]=se,e[27]=R,e[28]=ae,e[29]=K):K=e[29];const ne=E==="list",oe=E==="list";let fe;e[30]!==oe?(fe=Xe(oe),e[30]=oe,e[31]=fe):fe=e[31];let X;e[32]!==s?(X=s("Table list"),e[32]=s,e[33]=X):X=e[33];let Q;e[34]!==w||e[35]!==ne||e[36]!==fe||e[37]!==X?(Q=l("button",{"aria-selected":ne,className:fe,"data-testid":"sc-view-list",onClick:w,role:"tab",type:"button",children:X}),e[34]=w,e[35]=ne,e[36]=fe,e[37]=X,e[38]=Q):Q=e[38];let U;e[39]!==K||e[40]!==Q||e[41]!==j?(U=p("div",{"aria-label":j,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[K,Q]}),e[39]=K,e[40]=Q,e[41]=j,e[42]=U):U=e[42];let ie;e[43]!==U||e[44]!==D?(ie=p("div",{className:"flex flex-wrap items-center gap-3",children:[D,U]}),e[43]=U,e[44]=D,e[45]=ie):ie=e[45];let V;e[46]!==Ne||e[47]!==t||e[48]!==be?(V=t===!0&&l(Tt,{onApplied:Ne,tableNames:be}),e[46]=Ne,e[47]=t,e[48]=be,e[49]=V):V=e[49];let re;e[50]!==le||e[51]!==s||e[52]!==A||e[53]!==E?(re=E==="list"&&l(ke,{"aria-label":s("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:le,placeholder:s("Filter tables"),value:A}),e[50]=le,e[51]=s,e[52]=A,e[53]=E,e[54]=re):re=e[54];let Y;e[55]!==r||e[56]!==g||e[57]!==f||e[58]!==T||e[59]!==C||e[60]!==E?(Y=E==="graph"&&p("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),l(at,{columnsError:T[C]===!0,tables:r,testIdPrefix:"sc-graph"})]}),e[55]=r,e[56]=g,e[57]=f,e[58]=T,e[59]=C,e[60]=E,e[61]=Y):Y=e[61];let P;e[62]!==d||e[63]!==g||e[64]!==o||e[65]!==u||e[66]!==i||e[67]!==v||e[68]!==f||e[69]!==O||e[70]!==S||e[71]!==G||e[72]!==C||e[73]!==s||e[74]!==F||e[75]!==pe||e[76]!==te||e[77]!==E?(P=E==="list"&&p("div",{className:"flex flex-col gap-4",children:[p(je,{"data-testid":"sc-shard-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"shard"}),l(Ge,{children:s("Shard tables")}),F!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:i.length})]}),l(ze,{children:Pe.shard.hint})]}),p(De,{children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),F!==null&&F.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:s("No tables in this shard.")}),F!==null&&F.length>0&&i.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:s("No tables match your filter.")}),i.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:i.map(b=>{const ee=`${C}:${b.name}`,de=G[ee]??[];return p(Je,{expanded:o===b.name,name:b.name,onToggle:()=>{Ce(pe(b.name))},rowCount:b.rowCount,rowTestId:`sc-table-${b.name}`,toggleTestId:`sc-toggle-${b.name}`,children:[l(We,{columns:d[ee]??He,testId:`sc-columns-${b.name}`}),de.length>0&&l(It,{heading:s("Indexes"),indexes:de,testId:`sc-indexes-${b.name}`})]},b.name)})})]})]}),p(je,{"data-testid":"sc-global-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"global"}),l(Ge,{children:s("Global tables (D1)")}),S!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:u.length})]}),l(ze,{children:Pe.global.hint})]}),p(De,{children:[f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),S!==null&&S.length===0&&l(et,{description:Pe.global.hint,testId:"sc-global-empty",title:s("No global tables.")}),S!==null&&S.length>0&&u.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:s("No tables match your filter.")}),u.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:u.map(b=>l(Je,{expanded:O===b.name,name:b.name,onToggle:()=>{Ce(te(b.name))},rowCount:b.rowCount,rowTestId:`sc-global-table-${b.name}`,toggleTestId:`sc-global-toggle-${b.name}`,children:l(We,{columns:v[b.name]??He,testId:`sc-global-columns-${b.name}`})},b.name))})]})]})]}),e[62]=d,e[63]=g,e[64]=o,e[65]=u,e[66]=i,e[67]=v,e[68]=f,e[69]=O,e[70]=S,e[71]=G,e[72]=C,e[73]=s,e[74]=F,e[75]=pe,e[76]=te,e[77]=E,e[78]=P):P=e[78];let Z;return e[79]!==ie||e[80]!==V||e[81]!==re||e[82]!==Y||e[83]!==P?(Z=p("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[ie,V,re,Y,P]}),e[79]=ie,e[80]=V,e[81]=re,e[82]=Y,e[83]=P,e[84]=Z):Z=e[84],Z};function kt(n){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:n},n)}function At(n){return p("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:n.name}),l(Fe,{variant:"outline",children:n.type}),n.unique===!0&&l(Fe,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:n.fields.join(", ")})]},`${n.type}:${n.name}`)}function $t(n){return n.name}export{Qt as SchemaViewer};
@@ -1 +1 @@
1
- import{c as u}from"react/compiler-runtime";import{u as h}from"../packem_shared/use-admin-query-CaOm4JS3.mjs";import{useT as m}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as p}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{A as f}from"../packem_shared/advisor-view-gtf_DhUU.mjs";import{jsx as R}from"react/jsx-runtime";const k=(e,s)=>({"admin-token-weak":e("Weak admin token"),"auth-secret-weak":e("Weak auth secret"),"cookies-insecure":e("Session cookies are not Secure"),"cors-wildcard-credentials":e("Wildcard CORS with credentials"),"csrf-disabled":e("CSRF/origin guard is off"),"dev-args-unredacted":e("Request log keeps un-redacted args"),"security-headers-disabled":e("Security headers are off"),"ws-gate-open":e("User subscriptions are ungated")})[s.kind],g=e=>Array.isArray(e.findings)?e.findings:[],S=e=>({"admin-token-weak":"LUNORA_ADMIN_TOKEN","auth-secret-weak":"AUTH_SECRET","cookies-insecure":"BETTER_AUTH_URL","cors-wildcard-credentials":"LUNORA_ALLOWED_ORIGINS","csrf-disabled":"LUNORA_SECURITY_CSRF","dev-args-unredacted":"request log","security-headers-disabled":"LUNORA_SECURITY_HEADERS","ws-gate-open":"LUNORA_WS_BEARER"})[e.kind],A=(e,s)=>({"admin-token-weak":e("Your admin token is {length} characters — use at least {min} for a brute-force-resistant secret.",{length:s.detail?.length,min:s.detail?.min}),"auth-secret-weak":e("Your auth secret is {length} characters — use at least {min} (e.g. `openssl rand -hex 32`) to sign sessions safely.",{length:s.detail?.length,min:s.detail?.min}),"cookies-insecure":e("BETTER_AUTH_URL is a plaintext http:// origin, so session cookies cannot be Secure and ride in cleartext. Serve auth over https:// in production."),"cors-wildcard-credentials":e("LUNORA_ALLOWED_ORIGINS includes a wildcard while credentials are allowed — browsers reject this and it defeats the allowlist. Name explicit origins instead of *."),"csrf-disabled":e("LUNORA_SECURITY_CSRF is off, so cross-origin state-changing cookie requests are not blocked. Re-enable it in production to keep mutations un-forgeable."),"dev-args-unredacted":e("This worker reports a development environment, so the request log stores raw args and identity. Confirm it isn't a mislabeled production deploy."),"security-headers-disabled":e("LUNORA_SECURITY_HEADERS is off, so HSTS, CSP, nosniff, and frame-options are not applied. Re-enable the baseline headers in production."),"ws-gate-open":e("LUNORA_WS_BEARER is unset, so the WebSocket upgrade gate is open: anyone who can reach the worker can open a socket and run ordinary user subscriptions. Admin subscriptions are unaffected — they need the admin token. Set it if subscribers should present a shared credential.")})[s.kind],T=()=>{const e=u(8),s=m();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t={},e[0]=t):t=e[0];const{data:i,error:o,errorSource:d}=h(p.getSecurityAudit,t);let a;if(e[1]!==i||e[2]!==s){const l=i===void 0?null:g(i);a=l===null?null:l.map(r=>({description:A(s,r),entity:S(r),issueType:k(s,r),key:r.kind,level:r.level})),e[1]=i,e[2]=s,e[3]=a}else a=e[3];const c=a;let n;return e[4]!==o||e[5]!==d||e[6]!==c?(n=R(f,{error:o,errorSource:d,rows:c,testId:"lunora-security-advisor"}),e[4]=o,e[5]=d,e[6]=c,e[7]=n):n=e[7],n};export{T as default};
1
+ import{c as u}from"react/compiler-runtime";import{u as h}from"../packem_shared/use-admin-query-DMnTt_hg.mjs";import{useT as m}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as p}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{A as f}from"../packem_shared/advisor-view-y9c2z5w1.mjs";import{jsx as R}from"react/jsx-runtime";const k=(e,s)=>({"admin-token-weak":e("Weak admin token"),"auth-secret-weak":e("Weak auth secret"),"cookies-insecure":e("Session cookies are not Secure"),"cors-wildcard-credentials":e("Wildcard CORS with credentials"),"csrf-disabled":e("CSRF/origin guard is off"),"dev-args-unredacted":e("Request log keeps un-redacted args"),"security-headers-disabled":e("Security headers are off"),"ws-gate-open":e("User subscriptions are ungated")})[s.kind],g=e=>Array.isArray(e.findings)?e.findings:[],S=e=>({"admin-token-weak":"LUNORA_ADMIN_TOKEN","auth-secret-weak":"AUTH_SECRET","cookies-insecure":"BETTER_AUTH_URL","cors-wildcard-credentials":"LUNORA_ALLOWED_ORIGINS","csrf-disabled":"LUNORA_SECURITY_CSRF","dev-args-unredacted":"request log","security-headers-disabled":"LUNORA_SECURITY_HEADERS","ws-gate-open":"LUNORA_WS_BEARER"})[e.kind],A=(e,s)=>({"admin-token-weak":e("Your admin token is {length} characters — use at least {min} for a brute-force-resistant secret.",{length:s.detail?.length,min:s.detail?.min}),"auth-secret-weak":e("Your auth secret is {length} characters — use at least {min} (e.g. `openssl rand -hex 32`) to sign sessions safely.",{length:s.detail?.length,min:s.detail?.min}),"cookies-insecure":e("BETTER_AUTH_URL is a plaintext http:// origin, so session cookies cannot be Secure and ride in cleartext. Serve auth over https:// in production."),"cors-wildcard-credentials":e("LUNORA_ALLOWED_ORIGINS includes a wildcard while credentials are allowed — browsers reject this and it defeats the allowlist. Name explicit origins instead of *."),"csrf-disabled":e("LUNORA_SECURITY_CSRF is off, so cross-origin state-changing cookie requests are not blocked. Re-enable it in production to keep mutations un-forgeable."),"dev-args-unredacted":e("This worker reports a development environment, so the request log stores raw args and identity. Confirm it isn't a mislabeled production deploy."),"security-headers-disabled":e("LUNORA_SECURITY_HEADERS is off, so HSTS, CSP, nosniff, and frame-options are not applied. Re-enable the baseline headers in production."),"ws-gate-open":e("LUNORA_WS_BEARER is unset, so the WebSocket upgrade gate is open: anyone who can reach the worker can open a socket and run ordinary user subscriptions. Admin subscriptions are unaffected — they need the admin token. Set it if subscribers should present a shared credential.")})[s.kind],T=()=>{const e=u(8),s=m();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t={},e[0]=t):t=e[0];const{data:i,error:o,errorSource:d}=h(p.getSecurityAudit,t);let a;if(e[1]!==i||e[2]!==s){const l=i===void 0?null:g(i);a=l===null?null:l.map(r=>({description:A(s,r),entity:S(r),issueType:k(s,r),key:r.kind,level:r.level})),e[1]=i,e[2]=s,e[3]=a}else a=e[3];const c=a;let n;return e[4]!==o||e[5]!==d||e[6]!==c?(n=R(f,{error:o,errorSource:d,rows:c,testId:"lunora-security-advisor"}),e[4]=o,e[5]=d,e[6]=c,e[7]=n):n=e[7],n};export{T as default};
@@ -1 +1 @@
1
- import{c as fe}from"react/compiler-runtime";import{E as De}from"../packem_shared/error-alert-3AR_-s_s.mjs";import{B as Te}from"../packem_shared/badge-r_5B4LHP.mjs";import{a as oe,C as ie}from"../packem_shared/card-By2O8ULa.mjs";import{T as Se,a as Ce,b as me,c as Y,d as Ae,e as Q}from"../packem_shared/table-D0SBiDu-.mjs";import{u as Ee}from"../packem_shared/use-admin-query-CaOm4JS3.mjs";import{useT as be}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as Re}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{b as Ie}from"../packem_shared/cf-links-BPy1pJRO.mjs";import{r as Le,u as Oe,s as Ue}from"../packem_shared/shortcuts-B9gDaXmw.mjs";import{useState as ae,useRef as Ne,useEffect as ye}from"react";import{ConfirmButton as Ke}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{B as ve}from"../packem_shared/button-q0UYSmrn.mjs";import{I as _e}from"../packem_shared/input-CXhxesPC.mjs";import{u as $e}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{h as pe,f as xe,b as ge}from"../packem_shared/internal-hIuTpSbx.mjs";import{jsxs as d,jsx as s}from"react/jsx-runtime";const ke=["disabled","schema","schema_and_log","schema_and_log_and_data"],je={describeTables:"schema",readAdvisors:"schema",readLogs:"schema_and_log",readPolicies:"schema",runSql:"schema_and_log_and_data"},Be=864e5,Fe=()=>{const t=fe(67),e=$e(),l=be();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],t[0]=n):n=t[0];let b;t[1]!==e?(b={owner:e,tokens:n},t[1]=e,t[2]=b):b=t[2];const[p,N]=ae(b),g=p.owner===e?p.tokens:[],[m,f]=ae(null),[h,o]=ae(null);h!==null&&h.owner!==e&&o(null);const i=h?.owner===e?h.token:null,[r,c]=ae(""),[a,u]=ae(""),[w,_]=ae(null),R=w===e,v=Ne(0),k=Ne(e);let D,I;t[3]!==e?(D=()=>{k.current=e},I=[e],t[3]=e,t[4]=D,t[5]=I):(D=t[4],I=t[5]),ye(D,I);let L;t[6]!==e?(L=async()=>{if(k.current!==e)return;v.current=v.current+1;const x=v.current;try{const E=await e.listAdminTokens();x===v.current&&(N({owner:e,tokens:E}),f(null))}catch(E){const re=E;x===v.current&&f(ge(re))}},t[6]=e,t[7]=L):L=t[7];const y=L;let O,U;t[8]!==y?(O=()=>{xe(y())},U=[y],t[8]=y,t[9]=O,t[10]=U):(O=t[9],U=t[10]),ye(O,U);let K;t[11]!==e||t[12]!==i||t[13]!==R||t[14]!==a||t[15]!==r||t[16]!==y?(K=x=>{if(x.preventDefault(),R||i!==null)return;_(e);const E=e,re=a===""?void 0:Date.now()+Number(a)*Be;xe((async()=>{try{const le=await E.createAdminToken({expiresAt:re,name:r.trim()});k.current===E&&(o({owner:E,token:le}),c(""),u(""),await y())}catch(le){f(ge(le))}_(le=>le===E?null:le)})())},t[11]=e,t[12]=i,t[13]=R,t[14]=a,t[15]=r,t[16]=y,t[17]=K):K=t[17];const F=K,q=x=>{xe((async()=>{try{await e.revokeAdminToken(x),o(E=>E?.token.name===x?null:E),await y()}catch(E){const re=E;await y(),k.current===e&&f(ge(re))}})())},M=ie,z="py-0",H="set-admin-tokens";let T;t[18]!==l?(T=l("Admin tokens"),t[18]=l,t[19]=T):T=t[19];let S;t[20]!==T?(S=s("header",{className:"border-b border-border px-4 py-3",children:s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:T})}),t[20]=T,t[21]=S):S=t[21];const P=oe,W="flex flex-col gap-3 py-3";let C;t[22]!==l?(C=l("Named tokens use the admin API but cannot manage tokens or open admin WebSockets. A revoked token is refused within 30 seconds."),t[22]=l,t[23]=C):C=t[23];let $;t[24]!==C?($=s("p",{className:"text-xs text-muted-foreground",children:C}),t[24]=C,t[25]=$):$=t[25];let V;t[26]!==m?(V=m!==null&&s("p",{className:"text-sm text-destructive","data-testid":"set-admin-tokens-error",role:"alert",children:m}),t[26]=m,t[27]=V):V=t[27];let j;t[28]!==i||t[29]!==l?(j=i!==null&&d("div",{className:"rounded-md border border-border p-3 text-xs","data-testid":"set-admin-token-created",role:"status",children:[s("p",{className:"pb-1 text-muted-foreground",children:l("Copy this token now. It is not shown again.")}),s("code",{className:"font-mono break-all select-all",children:i.token}),s("div",{className:"pt-2",children:s(ve,{"data-testid":"set-admin-token-dismiss",onClick:()=>{o(null)},size:"xs",variant:"outline",children:l("Dismiss")})})]}),t[28]=i,t[29]=l,t[30]=j):j=t[30];let A;t[31]!==l?(A=l("Token name"),t[31]=l,t[32]=A):A=t[32];let B;t[33]===Symbol.for("react.memo_cache_sentinel")?(B=x=>{c(x.target.value)},t[33]=B):B=t[33];let G;t[34]!==r||t[35]!==A?(G=s(_e,{"aria-label":A,className:"w-48","data-testid":"set-admin-token-name",onChange:B,pattern:"[a-z0-9][a-z0-9_\\-]{0,63}",placeholder:"ci-deploy",required:!0,value:r}),t[34]=r,t[35]=A,t[36]=G):G=t[36];let J;t[37]!==l?(J=l("Expires in days (optional)"),t[37]=l,t[38]=J):J=t[38];let de;t[39]===Symbol.for("react.memo_cache_sentinel")?(de=x=>{u(x.target.value)},t[39]=de):de=t[39];let X;t[40]!==l?(X=l("Expires in days (optional)"),t[40]=l,t[41]=X):X=t[41];let Z;t[42]!==a||t[43]!==J||t[44]!==X?(Z=s(_e,{"aria-label":J,className:"w-40",min:1,onChange:de,placeholder:X,type:"number",value:a}),t[42]=a,t[43]=J,t[44]=X,t[45]=Z):Z=t[45];const ue=R||i!==null;let ee;t[46]!==l?(ee=l("Create token"),t[46]=l,t[47]=ee):ee=t[47];let te;t[48]!==ue||t[49]!==ee?(te=s(ve,{"data-testid":"set-admin-token-create",disabled:ue,size:"sm",type:"submit",children:ee}),t[48]=ue,t[49]=ee,t[50]=te):te=t[50];let se;t[51]!==F||t[52]!==G||t[53]!==Z||t[54]!==te?(se=d("form",{className:"flex flex-wrap items-end gap-2",onSubmit:F,children:[G,Z,te]}),t[51]=F,t[52]=G,t[53]=Z,t[54]=te,t[55]=se):se=t[55];const he=g.length>0&&d(Se,{"data-testid":"set-admin-tokens-table",children:[s(Ce,{children:d(me,{children:[s(Y,{children:l("name")}),s(Y,{children:l("Created")}),s(Y,{children:l("Last used")}),s(Y,{children:l("Expires")}),s(Y,{})]})}),s(Ae,{children:g.map(x=>d(me,{"data-testid":"set-admin-token-row",children:[d(Q,{className:"font-mono text-xs",children:[x.name,x.revoked===!0&&s("span",{className:"pl-2 text-destructive",children:l("Revoked")})]}),s(Q,{className:"text-xs",children:pe(x.createdAt)}),s(Q,{className:"text-xs",children:pe(x.lastUsedAt,"—")}),s(Q,{className:"text-xs",children:pe(x.expiresAt,l("Never"))}),s(Q,{children:s(Ke,{onConfirm:()=>{q(x.name)},testId:`set-admin-token-revoke-${x.name}`,children:l("Revoke")})})]},x.name))})]});let ne;t[56]!==P||t[57]!==$||t[58]!==V||t[59]!==j||t[60]!==se||t[61]!==he?(ne=d(P,{className:W,children:[$,V,j,se,he]}),t[56]=P,t[57]=$,t[58]=V,t[59]=j,t[60]=se,t[61]=he,t[62]=ne):ne=t[62];let ce;return t[63]!==M||t[64]!==S||t[65]!==ne?(ce=d(M,{className:z,"data-testid":H,children:[S,ne]}),t[63]=M,t[64]=S,t[65]=ne,t[66]=ce):ce=t[66],ce},Me={binding:"outline",secret:"destructive",var:"secondary"},Pe=(t,e)=>{if(t===void 0)return[];const l=[];return t.workerUrl!==void 0&&l.push({label:e("URL"),value:t.workerUrl}),t.environment!==void 0&&l.push({label:e("Environment"),value:t.environment}),t.deploymentId!==void 0&&l.push({label:e("Deployment"),value:t.deploymentId}),t.versionTag!==void 0&&l.push({label:e("Version"),value:t.versionTag}),l},Ve={disabled:"The assistant is off. Nothing about this deployment is sent to a model.",schema:"Table and column names.",schema_and_log:"Table and column names, plus recent log lines.",schema_and_log_and_data:"Table and column names, log lines, and rows read with SELECT."},qe=t=>{const e=[];for(const[l,n]of Object.entries(je))n===t&&e.push(l);return e},ze=()=>{const t=fe(29),e=be();let l,n;t[0]===Symbol.for("react.memo_cache_sentinel")?(l={},n={shardKey:""},t[0]=l,t[1]=n):(l=t[0],n=t[1]);const{data:b}=Ee(Re.aiAvailable,l,n),p=b?.level;let N;t[2]!==p?(N=p===void 0?-1:ke.indexOf(p),t[2]=p,t[3]=N):N=t[3];const g=N;let m;t[4]!==e?(m=e("AI assistant data sharing"),t[4]=e,t[5]=m):m=t[5];let f;t[6]!==m?(f=s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m}),t[6]=m,t[7]=f):f=t[7];let h;t[8]!==p?(h=p!==void 0&&s(Te,{"data-testid":"set-ai-level",variant:p==="disabled"?"outline":"secondary",children:p}),t[8]=p,t[9]=h):h=t[9];let o;t[10]!==f||t[11]!==h?(o=d("header",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[f,h]}),t[10]=f,t[11]=h,t[12]=o):o=t[12];let i;t[13]!==g||t[14]!==p||t[15]!==e?(i=ke.map((_,R)=>{const v=g>=R,k=qe(_);return d("li",{className:v?"flex flex-col gap-0.5":"flex flex-col gap-0.5 opacity-50","data-granted":String(v),"data-testid":`set-ai-tier-${_}`,children:[d("span",{className:"flex items-center gap-2",children:[s("span",{className:"font-mono text-xs",children:_}),_===p&&s("span",{className:"text-[11px] text-primary",children:e("current")})]}),s("span",{className:"text-xs text-muted-foreground",children:e(Ve[_])}),k.length>0&&s("span",{className:"font-mono text-[11px] text-muted-foreground",children:k.join(", ")})]},_)}),t[13]=g,t[14]=p,t[15]=e,t[16]=i):i=t[16];let r;t[17]!==i?(r=s("ul",{className:"flex flex-col gap-1.5 text-sm",children:i}),t[17]=i,t[18]=r):r=t[18];let c;t[19]!==e?(c=e("Set LUNORA_AI_OPT_IN in wrangler.jsonc and redeploy to change this. The Studio can read this level but never raise it."),t[19]=e,t[20]=c):c=t[20];let a;t[21]!==c?(a=s("p",{className:"text-xs text-muted-foreground","data-testid":"set-ai-howto",children:c}),t[21]=c,t[22]=a):a=t[22];let u;t[23]!==a||t[24]!==r?(u=d(oe,{className:"flex flex-col gap-3 py-3",children:[r,a]}),t[23]=a,t[24]=r,t[25]=u):u=t[25];let w;return t[26]!==u||t[27]!==o?(w=d(ie,{className:"py-0","data-testid":"set-ai-sharing",children:[o,u]}),t[26]=u,t[27]=o,t[28]=w):w=t[28],w},we=t=>{const e=fe(18),{modifier:l,name:n,label:b}=t,p=Oe();let N;e[0]!==n?(N=u=>{if(!["Escape","Tab"].includes(u.key)){if(u.shiftKey){u.preventDefault();return}u.preventDefault(),Ue(n,u.key)}},e[0]=n,e[1]=N):N=e[1];const g=N,m=`set-shortcut-${n}`;let f;e[2]!==b?(f=s("dt",{className:"text-muted-foreground",children:b}),e[2]=b,e[3]=f):f=e[3];let h;e[4]!==l?(h=s("kbd",{className:"rounded border border-border px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:l}),e[4]=l,e[5]=h):h=e[5];const o=`set-shortcut-input-${n}`,i=p[n];let r;e[6]!==b||e[7]!==g||e[8]!==o||e[9]!==i?(r=s("input",{"aria-label":b,className:"h-7 w-12 rounded-md border border-border bg-background text-center font-mono text-xs uppercase outline-none focus-visible:border-ring","data-testid":o,onKeyDown:g,readOnly:!0,value:i}),e[6]=b,e[7]=g,e[8]=o,e[9]=i,e[10]=r):r=e[10];let c;e[11]!==h||e[12]!==r?(c=d("dd",{className:"flex items-center gap-1.5",children:[h,r]}),e[11]=h,e[12]=r,e[13]=c):c=e[13];let a;return e[14]!==m||e[15]!==f||e[16]!==c?(a=d("div",{className:"contents","data-testid":m,children:[f,c]}),e[14]=m,e[15]=f,e[16]=c,e[17]=a):a=e[17],a},ft=t=>{const e=fe(87),{initialShardKey:l}=t,n=be();let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={},e[0]=b):b=e[0];const p=l??"";let N;e[1]!==p?(N={shardKey:p},e[1]=p,e[2]=N):N=e[2];const{data:g,error:m,errorSource:f,isLoading:h}=Ee(Re.getSettings,b,N);let o,i,r,c,a,u,w;if(e[3]!==m||e[4]!==f||e[5]!==g?.deploy||e[6]!==g?.settings||e[7]!==n){const V=Pe(g?.deploy,n);let j;e[15]!==g?.settings?(j=g?.settings??[],e[15]=g?.settings,e[16]=j):j=e[16],o=j,i="flex flex-col gap-4",r="lunora-settings";let A;e[17]!==n?(A=n("Open in Cloudflare"),e[17]=n,e[18]=A):A=e[18],e[19]!==A?(c=s("div",{className:"flex flex-wrap items-center gap-3",children:s("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"set-cf-link",href:Ie,rel:"noreferrer",target:"_blank",children:A})}),e[19]=A,e[20]=c):c=e[20];let B;e[21]!==n?(B=n("View-only — values are masked. Edit vars, secrets, and bindings in wrangler or the Cloudflare dashboard."),e[21]=n,e[22]=B):B=e[22],e[23]!==B?(a=s("p",{className:"text-sm text-muted-foreground","data-testid":"set-readonly-note",children:B}),e[23]=B,e[24]=a):a=e[24],e[25]!==m||e[26]!==f?(u=m!==null&&s(De,{error:f,testId:"set-error"}),e[25]=m,e[26]=f,e[27]=u):u=e[27],w=V.length>0&&d(ie,{className:"py-0","data-testid":"set-deploy",children:[s("header",{className:"border-b border-border px-4 py-3",children:s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Deployment")})}),s(oe,{className:"py-3",children:s("dl",{className:"grid grid-cols-[8rem_minmax(0,1fr)] gap-x-4 gap-y-1 text-sm",children:V.map(He)})})]}),e[3]=m,e[4]=f,e[5]=g?.deploy,e[6]=g?.settings,e[7]=n,e[8]=o,e[9]=i,e[10]=r,e[11]=c,e[12]=a,e[13]=u,e[14]=w}else o=e[8],i=e[9],r=e[10],c=e[11],a=e[12],u=e[13],w=e[14];let _,R;e[28]===Symbol.for("react.memo_cache_sentinel")?(_=s(ze,{}),R=s(Fe,{}),e[28]=_,e[29]=R):(_=e[28],R=e[29]);let v;e[30]!==n?(v=n("Keyboard shortcuts"),e[30]=n,e[31]=v):v=e[31];let k;e[32]!==v?(k=s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[32]=v,e[33]=k):k=e[33];let D;e[34]!==n?(D=n("Reset"),e[34]=n,e[35]=D):D=e[35];let I;e[36]!==D?(I=s("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"set-shortcut-reset",onClick:Le,type:"button",children:D}),e[36]=D,e[37]=I):I=e[37];let L;e[38]!==k||e[39]!==I?(L=d("header",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[k,I]}),e[38]=k,e[39]=I,e[40]=L):L=e[40];let y;e[41]!==n?(y=n("Command palette"),e[41]=n,e[42]=y):y=e[42];let O;e[43]!==y?(O=s(we,{label:y,modifier:"⌘/Ctrl",name:"palette"}),e[43]=y,e[44]=O):O=e[44];let U;e[45]!==n?(U=n("Operation console"),e[45]=n,e[46]=U):U=e[46];let K;e[47]!==U?(K=s(we,{label:U,modifier:"Ctrl",name:"console"}),e[47]=U,e[48]=K):K=e[48];let F;e[49]!==O||e[50]!==K?(F=d("dl",{className:"grid grid-cols-[10rem_minmax(0,1fr)] items-center gap-x-4 gap-y-2 text-sm",children:[O,K]}),e[49]=O,e[50]=K,e[51]=F):F=e[51];let q;e[52]!==n?(q=n("Stored in this browser. Focus a box and press a key to rebind it."),e[52]=n,e[53]=q):q=e[53];let M;e[54]!==q?(M=s("p",{className:"pt-3 text-xs text-muted-foreground",children:q}),e[54]=q,e[55]=M):M=e[55];let z;e[56]!==F||e[57]!==M?(z=d(oe,{className:"py-3",children:[F,M]}),e[56]=F,e[57]=M,e[58]=z):z=e[58];let H;e[59]!==L||e[60]!==z?(H=d(ie,{className:"py-0","data-testid":"set-preferences",children:[L,z]}),e[59]=L,e[60]=z,e[61]=H):H=e[61];let T;e[62]!==n?(T=n("Environment & bindings"),e[62]=n,e[63]=T):T=e[63];let S;e[64]!==T?(S=s("header",{className:"border-b border-border px-4 py-3",children:s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:T})}),e[64]=T,e[65]=S):S=e[65];let P;e[66]!==m||e[67]!==h||e[68]!==o.length||e[69]!==n?(P=m===null&&!h&&o.length===0&&s("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"set-empty",children:n("No environment variables or bindings.")}),e[66]=m,e[67]=h,e[68]=o.length,e[69]=n,e[70]=P):P=e[70];let W;e[71]!==o||e[72]!==n?(W=o.length>0&&s(oe,{className:"px-0 py-0",children:d(Se,{"data-testid":"set-table",children:[s(Ce,{children:d(me,{children:[s(Y,{children:n("name")}),s(Y,{children:n("kind")}),s(Y,{children:n("value")})]})}),s(Ae,{children:o.map(We)})]})}),e[71]=o,e[72]=n,e[73]=W):W=e[73];let C;e[74]!==S||e[75]!==P||e[76]!==W?(C=d(ie,{className:"py-0",children:[S,P,W]}),e[74]=S,e[75]=P,e[76]=W,e[77]=C):C=e[77];let $;return e[78]!==H||e[79]!==C||e[80]!==i||e[81]!==r||e[82]!==c||e[83]!==a||e[84]!==u||e[85]!==w?($=d("div",{className:i,"data-testid":r,children:[c,a,u,w,_,R,H,C]}),e[78]=H,e[79]=C,e[80]=i,e[81]=r,e[82]=c,e[83]=a,e[84]=u,e[85]=w,e[86]=$):$=e[86],$};function He(t){return d("div",{className:"contents","data-testid":"set-deploy-row",children:[s("dt",{className:"text-muted-foreground",children:t.label}),s("dd",{className:"truncate font-mono text-xs",title:t.value,children:t.value})]},t.label)}function We(t){return d(me,{"data-testid":"set-row",children:[s(Q,{className:"font-mono text-xs font-medium",children:t.name}),s(Q,{children:s(Te,{variant:Me[t.kind],children:t.bindingType??t.kind})}),s(Q,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",children:t.value??s("span",{className:"text-muted-foreground",children:"—"})})]},t.name)}export{ft as SettingsPanel};
1
+ import{c as fe}from"react/compiler-runtime";import{E as De}from"../packem_shared/error-alert-BxCd81tw.mjs";import{B as Te}from"../packem_shared/badge-r_5B4LHP.mjs";import{a as oe,C as ie}from"../packem_shared/card-By2O8ULa.mjs";import{T as Se,a as Ce,b as me,c as Y,d as Ae,e as Q}from"../packem_shared/table-D0SBiDu-.mjs";import{u as Ee}from"../packem_shared/use-admin-query-DMnTt_hg.mjs";import{useT as be}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as Re}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{b as Ie}from"../packem_shared/cf-links-BPy1pJRO.mjs";import{r as Le,u as Oe,s as Ue}from"../packem_shared/shortcuts-B9gDaXmw.mjs";import{useState as ae,useRef as Ne,useEffect as ye}from"react";import{ConfirmButton as Ke}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{B as ve}from"../packem_shared/button-q0UYSmrn.mjs";import{I as _e}from"../packem_shared/input-CXhxesPC.mjs";import{u as $e}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{c as pe,f as xe,b as ge}from"../packem_shared/internal-BT5tH08j.mjs";import{jsxs as d,jsx as s}from"react/jsx-runtime";const ke=["disabled","schema","schema_and_log","schema_and_log_and_data"],je={describeTables:"schema",readAdvisors:"schema",readLogs:"schema_and_log",readPolicies:"schema",runSql:"schema_and_log_and_data"},Be=864e5,Fe=()=>{const t=fe(67),e=$e(),l=be();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],t[0]=n):n=t[0];let b;t[1]!==e?(b={owner:e,tokens:n},t[1]=e,t[2]=b):b=t[2];const[p,N]=ae(b),g=p.owner===e?p.tokens:[],[m,f]=ae(null),[h,o]=ae(null);h!==null&&h.owner!==e&&o(null);const i=h?.owner===e?h.token:null,[r,c]=ae(""),[a,u]=ae(""),[w,_]=ae(null),R=w===e,v=Ne(0),k=Ne(e);let D,I;t[3]!==e?(D=()=>{k.current=e},I=[e],t[3]=e,t[4]=D,t[5]=I):(D=t[4],I=t[5]),ye(D,I);let L;t[6]!==e?(L=async()=>{if(k.current!==e)return;v.current=v.current+1;const x=v.current;try{const E=await e.listAdminTokens();x===v.current&&(N({owner:e,tokens:E}),f(null))}catch(E){const re=E;x===v.current&&f(ge(re))}},t[6]=e,t[7]=L):L=t[7];const y=L;let O,U;t[8]!==y?(O=()=>{xe(y())},U=[y],t[8]=y,t[9]=O,t[10]=U):(O=t[9],U=t[10]),ye(O,U);let K;t[11]!==e||t[12]!==i||t[13]!==R||t[14]!==a||t[15]!==r||t[16]!==y?(K=x=>{if(x.preventDefault(),R||i!==null)return;_(e);const E=e,re=a===""?void 0:Date.now()+Number(a)*Be;xe((async()=>{try{const le=await E.createAdminToken({expiresAt:re,name:r.trim()});k.current===E&&(o({owner:E,token:le}),c(""),u(""),await y())}catch(le){f(ge(le))}_(le=>le===E?null:le)})())},t[11]=e,t[12]=i,t[13]=R,t[14]=a,t[15]=r,t[16]=y,t[17]=K):K=t[17];const F=K,q=x=>{xe((async()=>{try{await e.revokeAdminToken(x),o(E=>E?.token.name===x?null:E),await y()}catch(E){const re=E;await y(),k.current===e&&f(ge(re))}})())},M=ie,z="py-0",H="set-admin-tokens";let T;t[18]!==l?(T=l("Admin tokens"),t[18]=l,t[19]=T):T=t[19];let S;t[20]!==T?(S=s("header",{className:"border-b border-border px-4 py-3",children:s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:T})}),t[20]=T,t[21]=S):S=t[21];const P=oe,W="flex flex-col gap-3 py-3";let C;t[22]!==l?(C=l("Named tokens use the admin API but cannot manage tokens or open admin WebSockets. A revoked token is refused within 30 seconds."),t[22]=l,t[23]=C):C=t[23];let $;t[24]!==C?($=s("p",{className:"text-xs text-muted-foreground",children:C}),t[24]=C,t[25]=$):$=t[25];let V;t[26]!==m?(V=m!==null&&s("p",{className:"text-sm text-destructive","data-testid":"set-admin-tokens-error",role:"alert",children:m}),t[26]=m,t[27]=V):V=t[27];let j;t[28]!==i||t[29]!==l?(j=i!==null&&d("div",{className:"rounded-md border border-border p-3 text-xs","data-testid":"set-admin-token-created",role:"status",children:[s("p",{className:"pb-1 text-muted-foreground",children:l("Copy this token now. It is not shown again.")}),s("code",{className:"font-mono break-all select-all",children:i.token}),s("div",{className:"pt-2",children:s(ve,{"data-testid":"set-admin-token-dismiss",onClick:()=>{o(null)},size:"xs",variant:"outline",children:l("Dismiss")})})]}),t[28]=i,t[29]=l,t[30]=j):j=t[30];let A;t[31]!==l?(A=l("Token name"),t[31]=l,t[32]=A):A=t[32];let B;t[33]===Symbol.for("react.memo_cache_sentinel")?(B=x=>{c(x.target.value)},t[33]=B):B=t[33];let G;t[34]!==r||t[35]!==A?(G=s(_e,{"aria-label":A,className:"w-48","data-testid":"set-admin-token-name",onChange:B,pattern:"[a-z0-9][a-z0-9_\\-]{0,63}",placeholder:"ci-deploy",required:!0,value:r}),t[34]=r,t[35]=A,t[36]=G):G=t[36];let J;t[37]!==l?(J=l("Expires in days (optional)"),t[37]=l,t[38]=J):J=t[38];let de;t[39]===Symbol.for("react.memo_cache_sentinel")?(de=x=>{u(x.target.value)},t[39]=de):de=t[39];let X;t[40]!==l?(X=l("Expires in days (optional)"),t[40]=l,t[41]=X):X=t[41];let Z;t[42]!==a||t[43]!==J||t[44]!==X?(Z=s(_e,{"aria-label":J,className:"w-40",min:1,onChange:de,placeholder:X,type:"number",value:a}),t[42]=a,t[43]=J,t[44]=X,t[45]=Z):Z=t[45];const ue=R||i!==null;let ee;t[46]!==l?(ee=l("Create token"),t[46]=l,t[47]=ee):ee=t[47];let te;t[48]!==ue||t[49]!==ee?(te=s(ve,{"data-testid":"set-admin-token-create",disabled:ue,size:"sm",type:"submit",children:ee}),t[48]=ue,t[49]=ee,t[50]=te):te=t[50];let se;t[51]!==F||t[52]!==G||t[53]!==Z||t[54]!==te?(se=d("form",{className:"flex flex-wrap items-end gap-2",onSubmit:F,children:[G,Z,te]}),t[51]=F,t[52]=G,t[53]=Z,t[54]=te,t[55]=se):se=t[55];const he=g.length>0&&d(Se,{"data-testid":"set-admin-tokens-table",children:[s(Ce,{children:d(me,{children:[s(Y,{children:l("name")}),s(Y,{children:l("Created")}),s(Y,{children:l("Last used")}),s(Y,{children:l("Expires")}),s(Y,{})]})}),s(Ae,{children:g.map(x=>d(me,{"data-testid":"set-admin-token-row",children:[d(Q,{className:"font-mono text-xs",children:[x.name,x.revoked===!0&&s("span",{className:"pl-2 text-destructive",children:l("Revoked")})]}),s(Q,{className:"text-xs",children:pe(x.createdAt)}),s(Q,{className:"text-xs",children:pe(x.lastUsedAt,"—")}),s(Q,{className:"text-xs",children:pe(x.expiresAt,l("Never"))}),s(Q,{children:s(Ke,{onConfirm:()=>{q(x.name)},testId:`set-admin-token-revoke-${x.name}`,children:l("Revoke")})})]},x.name))})]});let ne;t[56]!==P||t[57]!==$||t[58]!==V||t[59]!==j||t[60]!==se||t[61]!==he?(ne=d(P,{className:W,children:[$,V,j,se,he]}),t[56]=P,t[57]=$,t[58]=V,t[59]=j,t[60]=se,t[61]=he,t[62]=ne):ne=t[62];let ce;return t[63]!==M||t[64]!==S||t[65]!==ne?(ce=d(M,{className:z,"data-testid":H,children:[S,ne]}),t[63]=M,t[64]=S,t[65]=ne,t[66]=ce):ce=t[66],ce},Me={binding:"outline",secret:"destructive",var:"secondary"},Pe=(t,e)=>{if(t===void 0)return[];const l=[];return t.workerUrl!==void 0&&l.push({label:e("URL"),value:t.workerUrl}),t.environment!==void 0&&l.push({label:e("Environment"),value:t.environment}),t.deploymentId!==void 0&&l.push({label:e("Deployment"),value:t.deploymentId}),t.versionTag!==void 0&&l.push({label:e("Version"),value:t.versionTag}),l},Ve={disabled:"The assistant is off. Nothing about this deployment is sent to a model.",schema:"Table and column names.",schema_and_log:"Table and column names, plus recent log lines.",schema_and_log_and_data:"Table and column names, log lines, and rows read with SELECT."},qe=t=>{const e=[];for(const[l,n]of Object.entries(je))n===t&&e.push(l);return e},ze=()=>{const t=fe(29),e=be();let l,n;t[0]===Symbol.for("react.memo_cache_sentinel")?(l={},n={shardKey:""},t[0]=l,t[1]=n):(l=t[0],n=t[1]);const{data:b}=Ee(Re.aiAvailable,l,n),p=b?.level;let N;t[2]!==p?(N=p===void 0?-1:ke.indexOf(p),t[2]=p,t[3]=N):N=t[3];const g=N;let m;t[4]!==e?(m=e("AI assistant data sharing"),t[4]=e,t[5]=m):m=t[5];let f;t[6]!==m?(f=s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m}),t[6]=m,t[7]=f):f=t[7];let h;t[8]!==p?(h=p!==void 0&&s(Te,{"data-testid":"set-ai-level",variant:p==="disabled"?"outline":"secondary",children:p}),t[8]=p,t[9]=h):h=t[9];let o;t[10]!==f||t[11]!==h?(o=d("header",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[f,h]}),t[10]=f,t[11]=h,t[12]=o):o=t[12];let i;t[13]!==g||t[14]!==p||t[15]!==e?(i=ke.map((_,R)=>{const v=g>=R,k=qe(_);return d("li",{className:v?"flex flex-col gap-0.5":"flex flex-col gap-0.5 opacity-50","data-granted":String(v),"data-testid":`set-ai-tier-${_}`,children:[d("span",{className:"flex items-center gap-2",children:[s("span",{className:"font-mono text-xs",children:_}),_===p&&s("span",{className:"text-[11px] text-primary",children:e("current")})]}),s("span",{className:"text-xs text-muted-foreground",children:e(Ve[_])}),k.length>0&&s("span",{className:"font-mono text-[11px] text-muted-foreground",children:k.join(", ")})]},_)}),t[13]=g,t[14]=p,t[15]=e,t[16]=i):i=t[16];let r;t[17]!==i?(r=s("ul",{className:"flex flex-col gap-1.5 text-sm",children:i}),t[17]=i,t[18]=r):r=t[18];let c;t[19]!==e?(c=e("Set LUNORA_AI_OPT_IN in wrangler.jsonc and redeploy to change this. The Studio can read this level but never raise it."),t[19]=e,t[20]=c):c=t[20];let a;t[21]!==c?(a=s("p",{className:"text-xs text-muted-foreground","data-testid":"set-ai-howto",children:c}),t[21]=c,t[22]=a):a=t[22];let u;t[23]!==a||t[24]!==r?(u=d(oe,{className:"flex flex-col gap-3 py-3",children:[r,a]}),t[23]=a,t[24]=r,t[25]=u):u=t[25];let w;return t[26]!==u||t[27]!==o?(w=d(ie,{className:"py-0","data-testid":"set-ai-sharing",children:[o,u]}),t[26]=u,t[27]=o,t[28]=w):w=t[28],w},we=t=>{const e=fe(18),{modifier:l,name:n,label:b}=t,p=Oe();let N;e[0]!==n?(N=u=>{if(!["Escape","Tab"].includes(u.key)){if(u.shiftKey){u.preventDefault();return}u.preventDefault(),Ue(n,u.key)}},e[0]=n,e[1]=N):N=e[1];const g=N,m=`set-shortcut-${n}`;let f;e[2]!==b?(f=s("dt",{className:"text-muted-foreground",children:b}),e[2]=b,e[3]=f):f=e[3];let h;e[4]!==l?(h=s("kbd",{className:"rounded border border-border px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:l}),e[4]=l,e[5]=h):h=e[5];const o=`set-shortcut-input-${n}`,i=p[n];let r;e[6]!==b||e[7]!==g||e[8]!==o||e[9]!==i?(r=s("input",{"aria-label":b,className:"h-7 w-12 rounded-md border border-border bg-background text-center font-mono text-xs uppercase outline-none focus-visible:border-ring","data-testid":o,onKeyDown:g,readOnly:!0,value:i}),e[6]=b,e[7]=g,e[8]=o,e[9]=i,e[10]=r):r=e[10];let c;e[11]!==h||e[12]!==r?(c=d("dd",{className:"flex items-center gap-1.5",children:[h,r]}),e[11]=h,e[12]=r,e[13]=c):c=e[13];let a;return e[14]!==m||e[15]!==f||e[16]!==c?(a=d("div",{className:"contents","data-testid":m,children:[f,c]}),e[14]=m,e[15]=f,e[16]=c,e[17]=a):a=e[17],a},ft=t=>{const e=fe(87),{initialShardKey:l}=t,n=be();let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={},e[0]=b):b=e[0];const p=l??"";let N;e[1]!==p?(N={shardKey:p},e[1]=p,e[2]=N):N=e[2];const{data:g,error:m,errorSource:f,isLoading:h}=Ee(Re.getSettings,b,N);let o,i,r,c,a,u,w;if(e[3]!==m||e[4]!==f||e[5]!==g?.deploy||e[6]!==g?.settings||e[7]!==n){const V=Pe(g?.deploy,n);let j;e[15]!==g?.settings?(j=g?.settings??[],e[15]=g?.settings,e[16]=j):j=e[16],o=j,i="flex flex-col gap-4",r="lunora-settings";let A;e[17]!==n?(A=n("Open in Cloudflare"),e[17]=n,e[18]=A):A=e[18],e[19]!==A?(c=s("div",{className:"flex flex-wrap items-center gap-3",children:s("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"set-cf-link",href:Ie,rel:"noreferrer",target:"_blank",children:A})}),e[19]=A,e[20]=c):c=e[20];let B;e[21]!==n?(B=n("View-only — values are masked. Edit vars, secrets, and bindings in wrangler or the Cloudflare dashboard."),e[21]=n,e[22]=B):B=e[22],e[23]!==B?(a=s("p",{className:"text-sm text-muted-foreground","data-testid":"set-readonly-note",children:B}),e[23]=B,e[24]=a):a=e[24],e[25]!==m||e[26]!==f?(u=m!==null&&s(De,{error:f,testId:"set-error"}),e[25]=m,e[26]=f,e[27]=u):u=e[27],w=V.length>0&&d(ie,{className:"py-0","data-testid":"set-deploy",children:[s("header",{className:"border-b border-border px-4 py-3",children:s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Deployment")})}),s(oe,{className:"py-3",children:s("dl",{className:"grid grid-cols-[8rem_minmax(0,1fr)] gap-x-4 gap-y-1 text-sm",children:V.map(He)})})]}),e[3]=m,e[4]=f,e[5]=g?.deploy,e[6]=g?.settings,e[7]=n,e[8]=o,e[9]=i,e[10]=r,e[11]=c,e[12]=a,e[13]=u,e[14]=w}else o=e[8],i=e[9],r=e[10],c=e[11],a=e[12],u=e[13],w=e[14];let _,R;e[28]===Symbol.for("react.memo_cache_sentinel")?(_=s(ze,{}),R=s(Fe,{}),e[28]=_,e[29]=R):(_=e[28],R=e[29]);let v;e[30]!==n?(v=n("Keyboard shortcuts"),e[30]=n,e[31]=v):v=e[31];let k;e[32]!==v?(k=s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[32]=v,e[33]=k):k=e[33];let D;e[34]!==n?(D=n("Reset"),e[34]=n,e[35]=D):D=e[35];let I;e[36]!==D?(I=s("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"set-shortcut-reset",onClick:Le,type:"button",children:D}),e[36]=D,e[37]=I):I=e[37];let L;e[38]!==k||e[39]!==I?(L=d("header",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[k,I]}),e[38]=k,e[39]=I,e[40]=L):L=e[40];let y;e[41]!==n?(y=n("Command palette"),e[41]=n,e[42]=y):y=e[42];let O;e[43]!==y?(O=s(we,{label:y,modifier:"⌘/Ctrl",name:"palette"}),e[43]=y,e[44]=O):O=e[44];let U;e[45]!==n?(U=n("Operation console"),e[45]=n,e[46]=U):U=e[46];let K;e[47]!==U?(K=s(we,{label:U,modifier:"Ctrl",name:"console"}),e[47]=U,e[48]=K):K=e[48];let F;e[49]!==O||e[50]!==K?(F=d("dl",{className:"grid grid-cols-[10rem_minmax(0,1fr)] items-center gap-x-4 gap-y-2 text-sm",children:[O,K]}),e[49]=O,e[50]=K,e[51]=F):F=e[51];let q;e[52]!==n?(q=n("Stored in this browser. Focus a box and press a key to rebind it."),e[52]=n,e[53]=q):q=e[53];let M;e[54]!==q?(M=s("p",{className:"pt-3 text-xs text-muted-foreground",children:q}),e[54]=q,e[55]=M):M=e[55];let z;e[56]!==F||e[57]!==M?(z=d(oe,{className:"py-3",children:[F,M]}),e[56]=F,e[57]=M,e[58]=z):z=e[58];let H;e[59]!==L||e[60]!==z?(H=d(ie,{className:"py-0","data-testid":"set-preferences",children:[L,z]}),e[59]=L,e[60]=z,e[61]=H):H=e[61];let T;e[62]!==n?(T=n("Environment & bindings"),e[62]=n,e[63]=T):T=e[63];let S;e[64]!==T?(S=s("header",{className:"border-b border-border px-4 py-3",children:s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:T})}),e[64]=T,e[65]=S):S=e[65];let P;e[66]!==m||e[67]!==h||e[68]!==o.length||e[69]!==n?(P=m===null&&!h&&o.length===0&&s("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"set-empty",children:n("No environment variables or bindings.")}),e[66]=m,e[67]=h,e[68]=o.length,e[69]=n,e[70]=P):P=e[70];let W;e[71]!==o||e[72]!==n?(W=o.length>0&&s(oe,{className:"px-0 py-0",children:d(Se,{"data-testid":"set-table",children:[s(Ce,{children:d(me,{children:[s(Y,{children:n("name")}),s(Y,{children:n("kind")}),s(Y,{children:n("value")})]})}),s(Ae,{children:o.map(We)})]})}),e[71]=o,e[72]=n,e[73]=W):W=e[73];let C;e[74]!==S||e[75]!==P||e[76]!==W?(C=d(ie,{className:"py-0",children:[S,P,W]}),e[74]=S,e[75]=P,e[76]=W,e[77]=C):C=e[77];let $;return e[78]!==H||e[79]!==C||e[80]!==i||e[81]!==r||e[82]!==c||e[83]!==a||e[84]!==u||e[85]!==w?($=d("div",{className:i,"data-testid":r,children:[c,a,u,w,_,R,H,C]}),e[78]=H,e[79]=C,e[80]=i,e[81]=r,e[82]=c,e[83]=a,e[84]=u,e[85]=w,e[86]=$):$=e[86],$};function He(t){return d("div",{className:"contents","data-testid":"set-deploy-row",children:[s("dt",{className:"text-muted-foreground",children:t.label}),s("dd",{className:"truncate font-mono text-xs",title:t.value,children:t.value})]},t.label)}function We(t){return d(me,{"data-testid":"set-row",children:[s(Q,{className:"font-mono text-xs font-medium",children:t.name}),s(Q,{children:s(Te,{variant:Me[t.kind],children:t.bindingType??t.kind})}),s(Q,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",children:t.value??s("span",{className:"text-muted-foreground",children:"—"})})]},t.name)}export{ft as SettingsPanel};
@@ -1,4 +1,4 @@
1
- import{c as G}from"react/compiler-runtime";import{useState as te,useMemo as je,useCallback as Ze,useEffect as ue,useRef as de,useId as ht}from"react";import{u as bt}from"../packem_shared/assistant-provider-Dw0roZh3.mjs";import{u as gt}from"../packem_shared/use-assistant-rpc-AKu8hvPm.mjs";import{u as $e}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as Z}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as qe}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{u as Oe,n as et,b as Be,r as Ce,s as xt}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{d as Re,f as ie,c as Ie,l as vt,b as yt}from"../packem_shared/internal-hIuTpSbx.mjs";import{r as St}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import wt from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{c as ae}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as W,jsx as u,Fragment as xe}from"react/jsx-runtime";import{I as Le}from"../packem_shared/input-CXhxesPC.mjs";import{a as tt}from"../packem_shared/assistant-reason-D6EwMCxT.mjs";import{diffLines as Ct}from"diff";import{S as Et,a as Nt}from"../packem_shared/sql-result-table-DCwooMGW.mjs";import{ShardInput as kt}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{A as Tt}from"../packem_shared/alert-PB5W11MM.mjs";import{E as Rt}from"../packem_shared/grid-features-Drvfswwy.mjs";const Lt="x",ze=" ",_t={'"':'"',"'":"'","[":"]","`":"`"},nt=(l,e)=>{let n=e+2;for(;n<l.length&&l[n]!==`
1
+ import{c as G}from"react/compiler-runtime";import{useState as te,useMemo as je,useCallback as Ze,useEffect as ue,useRef as de,useId as ht}from"react";import{u as bt}from"../packem_shared/assistant-provider-b2GtJb5K.mjs";import{u as gt}from"../packem_shared/use-assistant-rpc-DLsuqTPB.mjs";import{u as $e}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as Z}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as qe}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{u as Oe,n as et,b as Be,r as Ce,s as xt}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{g as Re,f as ie,d as Ie,k as vt,b as yt}from"../packem_shared/internal-BT5tH08j.mjs";import{r as St}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import wt from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{c as ae}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as W,jsx as u,Fragment as xe}from"react/jsx-runtime";import{I as Le}from"../packem_shared/input-CXhxesPC.mjs";import{a as tt}from"../packem_shared/assistant-reason-D6EwMCxT.mjs";import{diffLines as Ct}from"diff";import{S as Et,a as Nt}from"../packem_shared/sql-result-table-BuOHHoFG.mjs";import{ShardInput as kt}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{A as Tt}from"../packem_shared/alert-PB5W11MM.mjs";import{E as Rt}from"../packem_shared/grid-features-Cdy2nWxA.mjs";const Lt="x",ze=" ",_t={'"':'"',"'":"'","[":"]","`":"`"},nt=(l,e)=>{let n=e+2;for(;n<l.length&&l[n]!==`
2
2
  `;)n+=1;return n},st=(l,e)=>{const n=l.indexOf("*/",e+2);return n===-1?-1:n+2},ot=l=>{const e=l.split("");let n=0;for(;n<l.length;){const t=l[n]??"",s=_t[t];if(t==="-"&&l[n+1]==="-"){const o=nt(l,n);e.fill(ze,n,o),n=o}else if(t==="/"&&l[n+1]==="*"){const o=st(l,n);if(o===-1)return;e.fill(ze,n,o),n=o}else if(s!==void 0){let o=n+1;for(;o<l.length;)if(l[o]!==s)o+=1;else if(s!=="]"&&l[o+1]===s)o+=2;else break;if(o>=l.length)return;e.fill(Lt,n,o+1),n=o+1}else n+=1}for(let t=0;t<l.length;t+=1)l[t]===`
3
3
  `&&(e[t]=`
4
4
  `);return e.join("")},qt="__lunora_admin_tokens__",Pe=new Set([qt,"dbstat","sqlite_dbpage"]),lt="pragma_",It=l=>/[\p{L}_]/u.test(l)||(l.codePointAt(0)??0)>127,At=l=>/[\p{L}\p{N}_$]/u.test(l)||(l.codePointAt(0)??0)>127,Dt=/^pragma_\w+$/u,Ot=l=>Pe.has(l)||Dt.test(l)?l:void 0,Ke=l=>{if(Pe.has(l)||l.startsWith(lt))return l},Ue=(l,e,n)=>{let t="",s=e+1;for(;s<l.length;){const o=l[s];if(o===n){if(n!=="]"&&l[s+1]===n){t+=n,s+=2;continue}return{end:s+1,text:t}}t+=o,s+=1}},Ye={'"':'"',"`":"`","[":"]"},Ae=l=>{const e=l.toLowerCase().replaceAll(/["'`[\]]/gu,"");for(const n of Pe)if(e.includes(n))return n;return/\bpragma_/u.test(e)?lt:void 0},Mt=l=>{let e=0;for(;e<l.length;){const n=l[e];if(/\s/u.test(n))e+=1;else if(n==="-"&&l[e+1]==="-"){const t=l.indexOf(`
@@ -1 +1 @@
1
- import{c as k}from"react/compiler-runtime";import{useNavigate as F,useRouter as M,useSearch as P}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as q}from"../packem_shared/use-mirrored-ref-CVDf2z1M.mjs";import{u as J}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{s as L,d as D}from"../packem_shared/data-view-params-C-_G-biH.mjs";import{f as m}from"../packem_shared/internal-hIuTpSbx.mjs";import{l as O,s as I}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as X}from"../packem_shared/DataBrowser-CkVOu6py.mjs";import{GlobalDataBrowser as Y}from"../packem_shared/GlobalDataBrowser-l2ECwXCm.mjs";import{jsx as v,jsxs as E}from"react/jsx-runtime";const N="lunora-studio-saved-queries",$=50,z=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,y=()=>O(N).filter(z),B=r=>{I(N,r)},H=(r,e)=>{const l=r.trim();if(l==="")return y();const n=[{name:l,view:e},...y().filter(o=>o.name!==l)].slice(0,$);return B(n),n},U=r=>{const e=y().filter(l=>l.name!==r);return B(e),e},W=r=>{const e=k(15),{onChange:l,tier:n}=r,o=K();let p;e[0]!==l?(p=S=>{l(S.target.value)},e[0]=l,e[1]=p):p=e[1];const u=p;let s;e[2]!==o?(s=o("Storage tier"),e[2]=o,e[3]=s):s=e[3];let d;e[4]!==s?(d=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:s}),e[4]=s,e[5]=d):d=e[5];const g=w[n];let c,i;e[6]===Symbol.for("react.memo_cache_sentinel")?(c=v("option",{value:"shard",children:w.shard.label}),i=v("option",{value:"global",children:w.global.label}),e[6]=c,e[7]=i):(c=e[6],i=e[7]);let h;e[8]!==u||e[9]!==g.title||e[10]!==n?(h=E("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:u,title:g.title,value:n,children:[c,i]}),e[8]=u,e[9]=g.title,e[10]=n,e[11]=h):h=e[11];let f;return e[12]!==d||e[13]!==h?(f=E("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[d,h]}),e[12]=d,e[13]=h,e[14]=f):f=e[14],f},Z=()=>{try{m(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},ge=({canGenerateRows:r=!1,editable:e=!1,initialShardKey:l})=>{const n=J(),o=F(),p=M(),u=P({strict:!1}),s=L(u),d=q(u),g=()=>p.state.location.pathname.split("/").findLast(Boolean)==="data",c=s.tier??"shard",i=s.table,[h,f]=Q(()=>y()),[S,C]=Q(()=>new Set);A(()=>{m((async()=>{try{const a=await n.listGlobalTables();C(new Set(a.map(t=>t.name)))}catch{}})())},[n]),A(()=>{c==="shard"&&i!==void 0&&S.has(i)&&m(o({replace:!0,search:a=>({...a,schema:"global"}),to:"/data"}))},[S,o,i,c]);const R=a=>{m(o({search:t=>({...t,schema:a==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(a,t)=>{g()&&m(o({search:b=>({schema:b.schema,search:t?.search,shard:b.shard,table:a}),to:"/data"}))},G=a=>{m(o({search:t=>({...t,schema:"global",table:a}),to:"/data"}))},_=a=>{const t=D(a),{current:b}=d;(b.filters??void 0)===t.filters&&(b.order??void 0)===t.order&&(b.search??void 0)===t.search&&(b.shard??void 0)===t.shard||!g()||m(o({replace:!0,search:V=>({...V,filters:t.filters,order:t.order,search:t.search,shard:t.shard}),to:"/data"}))},j={onApplyQuery:a=>{const t=D(a.view);m(o({search:()=>({filters:t.filters,order:t.order,schema:t.schema,search:t.search,shard:t.shard,table:t.table}),to:"/data"}))},onCopyLink:Z,onDeleteQuery:a=>{f(U(a))},onSaveQuery:(a,t)=>{f(H(a,t))},saved:h},x=v(W,{onChange:R,tier:c});return c==="global"?v(Y,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(X,{canGenerateRows:r,editable:e,globalTableNames:S,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:u.pins,initialSearch:s.search,initialShardKey:s.shard??l,onNavigateToGlobal:G,onSelectTable:T,onViewChange:_,queryBar:j,schemaSwitch:x,tableParam:i})};export{ge as TableEditor};
1
+ import{c as k}from"react/compiler-runtime";import{useNavigate as F,useRouter as M,useSearch as P}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as q}from"../packem_shared/use-mirrored-ref-CVDf2z1M.mjs";import{u as J}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{s as L,d as D}from"../packem_shared/data-view-params-C-_G-biH.mjs";import{f as m}from"../packem_shared/internal-BT5tH08j.mjs";import{l as O,s as I}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as X}from"../packem_shared/DataBrowser-Dp8ayK1S.mjs";import{GlobalDataBrowser as Y}from"../packem_shared/GlobalDataBrowser-VehUMwUK.mjs";import{jsx as v,jsxs as E}from"react/jsx-runtime";const N="lunora-studio-saved-queries",$=50,z=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,y=()=>O(N).filter(z),B=r=>{I(N,r)},H=(r,e)=>{const l=r.trim();if(l==="")return y();const n=[{name:l,view:e},...y().filter(o=>o.name!==l)].slice(0,$);return B(n),n},U=r=>{const e=y().filter(l=>l.name!==r);return B(e),e},W=r=>{const e=k(15),{onChange:l,tier:n}=r,o=K();let p;e[0]!==l?(p=S=>{l(S.target.value)},e[0]=l,e[1]=p):p=e[1];const u=p;let s;e[2]!==o?(s=o("Storage tier"),e[2]=o,e[3]=s):s=e[3];let d;e[4]!==s?(d=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:s}),e[4]=s,e[5]=d):d=e[5];const g=w[n];let c,i;e[6]===Symbol.for("react.memo_cache_sentinel")?(c=v("option",{value:"shard",children:w.shard.label}),i=v("option",{value:"global",children:w.global.label}),e[6]=c,e[7]=i):(c=e[6],i=e[7]);let h;e[8]!==u||e[9]!==g.title||e[10]!==n?(h=E("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:u,title:g.title,value:n,children:[c,i]}),e[8]=u,e[9]=g.title,e[10]=n,e[11]=h):h=e[11];let f;return e[12]!==d||e[13]!==h?(f=E("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[d,h]}),e[12]=d,e[13]=h,e[14]=f):f=e[14],f},Z=()=>{try{m(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},ge=({canGenerateRows:r=!1,editable:e=!1,initialShardKey:l})=>{const n=J(),o=F(),p=M(),u=P({strict:!1}),s=L(u),d=q(u),g=()=>p.state.location.pathname.split("/").findLast(Boolean)==="data",c=s.tier??"shard",i=s.table,[h,f]=Q(()=>y()),[S,C]=Q(()=>new Set);A(()=>{m((async()=>{try{const a=await n.listGlobalTables();C(new Set(a.map(t=>t.name)))}catch{}})())},[n]),A(()=>{c==="shard"&&i!==void 0&&S.has(i)&&m(o({replace:!0,search:a=>({...a,schema:"global"}),to:"/data"}))},[S,o,i,c]);const R=a=>{m(o({search:t=>({...t,schema:a==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(a,t)=>{g()&&m(o({search:b=>({schema:b.schema,search:t?.search,shard:b.shard,table:a}),to:"/data"}))},G=a=>{m(o({search:t=>({...t,schema:"global",table:a}),to:"/data"}))},_=a=>{const t=D(a),{current:b}=d;(b.filters??void 0)===t.filters&&(b.order??void 0)===t.order&&(b.search??void 0)===t.search&&(b.shard??void 0)===t.shard||!g()||m(o({replace:!0,search:V=>({...V,filters:t.filters,order:t.order,search:t.search,shard:t.shard}),to:"/data"}))},j={onApplyQuery:a=>{const t=D(a.view);m(o({search:()=>({filters:t.filters,order:t.order,schema:t.schema,search:t.search,shard:t.shard,table:t.table}),to:"/data"}))},onCopyLink:Z,onDeleteQuery:a=>{f(U(a))},onSaveQuery:(a,t)=>{f(H(a,t))},saved:h},x=v(W,{onChange:R,tier:c});return c==="global"?v(Y,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(X,{canGenerateRows:r,editable:e,globalTableNames:S,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:u.pins,initialSearch:s.search,initialShardKey:s.shard??l,onNavigateToGlobal:G,onSelectTable:T,onViewChange:_,queryBar:j,schemaSwitch:x,tableParam:i})};export{ge as TableEditor};
@@ -1 +1 @@
1
- import{c as te}from"react/compiler-runtime";import{useState as se}from"react";import{E as q}from"../packem_shared/error-alert-3AR_-s_s.mjs";import{B as A}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as $}from"../packem_shared/button-q0UYSmrn.mjs";import{C as M,a as j}from"../packem_shared/card-By2O8ULa.mjs";import{E as K}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as L,a as P,b as f,c as o,d as U,e as d}from"../packem_shared/table-D0SBiDu-.mjs";import{u as x}from"../packem_shared/use-admin-query-CaOm4JS3.mjs";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as v}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{h as ae}from"../packem_shared/internal-hIuTpSbx.mjs";import{jsx as e,jsxs as l}from"react/jsx-runtime";const Q="agent_threads",re="agent_messages",D="agent_run_queue",_=100,y=250,ne={},oe={filters:[],limit:_,offset:0,orderBy:{column:"updatedAt",direction:"desc"},skipCount:!0,table:Q},c=(r,t)=>{const s=r[t];return typeof s=="string"?s:void 0},E=(r,t)=>{const s=r[t];return typeof s=="number"?s:void 0},H=r=>{const{usage:t}=r;if(t===null||typeof t!="object")return;const{totalTokens:s}=t;return typeof s=="number"?s:void 0},de=r=>{const{toolCalls:t}=r;return Array.isArray(t)?t.map(s=>s!==null&&typeof s=="object"?s.name:void 0).filter(s=>typeof s=="string"):[]},le=r=>{switch(r){case"awaiting_input":return"warning";case"cancelled":return"warning";case"error":return"destructive";case"running":return"info";default:return"outline"}},ie=r=>{switch(r){case"approved":return"success";case"rejected":return"destructive";default:return"warning"}},ce=r=>{const t=te(3),{fetched:s}=r,u=G();let i;return t[0]!==s||t[1]!==u?(i=s<=y?null:e("p",{className:"text-xs text-muted-foreground","data-testid":"agents-messages-truncated",children:u("Showing the latest {count} messages; older ones are not shown.",{count:y})}),t[0]=s,t[1]=u,t[2]=i):i=t[2],i},Ee=({initialShardKey:r=""})=>{const t=G(),[s,u]=se(void 0),{data:i}=x(v.listTables,ne,{live:!0,shardKey:r}),z=i!==void 0,h=Array.isArray(i)&&i.some(a=>a.name===Q),O=Array.isArray(i)&&i.some(a=>a.name===D),{data:S,error:V,errorSource:F,liveError:J}=x(v.readTablePage,oe,{enabled:h,live:!0,shardKey:r}),W={filters:[{column:"threadKey",operator:"eq",value:s??""}],limit:y+1,offset:0,orderBy:{column:"seq",direction:"desc"},skipCount:!0,table:re},{data:w}=x(v.readTablePage,{limit:_,offset:0,orderBy:{column:"position",direction:"asc"},skipCount:!0,table:D},{enabled:O,live:!0,shardKey:r}),{data:k,error:X,errorSource:Y}=x(v.readTablePage,W,{enabled:h&&s!==void 0,live:!0,shardKey:r}),b=Array.isArray(S?.rows)?S.rows:[],Z=Array.isArray(w?.rows)?w.rows:[],C=a=>Z.filter(n=>c(n,"threadKey")===a).length,B=Array.isArray(k?.rows)?k.rows:[],I=B.slice(0,y).toReversed(),R=b.find(a=>c(a,"key")===s);let g;return z&&!h?g=e(K,{description:t("No @lunora/agent tables found in this deployment. Add lunora/agents.ts with defineAgent(...) and merge the agent schema extension to run durable AI agents."),testId:"agents-unconfigured",title:t("No agents configured")}):h&&b.length===0?g=e(K,{description:t("No agent has run yet. Start a run with ctx.agents.<name>.run(...) and its thread appears here."),testId:"agents-empty",title:t("No agent threads yet")}):g=l("div",{className:"flex flex-col gap-6",children:[e(M,{className:"overflow-hidden py-0",children:e(j,{className:"px-0",children:l(L,{"data-testid":"agents-threads-table",children:[e(P,{children:l(f,{children:[e(o,{children:t("Agent")}),e(o,{children:t("Key")}),e(o,{children:t("Status")}),e(o,{children:t("Queued")}),e(o,{children:t("Messages")}),e(o,{children:t("Tokens")}),e(o,{children:t("Updated")}),e(o,{"aria-label":t("Actions")})]})}),e(U,{children:b.map(a=>{const n=c(a,"key")??"",m=c(a,"status"),p=H(a);return l(f,{"data-active":n===s?"":void 0,"data-testid":`agents-thread-${n}`,children:[e(d,{className:"font-mono text-xs",children:c(a,"agent")??"—"}),e(d,{className:"font-mono text-xs text-muted-foreground",children:n}),e(d,{children:e(A,{"data-testid":`agents-thread-status-${n}`,variant:le(m),children:m??"—"})}),e(d,{className:"tabular-nums",children:C(n)===0?e("span",{className:"text-muted-foreground",children:"—"}):e(A,{"data-testid":`agents-thread-queued-${n}`,variant:"warning",children:C(n)})}),e(d,{className:"tabular-nums",children:E(a,"messageCount")??"—"}),e(d,{className:"tabular-nums text-muted-foreground",children:p??"—"}),e(d,{className:"text-muted-foreground tabular-nums",children:ae(E(a,"updatedAt"),"—")}),e(d,{className:"text-right",children:e($,{"data-testid":`agents-thread-open-${n}`,onClick:()=>{u(n)},size:"sm",type:"button",variant:"outline",children:t("Timeline")})})]},n)})})]})})}),X!==null&&e(q,{error:Y,shardKey:r,testId:"agents-messages-error"}),s!==void 0&&e(M,{className:"overflow-hidden py-0","data-testid":"agents-thread-detail",children:l(j,{className:"flex flex-col gap-3 px-4 py-3",children:[l("div",{className:"flex items-center justify-between gap-2",children:[l("span",{className:"font-mono text-xs",children:[t("Timeline")," · ",s,R!==void 0&&l("span",{className:"text-muted-foreground",children:[" · ",t("Usage"),": ",H(R)??0," ",t("Tokens")]})]}),e($,{"data-testid":"agents-thread-detail-close",onClick:()=>{u(void 0)},size:"xs",type:"button",variant:"ghost",children:t("Close")})]}),e(ce,{fetched:B.length}),I.length===0?e("p",{className:"text-xs text-muted-foreground",children:t("This thread has no messages yet.")}):l(L,{"data-testid":"agents-messages-table",children:[e(P,{children:l(f,{children:[e(o,{children:t("Role")}),e(o,{children:t("Content")}),e(o,{children:t("Tool")}),e(o,{children:t("Approval")})]})}),e(U,{children:I.map((a,n)=>{const m=c(a,"role")??"—",p=de(a),ee=c(a,"toolName"),N=c(a,"status"),T=E(a,"seq")??n;return l(f,{"data-testid":`agents-message-${String(T)}`,children:[e(d,{className:"font-mono text-xs align-top text-muted-foreground",children:m}),e(d,{className:"max-w-md font-mono text-xs whitespace-pre-wrap break-words",children:c(a,"content")??"—"}),e(d,{className:"font-mono text-xs align-top text-muted-foreground",children:ee??(p.length>0?p.join(", "):"—")}),e(d,{className:"align-top",children:N===void 0?e("span",{className:"text-xs text-muted-foreground",children:"—"}):e(A,{"data-testid":`agents-message-approval-${String(T)}`,variant:ie(N),children:N})})]},c(a,"messageKey")??`${m}:${String(T)}`)})})]})]})})]}),l("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[V!==null&&e(q,{error:F,shardKey:r,testId:"agents-error"}),e("p",{className:"text-sm text-muted-foreground",children:t("Agents run as durable workflows. Each run persists a thread of assistant and tool messages; select a thread to inspect its timeline, tool calls, approvals, and token usage.")}),J!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"agents-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")}),g]})};export{Ee as default};
1
+ import{c as te}from"react/compiler-runtime";import{useState as se}from"react";import{E as q}from"../packem_shared/error-alert-BxCd81tw.mjs";import{B as A}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as $}from"../packem_shared/button-q0UYSmrn.mjs";import{C as M,a as j}from"../packem_shared/card-By2O8ULa.mjs";import{E as K}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as L,a as P,b as f,c as o,d as U,e as d}from"../packem_shared/table-D0SBiDu-.mjs";import{u as x}from"../packem_shared/use-admin-query-DMnTt_hg.mjs";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as v}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{c as ae}from"../packem_shared/internal-BT5tH08j.mjs";import{jsx as e,jsxs as l}from"react/jsx-runtime";const Q="agent_threads",re="agent_messages",D="agent_run_queue",_=100,y=250,ne={},oe={filters:[],limit:_,offset:0,orderBy:{column:"updatedAt",direction:"desc"},skipCount:!0,table:Q},c=(r,t)=>{const s=r[t];return typeof s=="string"?s:void 0},E=(r,t)=>{const s=r[t];return typeof s=="number"?s:void 0},H=r=>{const{usage:t}=r;if(t===null||typeof t!="object")return;const{totalTokens:s}=t;return typeof s=="number"?s:void 0},de=r=>{const{toolCalls:t}=r;return Array.isArray(t)?t.map(s=>s!==null&&typeof s=="object"?s.name:void 0).filter(s=>typeof s=="string"):[]},le=r=>{switch(r){case"awaiting_input":return"warning";case"cancelled":return"warning";case"error":return"destructive";case"running":return"info";default:return"outline"}},ie=r=>{switch(r){case"approved":return"success";case"rejected":return"destructive";default:return"warning"}},ce=r=>{const t=te(3),{fetched:s}=r,u=G();let i;return t[0]!==s||t[1]!==u?(i=s<=y?null:e("p",{className:"text-xs text-muted-foreground","data-testid":"agents-messages-truncated",children:u("Showing the latest {count} messages; older ones are not shown.",{count:y})}),t[0]=s,t[1]=u,t[2]=i):i=t[2],i},Ee=({initialShardKey:r=""})=>{const t=G(),[s,u]=se(void 0),{data:i}=x(v.listTables,ne,{live:!0,shardKey:r}),z=i!==void 0,h=Array.isArray(i)&&i.some(a=>a.name===Q),O=Array.isArray(i)&&i.some(a=>a.name===D),{data:S,error:V,errorSource:F,liveError:J}=x(v.readTablePage,oe,{enabled:h,live:!0,shardKey:r}),W={filters:[{column:"threadKey",operator:"eq",value:s??""}],limit:y+1,offset:0,orderBy:{column:"seq",direction:"desc"},skipCount:!0,table:re},{data:w}=x(v.readTablePage,{limit:_,offset:0,orderBy:{column:"position",direction:"asc"},skipCount:!0,table:D},{enabled:O,live:!0,shardKey:r}),{data:k,error:X,errorSource:Y}=x(v.readTablePage,W,{enabled:h&&s!==void 0,live:!0,shardKey:r}),b=Array.isArray(S?.rows)?S.rows:[],Z=Array.isArray(w?.rows)?w.rows:[],C=a=>Z.filter(n=>c(n,"threadKey")===a).length,B=Array.isArray(k?.rows)?k.rows:[],I=B.slice(0,y).toReversed(),R=b.find(a=>c(a,"key")===s);let g;return z&&!h?g=e(K,{description:t("No @lunora/agent tables found in this deployment. Add lunora/agents.ts with defineAgent(...) and merge the agent schema extension to run durable AI agents."),testId:"agents-unconfigured",title:t("No agents configured")}):h&&b.length===0?g=e(K,{description:t("No agent has run yet. Start a run with ctx.agents.<name>.run(...) and its thread appears here."),testId:"agents-empty",title:t("No agent threads yet")}):g=l("div",{className:"flex flex-col gap-6",children:[e(M,{className:"overflow-hidden py-0",children:e(j,{className:"px-0",children:l(L,{"data-testid":"agents-threads-table",children:[e(P,{children:l(f,{children:[e(o,{children:t("Agent")}),e(o,{children:t("Key")}),e(o,{children:t("Status")}),e(o,{children:t("Queued")}),e(o,{children:t("Messages")}),e(o,{children:t("Tokens")}),e(o,{children:t("Updated")}),e(o,{"aria-label":t("Actions")})]})}),e(U,{children:b.map(a=>{const n=c(a,"key")??"",m=c(a,"status"),p=H(a);return l(f,{"data-active":n===s?"":void 0,"data-testid":`agents-thread-${n}`,children:[e(d,{className:"font-mono text-xs",children:c(a,"agent")??"—"}),e(d,{className:"font-mono text-xs text-muted-foreground",children:n}),e(d,{children:e(A,{"data-testid":`agents-thread-status-${n}`,variant:le(m),children:m??"—"})}),e(d,{className:"tabular-nums",children:C(n)===0?e("span",{className:"text-muted-foreground",children:"—"}):e(A,{"data-testid":`agents-thread-queued-${n}`,variant:"warning",children:C(n)})}),e(d,{className:"tabular-nums",children:E(a,"messageCount")??"—"}),e(d,{className:"tabular-nums text-muted-foreground",children:p??"—"}),e(d,{className:"text-muted-foreground tabular-nums",children:ae(E(a,"updatedAt"),"—")}),e(d,{className:"text-right",children:e($,{"data-testid":`agents-thread-open-${n}`,onClick:()=>{u(n)},size:"sm",type:"button",variant:"outline",children:t("Timeline")})})]},n)})})]})})}),X!==null&&e(q,{error:Y,shardKey:r,testId:"agents-messages-error"}),s!==void 0&&e(M,{className:"overflow-hidden py-0","data-testid":"agents-thread-detail",children:l(j,{className:"flex flex-col gap-3 px-4 py-3",children:[l("div",{className:"flex items-center justify-between gap-2",children:[l("span",{className:"font-mono text-xs",children:[t("Timeline")," · ",s,R!==void 0&&l("span",{className:"text-muted-foreground",children:[" · ",t("Usage"),": ",H(R)??0," ",t("Tokens")]})]}),e($,{"data-testid":"agents-thread-detail-close",onClick:()=>{u(void 0)},size:"xs",type:"button",variant:"ghost",children:t("Close")})]}),e(ce,{fetched:B.length}),I.length===0?e("p",{className:"text-xs text-muted-foreground",children:t("This thread has no messages yet.")}):l(L,{"data-testid":"agents-messages-table",children:[e(P,{children:l(f,{children:[e(o,{children:t("Role")}),e(o,{children:t("Content")}),e(o,{children:t("Tool")}),e(o,{children:t("Approval")})]})}),e(U,{children:I.map((a,n)=>{const m=c(a,"role")??"—",p=de(a),ee=c(a,"toolName"),N=c(a,"status"),T=E(a,"seq")??n;return l(f,{"data-testid":`agents-message-${String(T)}`,children:[e(d,{className:"font-mono text-xs align-top text-muted-foreground",children:m}),e(d,{className:"max-w-md font-mono text-xs whitespace-pre-wrap break-words",children:c(a,"content")??"—"}),e(d,{className:"font-mono text-xs align-top text-muted-foreground",children:ee??(p.length>0?p.join(", "):"—")}),e(d,{className:"align-top",children:N===void 0?e("span",{className:"text-xs text-muted-foreground",children:"—"}):e(A,{"data-testid":`agents-message-approval-${String(T)}`,variant:ie(N),children:N})})]},c(a,"messageKey")??`${m}:${String(T)}`)})})]})]})})]}),l("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[V!==null&&e(q,{error:F,shardKey:r,testId:"agents-error"}),e("p",{className:"text-sm text-muted-foreground",children:t("Agents run as durable workflows. Each run persists a thread of assistant and tool messages; select a thread to inspect its timeline, tool calls, approvals, and token usage.")}),J!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"agents-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")}),g]})};export{Ee as default};
@@ -1 +1 @@
1
- import{c as E}from"react/compiler-runtime";import{E as de}from"../packem_shared/error-alert-3AR_-s_s.mjs";import{ShardInput as ue}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{S as U}from"../packem_shared/stat-card-BAv73QtB.mjs";import{B}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as D,a as me,b as te,c as se}from"../packem_shared/card-By2O8ULa.mjs";import{E as pe}from"../packem_shared/empty-state-D7jEML_T.mjs";import{c as _,a as oe,b as R,e as M,d as ne,T as re}from"../packem_shared/table-D0SBiDu-.mjs";import{u as X}from"../packem_shared/use-admin-query-CaOm4JS3.mjs";import{u as fe}from"../packem_shared/use-open-trace-BJKMJjeS.mjs";import{u as he}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as w}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as z}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{h as Te}from"../packem_shared/internal-hIuTpSbx.mjs";import{f as $,a as O}from"../packem_shared/metrics-format-1sNGG47R.mjs";import{S as ve}from"../packem_shared/sparkline-B_sPPO_8.mjs";import{jsx as r,jsxs as I,Fragment as ke}from"react/jsx-runtime";const H="gen_ai.usage.input_tokens",W="gen_ai.usage.output_tokens",j="gen_ai.usage.cost",ie="gen_ai.request.model",ye="lunora.usage.cost.source",Ce=new Set(["ai.embed","ai.generate","ai.stream"]),G=6e4,be=1440,le="unknown",q=()=>({calls:0,estimatedCost:0,inputTokens:0,outputTokens:0,providerCost:0}),J=(o,e)=>{const s=o?.[e];return typeof s=="string"&&s!==""?s:void 0},L=(o,e)=>{const s=o?.[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},Q=o=>J(o,ye)==="provider"?"provider":"estimated",Y=(o,e)=>o.reduce((s,n)=>s+e(n),0),F=o=>o.providerCost+o.estimatedCost,ae=o=>o.estimatedCost>0?o.providerCost>0?"mixed":"estimated":o.providerCost>0?"provider":"none",ce=(o,e)=>({calls:o.calls+e.calls,estimatedCost:o.estimatedCost+e.estimatedCost,inputTokens:o.inputTokens+e.inputTokens,outputTokens:o.outputTokens+e.outputTokens,providerCost:o.providerCost+e.providerCost}),ge=o=>{const e=q();let s=0,n=0,t=0;for(const c of o){const l=Y(c.points,a=>a.sum),i=Y(c.points,a=>a.count);c.name===H?(e.inputTokens+=l,s+=i):c.name===W?(e.outputTokens+=l,n+=i):(t+=i,Q(c.attributes)==="provider"?e.providerCost+=l:e.estimatedCost+=l)}return e.calls=Math.max(s,n,t),e},Ne=(o,e)=>F(e)-F(o)||e.inputTokens+e.outputTokens-(o.inputTokens+o.outputTokens)||o.key.localeCompare(e.key),Z=(o,e)=>{const s=new Map;for(const n of o){const t=e(n);s.set(t,{key:t,...ce(s.get(t)??q(),n)})}return[...s.values()].toSorted(Ne)},xe=o=>(o?.series??[]).filter(e=>e.name===H||e.name===W||e.name===j),Se=o=>J(o.attributes,ie)??le,Ie=o=>{const e=new Map;for(const s of o){const n=Se(s),t=JSON.stringify([s.functionPath,n]),c=e.get(t)??{functionPath:s.functionPath,model:n,series:[]};c.series.push(s),e.set(t,c)}return[...e.values()].map(({functionPath:s,model:n,series:t})=>({functionPath:s,model:n,...ge(t)}))},_e=o=>{const e=new Map;for(const i of o){if(i.name!==j)continue;const a=Q(i.attributes)==="provider";for(const u of i.points){const m=e.get(u.bucketMs)??{bucketMs:u.bucketMs,estimatedCost:0,providerCost:0};a?m.providerCost+=u.sum:m.estimatedCost+=u.sum,e.set(u.bucketMs,m)}}const s=[...e.keys()].toSorted((i,a)=>i-a),n=s[0],t=s.at(-1);if(n===void 0||t===void 0)return[];const c=Math.max(n,t-(be-1)*G),l=[];for(let i=c;i<=t;i+=G)l.push(e.get(i)??{bucketMs:i,estimatedCost:0,providerCost:0});return l},Me=o=>{const e=[];for(const s of o)for(const n of s.spans){if(!Ce.has(n.name))continue;const{attributes:t}=n,c=L(t,j),l=L(t,H),i=L(t,W);e.push({...c===void 0?{}:{cost:c,costSource:Q(t)},functionPath:s.functionPath,...l===void 0?{}:{inputTokens:l},model:J(t,ie)??le,ok:n.ok,...i===void 0?{}:{outputTokens:i},startTs:s.startTs+n.offsetMs,streaming:n.name==="ai.stream",traceId:s.traceId})}return e.toSorted((s,n)=>n.startTs-s.startTs)},Oe=o=>o.map(e=>{const s=e.cost??0;return{calls:1,estimatedCost:e.costSource==="provider"?0:s,functionPath:e.functionPath,inputTokens:e.inputTokens??0,model:e.model,outputTokens:e.outputTokens??0,providerCost:e.costSource==="provider"?s:0}}),Ae=(o,e)=>{const s=xe(o),n=Me(e),t=s.length>0,c=t?Ie(s):Oe(n);let l=q(),i="none";for(const a of c)l=ce(l,a);return t?i="history":n.length>0&&(i="live"),{byFunction:Z(c,a=>a.functionPath),byModel:Z(c,a=>a.model),calls:n,source:i,totals:l,trend:t?_e(s):[]}},Ee=o=>Array.isArray(o?.traces)?o.traces:[],we=25,V=o=>{const e=E(16),{provenance:s,value:n}=o,t=w();if(s==="none"){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=r("span",{className:"text-muted-foreground",children:"—"}),e[0]=m):m=e[0],m}let c;e[1]!==s||e[2]!==n?(c=s==="provider"?$(n):`~${$(n)}`,e[1]=s,e[2]=n,e[3]=c):c=e[3];let l;e[4]!==c?(l=r("span",{className:"tabular-nums",children:c}),e[4]=c,e[5]=l):l=e[5];let i;e[6]!==s||e[7]!==t?(i=s==="estimated"?r(B,{title:t("Derived from a price table, not reported by the provider."),variant:"warning",children:t("Estimated")}):null,e[6]=s,e[7]=t,e[8]=i):i=e[8];let a;e[9]!==s||e[10]!==t?(a=s==="mixed"?r(B,{title:t("Includes cost derived from a price table, not reported by the provider."),variant:"warning",children:t("Partly estimated")}):null,e[9]=s,e[10]=t,e[11]=a):a=e[11];let u;return e[12]!==l||e[13]!==i||e[14]!==a?(u=I("span",{className:"inline-flex items-center gap-2",children:[l,i,a]}),e[12]=l,e[13]=i,e[14]=a,e[15]=u):u=e[15],u},ee=o=>{const e=E(40),{keyLabel:s,rows:n,testId:t,title:c}=o,l=w();let i;e[0]!==c?(i=r(te,{className:"px-4 py-3",children:r(se,{children:c})}),e[0]=c,e[1]=i):i=e[1];let a;e[2]!==s?(a=r(_,{children:s}),e[2]=s,e[3]=a):a=e[3];let u;e[4]!==l?(u=l("Calls"),e[4]=l,e[5]=u):u=e[5];let m;e[6]!==u?(m=r(_,{className:"text-end",children:u}),e[6]=u,e[7]=m):m=e[7];let T;e[8]!==l?(T=l("Input tokens"),e[8]=l,e[9]=T):T=e[9];let v;e[10]!==T?(v=r(_,{className:"text-end",children:T}),e[10]=T,e[11]=v):v=e[11];let k;e[12]!==l?(k=l("Output tokens"),e[12]=l,e[13]=k):k=e[13];let C;e[14]!==k?(C=r(_,{className:"text-end",children:k}),e[14]=k,e[15]=C):C=e[15];let y;e[16]!==l?(y=l("Cost"),e[16]=l,e[17]=y):y=e[17];let d;e[18]!==y?(d=r(_,{className:"text-end",children:y}),e[18]=y,e[19]=d):d=e[19];let b;e[20]!==d||e[21]!==a||e[22]!==m||e[23]!==v||e[24]!==C?(b=r(oe,{children:I(R,{children:[a,m,v,C,d]})}),e[20]=d,e[21]=a,e[22]=m,e[23]=v,e[24]=C,e[25]=b):b=e[25];let p;if(e[26]!==n||e[27]!==t){let x;e[29]!==t?(x=S=>I(R,{"data-testid":`${t}-row`,children:[r(M,{className:"max-w-[280px] truncate font-mono",title:S.key,children:S.key}),r(M,{className:"text-end tabular-nums",children:O(S.calls)}),r(M,{className:"text-end tabular-nums",children:O(S.inputTokens)}),r(M,{className:"text-end tabular-nums",children:O(S.outputTokens)}),r(M,{className:"text-end",children:r(V,{provenance:ae(S),value:F(S)})})]},S.key),e[29]=t,e[30]=x):x=e[30],p=n.map(x),e[26]=n,e[27]=t,e[28]=p}else p=e[28];let f;e[31]!==p?(f=r(ne,{children:p}),e[31]=p,e[32]=f):f=e[32];let h;e[33]!==b||e[34]!==f?(h=I(re,{children:[b,f]}),e[33]=b,e[34]=f,e[35]=h):h=e[35];let g;return e[36]!==i||e[37]!==h||e[38]!==t?(g=I(D,{className:"gap-0 py-0","data-testid":t,children:[i,h]}),e[36]=i,e[37]=h,e[38]=t,e[39]=g):g=e[39],g},Pe=o=>{const e=E(55),{calls:s,onOpenTrace:n}=o,t=w();let c;e[0]!==t?(c=t("Recent calls"),e[0]=t,e[1]=c):c=e[1];let l;e[2]!==c?(l=r(te,{className:"px-4 py-3",children:r(se,{children:c})}),e[2]=c,e[3]=l):l=e[3];let i;e[4]!==t?(i=t("When"),e[4]=t,e[5]=i):i=e[5];let a;e[6]!==i?(a=r(_,{children:i}),e[6]=i,e[7]=a):a=e[7];let u;e[8]!==t?(u=t("Function"),e[8]=t,e[9]=u):u=e[9];let m;e[10]!==u?(m=r(_,{children:u}),e[10]=u,e[11]=m):m=e[11];let T;e[12]!==t?(T=t("Model"),e[12]=t,e[13]=T):T=e[13];let v;e[14]!==T?(v=r(_,{children:T}),e[14]=T,e[15]=v):v=e[15];let k;e[16]!==t?(k=t("Input tokens"),e[16]=t,e[17]=k):k=e[17];let C;e[18]!==k?(C=r(_,{className:"text-end",children:k}),e[18]=k,e[19]=C):C=e[19];let y;e[20]!==t?(y=t("Output tokens"),e[20]=t,e[21]=y):y=e[21];let d;e[22]!==y?(d=r(_,{className:"text-end",children:y}),e[22]=y,e[23]=d):d=e[23];let b;e[24]!==t?(b=t("Cost"),e[24]=t,e[25]=b):b=e[25];let p;e[26]!==b?(p=r(_,{className:"text-end",children:b}),e[26]=b,e[27]=p):p=e[27];let f;e[28]!==t?(f=t("Trace"),e[28]=t,e[29]=f):f=e[29];let h;e[30]!==f?(h=r(_,{children:f}),e[30]=f,e[31]=h):h=e[31];let g;e[32]!==C||e[33]!==d||e[34]!==p||e[35]!==h||e[36]!==a||e[37]!==m||e[38]!==v?(g=r(oe,{children:I(R,{children:[a,m,v,C,d,p,h]})}),e[32]=C,e[33]=d,e[34]=p,e[35]=h,e[36]=a,e[37]=m,e[38]=v,e[39]=g):g=e[39];let x;if(e[40]!==s||e[41]!==n||e[42]!==t){let K;e[44]!==n||e[45]!==t?(K=N=>I(R,{"data-testid":"ai-call",children:[r(M,{className:"font-mono text-muted-foreground",children:Te(N.startTs)}),r(M,{className:"font-mono",children:I("span",{className:"inline-flex items-center gap-2",children:[N.functionPath,N.streaming?r(B,{variant:"outline",children:t("stream")}):null,N.ok?null:r(B,{variant:"destructive",children:t("failed")})]})}),r(M,{className:"max-w-[240px] truncate font-mono",title:N.model,children:N.model}),r(M,{className:"text-end tabular-nums",children:N.inputTokens===void 0?"—":O(N.inputTokens)}),r(M,{className:"text-end tabular-nums",children:N.outputTokens===void 0?"—":O(N.outputTokens)}),r(M,{className:"text-end",children:r(V,{provenance:N.cost===void 0?"none":N.costSource??"estimated",value:N.cost??0})}),r(M,{children:r("button",{className:"font-mono text-muted-foreground underline-offset-2 hover:underline",onClick:()=>{n(N.traceId)},title:t("Open the trace {trace}",{trace:N.traceId}),type:"button",children:N.traceId.slice(0,8)})})]},`${N.traceId}:${N.startTs.toString()}:${N.model}`),e[44]=n,e[45]=t,e[46]=K):K=e[46],x=s.slice(0,we).map(K),e[40]=s,e[41]=n,e[42]=t,e[43]=x}else x=e[43];let S;e[47]!==x?(S=r(ne,{children:x}),e[47]=x,e[48]=S):S=e[48];let A;e[49]!==g||e[50]!==S?(A=I(re,{children:[g,S]}),e[49]=g,e[50]=S,e[51]=A):A=e[51];let P;return e[52]!==l||e[53]!==A?(P=I(D,{className:"gap-0 py-0","data-testid":"ai-calls",children:[l,A]}),e[52]=l,e[53]=A,e[54]=P):P=e[54],P},Ke=o=>{const e=E(48),{totals:s,trend:n}=o,t=w();let c;e[0]!==s?(c=ae(s),e[0]=s,e[1]=c):c=e[1];const l=c;let i;e[2]!==t||e[3]!==n?(i=n.length>=2?r(ve,{ariaLabel:t("Cost per minute"),className:"h-7 w-24",series:n,testId:"ai-trend"}):void 0,e[2]=t,e[3]=n,e[4]=i):i=e[4];let a;e[5]!==l||e[6]!==t||e[7]!==s.estimatedCost||e[8]!==s.providerCost?(a=l==="none"?t("No cost reported"):r("span",{"data-testid":"ai-cost-split",children:t("{provider} provider-reported · {estimated} estimated",{estimated:$(s.estimatedCost),provider:$(s.providerCost)})}),e[5]=l,e[6]=t,e[7]=s.estimatedCost,e[8]=s.providerCost,e[9]=a):a=e[9];let u;e[10]!==t?(u=t("Total cost"),e[10]=t,e[11]=u):u=e[11];let m;e[12]!==s?(m=F(s),e[12]=s,e[13]=m):m=e[13];let T;e[14]!==l||e[15]!==m?(T=r(V,{provenance:l,value:m}),e[14]=l,e[15]=m,e[16]=T):T=e[16];let v;e[17]!==i||e[18]!==a||e[19]!==u||e[20]!==T?(v=r(U,{chart:i,footer:a,label:u,testId:"ai-total-cost",value:T}),e[17]=i,e[18]=a,e[19]=u,e[20]=T,e[21]=v):v=e[21];let k;e[22]!==t?(k=t("Input tokens"),e[22]=t,e[23]=k):k=e[23];let C;e[24]!==s.inputTokens?(C=O(s.inputTokens),e[24]=s.inputTokens,e[25]=C):C=e[25];let y;e[26]!==k||e[27]!==C?(y=r(U,{label:k,testId:"ai-input-tokens",value:C}),e[26]=k,e[27]=C,e[28]=y):y=e[28];let d;e[29]!==t?(d=t("Output tokens"),e[29]=t,e[30]=d):d=e[30];let b;e[31]!==s.outputTokens?(b=O(s.outputTokens),e[31]=s.outputTokens,e[32]=b):b=e[32];let p;e[33]!==d||e[34]!==b?(p=r(U,{label:d,testId:"ai-output-tokens",value:b}),e[33]=d,e[34]=b,e[35]=p):p=e[35];let f;e[36]!==t?(f=t("Calls"),e[36]=t,e[37]=f):f=e[37];let h;e[38]!==s.calls?(h=O(s.calls),e[38]=s.calls,e[39]=h):h=e[39];let g;e[40]!==f||e[41]!==h?(g=r(U,{label:f,testId:"ai-calls-total",value:h}),e[40]=f,e[41]=h,e[42]=g):g=e[42];let x;return e[43]!==y||e[44]!==p||e[45]!==g||e[46]!==v?(x=I("dl",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"ai-totals",children:[v,y,p,g]}),e[43]=y,e[44]=p,e[45]=g,e[46]=v,e[47]=x):x=e[47],x},Ze=o=>{const e=E(29),{initialShardKey:s}=o,n=w(),{queryShardKey:t,setShardKey:c,shardKey:l}=he(s),i=fe(t);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={},e[0]=a):a=e[0];let u;e[1]!==t?(u={live:!0,shardKey:t},e[1]=t,e[2]=u):u=e[2];const{data:m,error:T}=X(z.getTraces,a,u);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v={},e[3]=v):v=e[3];let k;e[4]!==t?(k={live:!0,shardKey:t},e[4]=t,e[5]=k):k=e[5];const{data:C}=X(z.getMetricHistory,v,k);let y,d;e[6]!==m||e[7]!==C?(d=Ae(C,Ee(m)),y=d.trend.map(Ue),e[6]=m,e[7]=C,e[8]=y,e[9]=d):(y=e[8],d=e[9]);const b=y;let p;e[10]!==c||e[11]!==l?(p=r(ue,{onChange:c,testId:"ai-shard-input",value:l}),e[10]=c,e[11]=l,e[12]=p):p=e[12];let f;e[13]!==T||e[14]!==t?(f=T===null?null:r(de,{error:T,shardKey:t,testId:"ai-error"}),e[13]=T,e[14]=t,e[15]=f):f=e[15];let h;e[16]!==i||e[17]!==n||e[18]!==b||e[19]!==d.byFunction||e[20]!==d.byModel||e[21]!==d.calls||e[22]!==d.source||e[23]!==d.totals?(h=d.source==="none"?r(pe,{description:n("Spend shows up here once an action calls ctx.ai.model(...) — tokens and cost per function and per model."),testId:"ai-empty",title:n("No AI usage recorded")}):I(ke,{children:[d.source==="live"?r("p",{className:"text-xs text-muted-foreground","data-testid":"ai-live-only",children:n("No durable history yet — these totals come from the live trace ring and reset when the shard hibernates.")}):r("p",{className:"text-xs text-muted-foreground","data-testid":"ai-window",children:n("Totals cover the retained metric history (up to the last 24 hours).")}),r(Ke,{totals:d.totals,trend:b}),I("div",{className:"grid gap-3 xl:grid-cols-2",children:[r(ee,{keyLabel:n("Function"),rows:d.byFunction,testId:"ai-by-function",title:n("By function")}),r(ee,{keyLabel:n("Model"),rows:d.byModel,testId:"ai-by-model",title:n("By model")})]}),d.calls.length===0?r(D,{children:r(me,{className:"p-4 text-xs text-muted-foreground","data-testid":"ai-no-calls",children:n("No recent calls in the live trace ring — it empties when the shard hibernates.")})}):r(Pe,{calls:d.calls,onOpenTrace:i})]}),e[16]=i,e[17]=n,e[18]=b,e[19]=d.byFunction,e[20]=d.byModel,e[21]=d.calls,e[22]=d.source,e[23]=d.totals,e[24]=h):h=e[24];let g;return e[25]!==p||e[26]!==f||e[27]!==h?(g=I("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[p,f,h]}),e[25]=p,e[26]=f,e[27]=h,e[28]=g):g=e[28],g};function Ue(o){return o.providerCost+o.estimatedCost}export{Ze as default};
1
+ import{c as E}from"react/compiler-runtime";import{E as de}from"../packem_shared/error-alert-BxCd81tw.mjs";import{ShardInput as ue}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{S as U}from"../packem_shared/stat-card-BAv73QtB.mjs";import{B}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as D,a as me,b as te,c as se}from"../packem_shared/card-By2O8ULa.mjs";import{E as pe}from"../packem_shared/empty-state-D7jEML_T.mjs";import{c as _,a as oe,b as R,e as M,d as ne,T as re}from"../packem_shared/table-D0SBiDu-.mjs";import{u as X}from"../packem_shared/use-admin-query-DMnTt_hg.mjs";import{u as fe}from"../packem_shared/use-open-trace-trRfFb77.mjs";import{u as he}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as w}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as z}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{c as Te}from"../packem_shared/internal-BT5tH08j.mjs";import{f as $,a as O}from"../packem_shared/metrics-format-1sNGG47R.mjs";import{S as ve}from"../packem_shared/sparkline-B_sPPO_8.mjs";import{jsx as r,jsxs as I,Fragment as ke}from"react/jsx-runtime";const H="gen_ai.usage.input_tokens",W="gen_ai.usage.output_tokens",j="gen_ai.usage.cost",ie="gen_ai.request.model",ye="lunora.usage.cost.source",Ce=new Set(["ai.embed","ai.generate","ai.stream"]),G=6e4,be=1440,le="unknown",q=()=>({calls:0,estimatedCost:0,inputTokens:0,outputTokens:0,providerCost:0}),J=(o,e)=>{const s=o?.[e];return typeof s=="string"&&s!==""?s:void 0},L=(o,e)=>{const s=o?.[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},Q=o=>J(o,ye)==="provider"?"provider":"estimated",Y=(o,e)=>o.reduce((s,n)=>s+e(n),0),F=o=>o.providerCost+o.estimatedCost,ae=o=>o.estimatedCost>0?o.providerCost>0?"mixed":"estimated":o.providerCost>0?"provider":"none",ce=(o,e)=>({calls:o.calls+e.calls,estimatedCost:o.estimatedCost+e.estimatedCost,inputTokens:o.inputTokens+e.inputTokens,outputTokens:o.outputTokens+e.outputTokens,providerCost:o.providerCost+e.providerCost}),ge=o=>{const e=q();let s=0,n=0,t=0;for(const c of o){const l=Y(c.points,a=>a.sum),i=Y(c.points,a=>a.count);c.name===H?(e.inputTokens+=l,s+=i):c.name===W?(e.outputTokens+=l,n+=i):(t+=i,Q(c.attributes)==="provider"?e.providerCost+=l:e.estimatedCost+=l)}return e.calls=Math.max(s,n,t),e},Ne=(o,e)=>F(e)-F(o)||e.inputTokens+e.outputTokens-(o.inputTokens+o.outputTokens)||o.key.localeCompare(e.key),Z=(o,e)=>{const s=new Map;for(const n of o){const t=e(n);s.set(t,{key:t,...ce(s.get(t)??q(),n)})}return[...s.values()].toSorted(Ne)},xe=o=>(o?.series??[]).filter(e=>e.name===H||e.name===W||e.name===j),Se=o=>J(o.attributes,ie)??le,Ie=o=>{const e=new Map;for(const s of o){const n=Se(s),t=JSON.stringify([s.functionPath,n]),c=e.get(t)??{functionPath:s.functionPath,model:n,series:[]};c.series.push(s),e.set(t,c)}return[...e.values()].map(({functionPath:s,model:n,series:t})=>({functionPath:s,model:n,...ge(t)}))},_e=o=>{const e=new Map;for(const i of o){if(i.name!==j)continue;const a=Q(i.attributes)==="provider";for(const u of i.points){const m=e.get(u.bucketMs)??{bucketMs:u.bucketMs,estimatedCost:0,providerCost:0};a?m.providerCost+=u.sum:m.estimatedCost+=u.sum,e.set(u.bucketMs,m)}}const s=[...e.keys()].toSorted((i,a)=>i-a),n=s[0],t=s.at(-1);if(n===void 0||t===void 0)return[];const c=Math.max(n,t-(be-1)*G),l=[];for(let i=c;i<=t;i+=G)l.push(e.get(i)??{bucketMs:i,estimatedCost:0,providerCost:0});return l},Me=o=>{const e=[];for(const s of o)for(const n of s.spans){if(!Ce.has(n.name))continue;const{attributes:t}=n,c=L(t,j),l=L(t,H),i=L(t,W);e.push({...c===void 0?{}:{cost:c,costSource:Q(t)},functionPath:s.functionPath,...l===void 0?{}:{inputTokens:l},model:J(t,ie)??le,ok:n.ok,...i===void 0?{}:{outputTokens:i},startTs:s.startTs+n.offsetMs,streaming:n.name==="ai.stream",traceId:s.traceId})}return e.toSorted((s,n)=>n.startTs-s.startTs)},Oe=o=>o.map(e=>{const s=e.cost??0;return{calls:1,estimatedCost:e.costSource==="provider"?0:s,functionPath:e.functionPath,inputTokens:e.inputTokens??0,model:e.model,outputTokens:e.outputTokens??0,providerCost:e.costSource==="provider"?s:0}}),Ae=(o,e)=>{const s=xe(o),n=Me(e),t=s.length>0,c=t?Ie(s):Oe(n);let l=q(),i="none";for(const a of c)l=ce(l,a);return t?i="history":n.length>0&&(i="live"),{byFunction:Z(c,a=>a.functionPath),byModel:Z(c,a=>a.model),calls:n,source:i,totals:l,trend:t?_e(s):[]}},Ee=o=>Array.isArray(o?.traces)?o.traces:[],we=25,V=o=>{const e=E(16),{provenance:s,value:n}=o,t=w();if(s==="none"){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=r("span",{className:"text-muted-foreground",children:"—"}),e[0]=m):m=e[0],m}let c;e[1]!==s||e[2]!==n?(c=s==="provider"?$(n):`~${$(n)}`,e[1]=s,e[2]=n,e[3]=c):c=e[3];let l;e[4]!==c?(l=r("span",{className:"tabular-nums",children:c}),e[4]=c,e[5]=l):l=e[5];let i;e[6]!==s||e[7]!==t?(i=s==="estimated"?r(B,{title:t("Derived from a price table, not reported by the provider."),variant:"warning",children:t("Estimated")}):null,e[6]=s,e[7]=t,e[8]=i):i=e[8];let a;e[9]!==s||e[10]!==t?(a=s==="mixed"?r(B,{title:t("Includes cost derived from a price table, not reported by the provider."),variant:"warning",children:t("Partly estimated")}):null,e[9]=s,e[10]=t,e[11]=a):a=e[11];let u;return e[12]!==l||e[13]!==i||e[14]!==a?(u=I("span",{className:"inline-flex items-center gap-2",children:[l,i,a]}),e[12]=l,e[13]=i,e[14]=a,e[15]=u):u=e[15],u},ee=o=>{const e=E(40),{keyLabel:s,rows:n,testId:t,title:c}=o,l=w();let i;e[0]!==c?(i=r(te,{className:"px-4 py-3",children:r(se,{children:c})}),e[0]=c,e[1]=i):i=e[1];let a;e[2]!==s?(a=r(_,{children:s}),e[2]=s,e[3]=a):a=e[3];let u;e[4]!==l?(u=l("Calls"),e[4]=l,e[5]=u):u=e[5];let m;e[6]!==u?(m=r(_,{className:"text-end",children:u}),e[6]=u,e[7]=m):m=e[7];let T;e[8]!==l?(T=l("Input tokens"),e[8]=l,e[9]=T):T=e[9];let v;e[10]!==T?(v=r(_,{className:"text-end",children:T}),e[10]=T,e[11]=v):v=e[11];let k;e[12]!==l?(k=l("Output tokens"),e[12]=l,e[13]=k):k=e[13];let C;e[14]!==k?(C=r(_,{className:"text-end",children:k}),e[14]=k,e[15]=C):C=e[15];let y;e[16]!==l?(y=l("Cost"),e[16]=l,e[17]=y):y=e[17];let d;e[18]!==y?(d=r(_,{className:"text-end",children:y}),e[18]=y,e[19]=d):d=e[19];let b;e[20]!==d||e[21]!==a||e[22]!==m||e[23]!==v||e[24]!==C?(b=r(oe,{children:I(R,{children:[a,m,v,C,d]})}),e[20]=d,e[21]=a,e[22]=m,e[23]=v,e[24]=C,e[25]=b):b=e[25];let p;if(e[26]!==n||e[27]!==t){let x;e[29]!==t?(x=S=>I(R,{"data-testid":`${t}-row`,children:[r(M,{className:"max-w-[280px] truncate font-mono",title:S.key,children:S.key}),r(M,{className:"text-end tabular-nums",children:O(S.calls)}),r(M,{className:"text-end tabular-nums",children:O(S.inputTokens)}),r(M,{className:"text-end tabular-nums",children:O(S.outputTokens)}),r(M,{className:"text-end",children:r(V,{provenance:ae(S),value:F(S)})})]},S.key),e[29]=t,e[30]=x):x=e[30],p=n.map(x),e[26]=n,e[27]=t,e[28]=p}else p=e[28];let f;e[31]!==p?(f=r(ne,{children:p}),e[31]=p,e[32]=f):f=e[32];let h;e[33]!==b||e[34]!==f?(h=I(re,{children:[b,f]}),e[33]=b,e[34]=f,e[35]=h):h=e[35];let g;return e[36]!==i||e[37]!==h||e[38]!==t?(g=I(D,{className:"gap-0 py-0","data-testid":t,children:[i,h]}),e[36]=i,e[37]=h,e[38]=t,e[39]=g):g=e[39],g},Pe=o=>{const e=E(55),{calls:s,onOpenTrace:n}=o,t=w();let c;e[0]!==t?(c=t("Recent calls"),e[0]=t,e[1]=c):c=e[1];let l;e[2]!==c?(l=r(te,{className:"px-4 py-3",children:r(se,{children:c})}),e[2]=c,e[3]=l):l=e[3];let i;e[4]!==t?(i=t("When"),e[4]=t,e[5]=i):i=e[5];let a;e[6]!==i?(a=r(_,{children:i}),e[6]=i,e[7]=a):a=e[7];let u;e[8]!==t?(u=t("Function"),e[8]=t,e[9]=u):u=e[9];let m;e[10]!==u?(m=r(_,{children:u}),e[10]=u,e[11]=m):m=e[11];let T;e[12]!==t?(T=t("Model"),e[12]=t,e[13]=T):T=e[13];let v;e[14]!==T?(v=r(_,{children:T}),e[14]=T,e[15]=v):v=e[15];let k;e[16]!==t?(k=t("Input tokens"),e[16]=t,e[17]=k):k=e[17];let C;e[18]!==k?(C=r(_,{className:"text-end",children:k}),e[18]=k,e[19]=C):C=e[19];let y;e[20]!==t?(y=t("Output tokens"),e[20]=t,e[21]=y):y=e[21];let d;e[22]!==y?(d=r(_,{className:"text-end",children:y}),e[22]=y,e[23]=d):d=e[23];let b;e[24]!==t?(b=t("Cost"),e[24]=t,e[25]=b):b=e[25];let p;e[26]!==b?(p=r(_,{className:"text-end",children:b}),e[26]=b,e[27]=p):p=e[27];let f;e[28]!==t?(f=t("Trace"),e[28]=t,e[29]=f):f=e[29];let h;e[30]!==f?(h=r(_,{children:f}),e[30]=f,e[31]=h):h=e[31];let g;e[32]!==C||e[33]!==d||e[34]!==p||e[35]!==h||e[36]!==a||e[37]!==m||e[38]!==v?(g=r(oe,{children:I(R,{children:[a,m,v,C,d,p,h]})}),e[32]=C,e[33]=d,e[34]=p,e[35]=h,e[36]=a,e[37]=m,e[38]=v,e[39]=g):g=e[39];let x;if(e[40]!==s||e[41]!==n||e[42]!==t){let K;e[44]!==n||e[45]!==t?(K=N=>I(R,{"data-testid":"ai-call",children:[r(M,{className:"font-mono text-muted-foreground",children:Te(N.startTs)}),r(M,{className:"font-mono",children:I("span",{className:"inline-flex items-center gap-2",children:[N.functionPath,N.streaming?r(B,{variant:"outline",children:t("stream")}):null,N.ok?null:r(B,{variant:"destructive",children:t("failed")})]})}),r(M,{className:"max-w-[240px] truncate font-mono",title:N.model,children:N.model}),r(M,{className:"text-end tabular-nums",children:N.inputTokens===void 0?"—":O(N.inputTokens)}),r(M,{className:"text-end tabular-nums",children:N.outputTokens===void 0?"—":O(N.outputTokens)}),r(M,{className:"text-end",children:r(V,{provenance:N.cost===void 0?"none":N.costSource??"estimated",value:N.cost??0})}),r(M,{children:r("button",{className:"font-mono text-muted-foreground underline-offset-2 hover:underline",onClick:()=>{n(N.traceId)},title:t("Open the trace {trace}",{trace:N.traceId}),type:"button",children:N.traceId.slice(0,8)})})]},`${N.traceId}:${N.startTs.toString()}:${N.model}`),e[44]=n,e[45]=t,e[46]=K):K=e[46],x=s.slice(0,we).map(K),e[40]=s,e[41]=n,e[42]=t,e[43]=x}else x=e[43];let S;e[47]!==x?(S=r(ne,{children:x}),e[47]=x,e[48]=S):S=e[48];let A;e[49]!==g||e[50]!==S?(A=I(re,{children:[g,S]}),e[49]=g,e[50]=S,e[51]=A):A=e[51];let P;return e[52]!==l||e[53]!==A?(P=I(D,{className:"gap-0 py-0","data-testid":"ai-calls",children:[l,A]}),e[52]=l,e[53]=A,e[54]=P):P=e[54],P},Ke=o=>{const e=E(48),{totals:s,trend:n}=o,t=w();let c;e[0]!==s?(c=ae(s),e[0]=s,e[1]=c):c=e[1];const l=c;let i;e[2]!==t||e[3]!==n?(i=n.length>=2?r(ve,{ariaLabel:t("Cost per minute"),className:"h-7 w-24",series:n,testId:"ai-trend"}):void 0,e[2]=t,e[3]=n,e[4]=i):i=e[4];let a;e[5]!==l||e[6]!==t||e[7]!==s.estimatedCost||e[8]!==s.providerCost?(a=l==="none"?t("No cost reported"):r("span",{"data-testid":"ai-cost-split",children:t("{provider} provider-reported · {estimated} estimated",{estimated:$(s.estimatedCost),provider:$(s.providerCost)})}),e[5]=l,e[6]=t,e[7]=s.estimatedCost,e[8]=s.providerCost,e[9]=a):a=e[9];let u;e[10]!==t?(u=t("Total cost"),e[10]=t,e[11]=u):u=e[11];let m;e[12]!==s?(m=F(s),e[12]=s,e[13]=m):m=e[13];let T;e[14]!==l||e[15]!==m?(T=r(V,{provenance:l,value:m}),e[14]=l,e[15]=m,e[16]=T):T=e[16];let v;e[17]!==i||e[18]!==a||e[19]!==u||e[20]!==T?(v=r(U,{chart:i,footer:a,label:u,testId:"ai-total-cost",value:T}),e[17]=i,e[18]=a,e[19]=u,e[20]=T,e[21]=v):v=e[21];let k;e[22]!==t?(k=t("Input tokens"),e[22]=t,e[23]=k):k=e[23];let C;e[24]!==s.inputTokens?(C=O(s.inputTokens),e[24]=s.inputTokens,e[25]=C):C=e[25];let y;e[26]!==k||e[27]!==C?(y=r(U,{label:k,testId:"ai-input-tokens",value:C}),e[26]=k,e[27]=C,e[28]=y):y=e[28];let d;e[29]!==t?(d=t("Output tokens"),e[29]=t,e[30]=d):d=e[30];let b;e[31]!==s.outputTokens?(b=O(s.outputTokens),e[31]=s.outputTokens,e[32]=b):b=e[32];let p;e[33]!==d||e[34]!==b?(p=r(U,{label:d,testId:"ai-output-tokens",value:b}),e[33]=d,e[34]=b,e[35]=p):p=e[35];let f;e[36]!==t?(f=t("Calls"),e[36]=t,e[37]=f):f=e[37];let h;e[38]!==s.calls?(h=O(s.calls),e[38]=s.calls,e[39]=h):h=e[39];let g;e[40]!==f||e[41]!==h?(g=r(U,{label:f,testId:"ai-calls-total",value:h}),e[40]=f,e[41]=h,e[42]=g):g=e[42];let x;return e[43]!==y||e[44]!==p||e[45]!==g||e[46]!==v?(x=I("dl",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"ai-totals",children:[v,y,p,g]}),e[43]=y,e[44]=p,e[45]=g,e[46]=v,e[47]=x):x=e[47],x},Ze=o=>{const e=E(29),{initialShardKey:s}=o,n=w(),{queryShardKey:t,setShardKey:c,shardKey:l}=he(s),i=fe(t);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={},e[0]=a):a=e[0];let u;e[1]!==t?(u={live:!0,shardKey:t},e[1]=t,e[2]=u):u=e[2];const{data:m,error:T}=X(z.getTraces,a,u);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v={},e[3]=v):v=e[3];let k;e[4]!==t?(k={live:!0,shardKey:t},e[4]=t,e[5]=k):k=e[5];const{data:C}=X(z.getMetricHistory,v,k);let y,d;e[6]!==m||e[7]!==C?(d=Ae(C,Ee(m)),y=d.trend.map(Ue),e[6]=m,e[7]=C,e[8]=y,e[9]=d):(y=e[8],d=e[9]);const b=y;let p;e[10]!==c||e[11]!==l?(p=r(ue,{onChange:c,testId:"ai-shard-input",value:l}),e[10]=c,e[11]=l,e[12]=p):p=e[12];let f;e[13]!==T||e[14]!==t?(f=T===null?null:r(de,{error:T,shardKey:t,testId:"ai-error"}),e[13]=T,e[14]=t,e[15]=f):f=e[15];let h;e[16]!==i||e[17]!==n||e[18]!==b||e[19]!==d.byFunction||e[20]!==d.byModel||e[21]!==d.calls||e[22]!==d.source||e[23]!==d.totals?(h=d.source==="none"?r(pe,{description:n("Spend shows up here once an action calls ctx.ai.model(...) — tokens and cost per function and per model."),testId:"ai-empty",title:n("No AI usage recorded")}):I(ke,{children:[d.source==="live"?r("p",{className:"text-xs text-muted-foreground","data-testid":"ai-live-only",children:n("No durable history yet — these totals come from the live trace ring and reset when the shard hibernates.")}):r("p",{className:"text-xs text-muted-foreground","data-testid":"ai-window",children:n("Totals cover the retained metric history (up to the last 24 hours).")}),r(Ke,{totals:d.totals,trend:b}),I("div",{className:"grid gap-3 xl:grid-cols-2",children:[r(ee,{keyLabel:n("Function"),rows:d.byFunction,testId:"ai-by-function",title:n("By function")}),r(ee,{keyLabel:n("Model"),rows:d.byModel,testId:"ai-by-model",title:n("By model")})]}),d.calls.length===0?r(D,{children:r(me,{className:"p-4 text-xs text-muted-foreground","data-testid":"ai-no-calls",children:n("No recent calls in the live trace ring — it empties when the shard hibernates.")})}):r(Pe,{calls:d.calls,onOpenTrace:i})]}),e[16]=i,e[17]=n,e[18]=b,e[19]=d.byFunction,e[20]=d.byModel,e[21]=d.calls,e[22]=d.source,e[23]=d.totals,e[24]=h):h=e[24];let g;return e[25]!==p||e[26]!==f||e[27]!==h?(g=I("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[p,f,h]}),e[25]=p,e[26]=f,e[27]=h,e[28]=g):g=e[28],g};function Ue(o){return o.providerCost+o.estimatedCost}export{Ze as default};
@@ -1 +1 @@
1
- import{c as L}from"react/compiler-runtime";import{useState as S,useCallback as k,useEffect as E}from"react";import{C}from"../packem_shared/card-By2O8ULa.mjs";import{E as P}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as j,a as I,b as x,d as M,e as q,c as H}from"../packem_shared/table-D0SBiDu-.mjs";import{useT as T}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{b as O,f as R,l as _}from"../packem_shared/internal-hIuTpSbx.mjs";import{jsx as n,jsxs as g}from"react/jsx-runtime";const w={volume:"Request volume per function",latency:"Latency p50 / p95 per function",hotShards:"Hot shards"},b=Object.keys(w),N={error:null,loading:!0,rows:null},B=s=>Object.keys(s[0]??{}),V=s=>{const e=L(22),{state:f,title:o}=s,l=T(),{error:t,loading:a,rows:r}=f;let c;if(e[0]!==t||e[1]!==a||e[2]!==r||e[3]!==l||e[4]!==o){const h=r===null?[]:B(r);let i;e[6]!==l||e[7]!==o?(i=l(o),e[6]=l,e[7]=o,e[8]=i):i=e[8];let d;e[9]!==i?(d=n("header",{className:"border-b border-border px-4 py-3",children:n("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:i})}),e[9]=i,e[10]=d):d=e[10];let u;e[11]!==a||e[12]!==l?(u=a&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-loading",children:l("Loading…")}),e[11]=a,e[12]=l,e[13]=u):u=e[13];let p;e[14]!==t||e[15]!==a?(p=!a&&t!==null&&n("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"analytics-error",role:"alert",children:t}),e[14]=t,e[15]=a,e[16]=p):p=e[16];let m;e[17]!==t||e[18]!==a||e[19]!==r||e[20]!==l?(m=!a&&t===null&&r!==null&&r.length===0&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-empty-rows",children:l("No data points yet.")}),e[17]=t,e[18]=a,e[19]=r,e[20]=l,e[21]=m):m=e[21],c=g(C,{className:"gap-0 py-0","data-testid":`analytics-panel-${o}`,children:[d,u,p,m,!a&&t===null&&r!==null&&r.length>0&&g(j,{children:[n(I,{children:n(x,{children:h.map($)})}),n(M,{children:r.map((v,A)=>n(x,{children:h.map(y=>n(q,{className:"font-mono text-xs",children:_(v[y])},y))},A))})]})]}),e[0]=t,e[1]=a,e[2]=r,e[3]=l,e[4]=o,e[5]=c}else c=e[5];return c},X=({runQuery:s}={})=>{const e=T(),[f,o]=S({}),l=k(async t=>{if(s!==void 0)for(const a of b){if(t.cancelled)return;o(r=>({...r,[a]:N}));try{const{rows:r}=await s(a);t.cancelled||o(c=>({...c,[a]:{error:null,loading:!1,rows:r}}))}catch(r){t.cancelled||o(c=>({...c,[a]:{error:O(r),loading:!1,rows:null}}))}}},[s]);return E(()=>{const t={cancelled:!1};return R(l(t)),()=>{t.cancelled=!0}},[l]),s===void 0?n(P,{description:e("Analytics usage panels read through your worker, never from the browser. Pass studio.analyticsSqlQuery, a runner that calls an admin-only action running functionUsageQuery(panel) through ctx.analyticsSql, to enable these panels."),icon:n("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:n("path",{d:"M5 20V10m6.5 10V4M18 20v-7M3 20h18"})}),testId:"analytics-not-configured",title:e("Analytics usage panels are not wired up.")}):n("div",{className:"flex flex-col gap-4","data-testid":"lunora-analytics-panel",children:b.map(t=>n(V,{state:f[t]??N,title:w[t]},t))})};function $(s){return n(H,{children:s},s)}export{X as AnalyticsPanel};
1
+ import{c as A}from"react/compiler-runtime";import{useState as L,useCallback as S,useEffect as E}from"react";import{C}from"../packem_shared/card-By2O8ULa.mjs";import{E as P}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as j,a as I,b as x,d as M,e as q,c as H}from"../packem_shared/table-D0SBiDu-.mjs";import{useT as T}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{b as O,f as R,k as _}from"../packem_shared/internal-BT5tH08j.mjs";import{jsx as n,jsxs as g}from"react/jsx-runtime";const w={volume:"Request volume per function",latency:"Latency p50 / p95 per function",hotShards:"Hot shards"},b=Object.keys(w),N={error:null,loading:!0,rows:null},B=s=>Object.keys(s[0]??{}),V=s=>{const e=A(22),{state:f,title:o}=s,l=T(),{error:t,loading:a,rows:r}=f;let c;if(e[0]!==t||e[1]!==a||e[2]!==r||e[3]!==l||e[4]!==o){const h=r===null?[]:B(r);let i;e[6]!==l||e[7]!==o?(i=l(o),e[6]=l,e[7]=o,e[8]=i):i=e[8];let d;e[9]!==i?(d=n("header",{className:"border-b border-border px-4 py-3",children:n("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:i})}),e[9]=i,e[10]=d):d=e[10];let u;e[11]!==a||e[12]!==l?(u=a&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-loading",children:l("Loading…")}),e[11]=a,e[12]=l,e[13]=u):u=e[13];let p;e[14]!==t||e[15]!==a?(p=!a&&t!==null&&n("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"analytics-error",role:"alert",children:t}),e[14]=t,e[15]=a,e[16]=p):p=e[16];let m;e[17]!==t||e[18]!==a||e[19]!==r||e[20]!==l?(m=!a&&t===null&&r!==null&&r.length===0&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-empty-rows",children:l("No data points yet.")}),e[17]=t,e[18]=a,e[19]=r,e[20]=l,e[21]=m):m=e[21],c=g(C,{className:"gap-0 py-0","data-testid":`analytics-panel-${o}`,children:[d,u,p,m,!a&&t===null&&r!==null&&r.length>0&&g(j,{children:[n(I,{children:n(x,{children:h.map($)})}),n(M,{children:r.map((v,k)=>n(x,{children:h.map(y=>n(q,{className:"font-mono text-xs",children:_(v[y])},y))},k))})]})]}),e[0]=t,e[1]=a,e[2]=r,e[3]=l,e[4]=o,e[5]=c}else c=e[5];return c},X=({runQuery:s}={})=>{const e=T(),[f,o]=L({}),l=S(async t=>{if(s!==void 0)for(const a of b){if(t.cancelled)return;o(r=>({...r,[a]:N}));try{const{rows:r}=await s(a);t.cancelled||o(c=>({...c,[a]:{error:null,loading:!1,rows:r}}))}catch(r){t.cancelled||o(c=>({...c,[a]:{error:O(r),loading:!1,rows:null}}))}}},[s]);return E(()=>{const t={cancelled:!1};return R(l(t)),()=>{t.cancelled=!0}},[l]),s===void 0?n(P,{description:e("Analytics usage panels read through your worker, never from the browser. Pass studio.analyticsSqlQuery, a runner that calls an admin-only action running functionUsageQuery(panel) through ctx.analyticsSql, to enable these panels."),icon:n("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:n("path",{d:"M5 20V10m6.5 10V4M18 20v-7M3 20h18"})}),testId:"analytics-not-configured",title:e("Analytics usage panels are not wired up.")}):n("div",{className:"flex flex-col gap-4","data-testid":"lunora-analytics-panel",children:b.map(t=>n(V,{state:f[t]??N,title:w[t]},t))})};function $(s){return n(H,{children:s},s)}export{X as AnalyticsPanel};
@@ -1 +1 @@
1
- import{c as F}from"react/compiler-runtime";import{useNavigate as pe}from"@tanstack/react-router";import{Background as ge,Controls as be,ReactFlow as xe,Handle as le,Position as oe}from"@xyflow/react";import{useState as re,useRef as Ne}from"react";import{D as ve}from"../packem_shared/diagram-export-panel-Vdt-DZnO.mjs";import{B as me}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as Ee,a as ke}from"../packem_shared/card-By2O8ULa.mjs";import{E as ae}from"../packem_shared/empty-state-D7jEML_T.mjs";import{S as ie}from"../packem_shared/skeleton-DX1gfixl.mjs";import{b as U,e as $,T as we,c as V,a as Se,d as Ae}from"../packem_shared/table-D0SBiDu-.mjs";import{u as _e}from"../packem_shared/use-admin-spec-CK7mk3Ui.mjs";import{u as ye}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{f as Le}from"../packem_shared/internal-hIuTpSbx.mjs";import{c as De}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as x,jsx as o,Fragment as Ce}from"react/jsx-runtime";const he=["call","schedule","read","write","enqueue","publish","subscribe","start","trigger","invoke"],$e=new Set(["enqueue","publish","schedule","start","subscribe","trigger"]),ce={cron:1,function:2,http:0,queue:4,service:7,table:6,topic:3,workflow:5},Ie={stroke:"var(--muted-foreground)"},Te={fill:"var(--muted-foreground)",fontSize:10},Oe={fill:"var(--background)"},W="",X=260,Be=120,de=44,ee=40,ue=12,te=16,Ge=n=>{if(typeof n!="object"||n===null)return;const e=n;return["edges","nodes","modules","unresolved"].every(a=>Array.isArray(e[a]))?e:void 0},He={cron:()=>({to:"/schedule"}),function:()=>({to:"/functions"}),http:()=>({to:"/api"}),queue:()=>({to:"/queues"}),service:()=>({to:"/functions"}),table:n=>({search:{table:n.name},to:"/data"}),topic:()=>({to:"/queues"}),workflow:()=>({to:"/workflows"})},Me=n=>He[n.kind](n),R=n=>n.module??W,Pe=(n,e,a)=>{const t=new Set;for(const r of n.nodes)(e===void 0||R(r)===e)&&t.add(r.id);if(e===void 0)return t;const l=new Set(t);for(const r of n.edges)a.has(r.kind)&&(t.has(r.from)&&l.add(r.to),t.has(r.to)&&l.add(r.from));return l},Re=(n,e,a,t)=>{const l=`lane:${n}`;return[{data:{label:e},id:l,position:{x:a*(X+Be),y:0},selectable:!1,style:{height:de+t.length*(ee+ue)+te,width:X},type:"lane"},...t.map((r,u)=>({className:"flex cursor-pointer items-center truncate rounded-md border border-border bg-card px-2 text-xs text-foreground hover:border-ring",data:{label:`${r.detail??r.kind} · ${r.name}`,link:Me(r)},extent:"parent",id:r.id,parentId:l,position:{x:te,y:de+u*(ee+ue)},style:{height:ee,width:X-te*2},type:"member"}))]},Fe=(n,e)=>{const a=Pe(n,e.lane,e.kinds),t=new Map;for(const s of n.nodes)a.has(s.id)&&t.set(R(s),[...t.get(R(s))??[],s]);const l=[...n.modules.map(s=>({label:s.installed===!0?`${s.name} · ${e.componentLabel}`:s.name,lane:s.name})),{label:e.appLaneLabel,lane:W}],r=[];let u=0;for(const{label:s,lane:f}of l){const d=(t.get(f)??[]).toSorted((c,b)=>ce[c.kind]-ce[b.kind]||c.name.localeCompare(b.name));d.length>0&&(r.push(...Re(f,s,u,d)),u+=1)}const h=[];for(const s of n.edges)e.kinds.has(s.kind)&&a.has(s.from)&&a.has(s.to)&&h.push({animated:$e.has(s.kind),id:`${s.from}|${s.kind}|${s.to}`,label:s.kind,labelBgStyle:Oe,labelStyle:Te,source:s.from,style:Ie,target:s.to,type:"smoothstep"});return{edges:h,nodes:r}},se="*",qe=n=>{const e=F(2),{data:a}=n,t=String(a.label);let l;return e[0]!==t?(l=o("div",{className:"size-full rounded-lg border border-dashed border-border bg-background/60 px-3 py-2 text-xs font-medium text-muted-foreground",children:t}),e[0]=t,e[1]=l):l=e[1],l},fe={opacity:0},je=n=>{const e=F(10),{data:a}=n,t=pe(),{label:l,link:r}=a;let u;e[0]!==r||e[1]!==t?(u=()=>{Le(t(r))},e[0]=r,e[1]=t,e[2]=u):u=e[2];const h=u;let s;e[3]===Symbol.for("react.memo_cache_sentinel")?(s=o(le,{isConnectable:!1,position:oe.Left,style:fe,type:"target"}),e[3]=s):s=e[3];let f;e[4]!==l||e[5]!==h?(f=o("button",{className:"size-full cursor-pointer truncate rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",onClick:h,type:"button",children:l}),e[4]=l,e[5]=h,e[6]=f):f=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=o(le,{isConnectable:!1,position:oe.Right,style:fe,type:"source"}),e[7]=d):d=e[7];let c;return e[8]!==f?(c=x(Ce,{children:[s,f,d]}),e[8]=f,e[9]=c):c=e[9],c},Ke={lane:qe,member:je},ze=n=>{const e=Ge(n);return e===void 0?{kind:"error",message:"the response is not an architecture manifest"}:e.modules.length===0?{kind:"empty"}:{kind:"ready",spec:e}},Ye=n=>{const e=F(54),{manifest:a}=n,t=ne();let l,r,u,h,s,f,d,c,b,i;if(e[0]!==a.modules||e[1]!==a.nodes||e[2]!==t){const P=new Map;for(const g of a.nodes)g.kind==="function"&&P.set(R(g),(P.get(R(g))??0)+1);const I=g=>P.get(g)??0;s=I(W),h=Ee,i="overflow-hidden py-0",u=ke,b="px-0",r=we,d="architecture-catalog";let y;e[13]!==t?(y=t("Module"),e[13]=t,e[14]=y):y=e[14];let L;e[15]!==y?(L=o(V,{children:y}),e[15]=y,e[16]=L):L=e[16];let D;e[17]!==t?(D=t("Description"),e[17]=t,e[18]=D):D=e[18];let C;e[19]!==D?(C=o(V,{children:D}),e[19]=D,e[20]=C):C=e[20];let N;e[21]!==t?(N=t("Owned tables"),e[21]=t,e[22]=N):N=e[22];let v;e[23]!==N?(v=o(V,{children:N}),e[23]=N,e[24]=v):v=e[24];let E;e[25]!==t?(E=t("Functions"),e[25]=t,e[26]=E):E=e[26];let k;e[27]!==E?(k=o(V,{children:E}),e[27]=E,e[28]=k):k=e[28],e[29]!==v||e[30]!==k||e[31]!==L||e[32]!==C?(c=o(Se,{children:x(U,{children:[L,C,v,k]})}),e[29]=v,e[30]=k,e[31]=L,e[32]=C,e[33]=c):c=e[33],l=Ae,f=a.modules.map(g=>x(U,{"data-testid":`architecture-module-${g.name}`,children:[x($,{className:"font-mono text-xs",children:[g.name,g.installed===!0&&o(me,{className:"ml-2","data-testid":`architecture-component-${g.name}`,variant:"outline",children:t("Component")})]}),o($,{className:"text-xs text-muted-foreground",children:g.description??(g.installed===!0?t("Installed component"):"—")}),o($,{className:"font-mono text-xs text-muted-foreground",children:g.tables.length===0?"—":g.tables.join(", ")}),o($,{className:"text-xs",children:I(g.name)})]},g.name)),e[0]=a.modules,e[1]=a.nodes,e[2]=t,e[3]=l,e[4]=r,e[5]=u,e[6]=h,e[7]=s,e[8]=f,e[9]=d,e[10]=c,e[11]=b,e[12]=i}else l=e[3],r=e[4],u=e[5],h=e[6],s=e[7],f=e[8],d=e[9],c=e[10],b=e[11],i=e[12];let m;e[34]!==s||e[35]!==t?(m=s>0&&x(U,{"data-testid":"architecture-module-app",children:[o($,{className:"text-xs italic text-muted-foreground",children:t("Outside any module")}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs",children:s})]}),e[34]=s,e[35]=t,e[36]=m):m=e[36];let p;e[37]!==l||e[38]!==f||e[39]!==m?(p=x(l,{children:[f,m]}),e[37]=l,e[38]=f,e[39]=m,e[40]=p):p=e[40];let S;e[41]!==r||e[42]!==d||e[43]!==c||e[44]!==p?(S=x(r,{"data-testid":d,children:[c,p]}),e[41]=r,e[42]=d,e[43]=c,e[44]=p,e[45]=S):S=e[45];let A;e[46]!==u||e[47]!==b||e[48]!==S?(A=o(u,{className:b,children:S}),e[46]=u,e[47]=b,e[48]=S,e[49]=A):A=e[49];let _;return e[50]!==h||e[51]!==i||e[52]!==A?(_=o(h,{className:i,children:A}),e[50]=h,e[51]=i,e[52]=A,e[53]=_):_=e[53],_},Ve=n=>{const e=F(52),{manifest:a}=n,t=ne(),[l,r]=re(se),[u,h]=re(We);let s;e[0]!==a.edges?(s=w=>a.edges.some(J=>J.kind===w),e[0]=a.edges,e[1]=s):s=e[1];const f=he.filter(s);let d;e[2]!==t?(d=t("Outside any module"),e[2]=t,e[3]=d):d=e[3];const c=d;let b;e[4]!==t?(b=t("Component"),e[4]=t,e[5]=b):b=e[5];const i=b;let m;e[6]!==c||e[7]!==i||e[8]!==u||e[9]!==l||e[10]!==a?(m=Fe(a,{appLaneLabel:c,componentLabel:i,kinds:u,...l===se?{}:{lane:l}}),e[6]=c,e[7]=i,e[8]=u,e[9]=l,e[10]=a,e[11]=m):m=e[11];const{edges:p,nodes:S}=m,A=Ne(null);let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=w=>{r(w.target.value)},e[12]=_):_=e[12];const P=_;let I;e[13]===Symbol.for("react.memo_cache_sentinel")?(I=w=>{h(J=>{const Q=new Set(J);return Q.delete(w)||Q.add(w),Q})},e[13]=I):I=e[13];const y=I,L="flex flex-col gap-2",D="architecture-diagram",C="flex flex-wrap items-center gap-2";let N;e[14]!==t?(N=t("Module"),e[14]=t,e[15]=N):N=e[15];let v;e[16]!==t?(v=t("All modules"),e[16]=t,e[17]=v):v=e[17];let E;e[18]!==v?(E=o("option",{value:se,children:v}),e[18]=v,e[19]=E):E=e[19];let k;e[20]!==a.modules?(k=a.modules.map(Ze),e[20]=a.modules,e[21]=k):k=e[21];let g;e[22]!==t?(g=t("Outside any module"),e[22]=t,e[23]=g):g=e[23];let T;e[24]!==g?(T=o("option",{value:W,children:g}),e[24]=g,e[25]=T):T=e[25];let O;e[26]!==l||e[27]!==N||e[28]!==E||e[29]!==k||e[30]!==T?(O=x("select",{"aria-label":N,className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"architecture-module-filter",onChange:P,value:l,children:[E,k,T]}),e[26]=l,e[27]=N,e[28]=E,e[29]=k,e[30]=T,e[31]=O):O=e[31];let B;e[32]!==p.length||e[33]!==t?(B=t("{count} edges shown",{count:p.length}),e[32]=p.length,e[33]=t,e[34]=B):B=e[34];let G;e[35]!==B?(G=o("span",{className:"text-xs text-muted-foreground","data-testid":"architecture-edge-count",children:B}),e[35]=B,e[36]=G):G=e[36];let q;e[37]!==u?(q=w=>o("button",{"aria-pressed":u.has(w),className:De("rounded-full border border-border px-2.5 py-0.5 text-xs",u.has(w)?"bg-muted":"text-muted-foreground line-through"),"data-testid":`architecture-kind-${w}`,onClick:()=>{y(w)},type:"button",children:w},w),e[37]=u,e[38]=q):q=e[38];const Z=f.map(q);let H;e[39]!==O||e[40]!==G||e[41]!==Z?(H=x("div",{className:C,children:[O,G,Z]}),e[39]=O,e[40]=G,e[41]=Z,e[42]=H):H=e[42];let j,K,z;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=o(ge,{}),K=o(be,{showInteractive:!1}),z=o(ve,{containerRef:A,filenameBase:"architecture",testIdPrefix:"architecture"}),e[43]=j,e[44]=K,e[45]=z):(j=e[43],K=e[44],z=e[45]);let M;e[46]!==p||e[47]!==S?(M=o("div",{className:"h-[600px] w-full overflow-hidden border border-border bg-muted/20","data-testid":"architecture-canvas",ref:A,children:x(xe,{edges:p,edgesFocusable:!1,fitView:!0,minZoom:.1,nodes:S,nodesConnectable:!1,nodesDraggable:!1,nodeTypes:Ke,children:[j,K,z]})}),e[46]=p,e[47]=S,e[48]=M):M=e[48];let Y;return e[49]!==H||e[50]!==M?(Y=x("section",{className:L,"data-testid":D,children:[H,M]}),e[49]=H,e[50]=M,e[51]=Y):Y=e[51],Y},mt=n=>{const e=F(28),{manifest:a}=n,t=ne(),l=ye();let r;e[0]!==l?(r=()=>l.fetchArchitecture(),e[0]=l,e[1]=r):r=e[1];const h=_e(a,r,ze);if(h.kind==="loading"){let i;return e[2]===Symbol.for("react.memo_cache_sentinel")?(i=x("div",{className:"flex flex-col gap-4","data-testid":"architecture-loading",children:[o(ie,{className:"h-8 w-48"}),o(ie,{className:"h-64 w-full"})]}),e[2]=i):i=e[2],i}if(h.kind==="error"){let i;e[3]!==h.message||e[4]!==t?(i=t("Couldn't load the architecture manifest: {message}",{message:h.message}),e[3]=h.message,e[4]=t,e[5]=i):i=e[5];let m;e[6]!==t?(m=t("Architecture unavailable"),e[6]=t,e[7]=m):m=e[7];let p;return e[8]!==i||e[9]!==m?(p=o(ae,{description:i,testId:"architecture-error",title:m}),e[8]=i,e[9]=m,e[10]=p):p=e[10],p}if(h.kind==="empty"){let i;e[11]!==t?(i=t("Add a lunora/<folder>/module.ts that default-exports defineModule(...) and run lunora codegen to map your modules here. Installed components join the map once you declare one."),e[11]=t,e[12]=i):i=e[12];let m;e[13]!==t?(m=t("No modules declared"),e[13]=t,e[14]=m):m=e[14];let p;return e[15]!==i||e[16]!==m?(p=o(ae,{description:i,testId:"architecture-empty",title:m}),e[15]=i,e[16]=m,e[17]=p):p=e[17],p}const{spec:s}=h;let f,d;e[18]!==s?(f=o(Ye,{manifest:s}),d=o(Ve,{manifest:s}),e[18]=s,e[19]=f,e[20]=d):(f=e[19],d=e[20]);let c;e[21]!==s.unresolved||e[22]!==t?(c=s.unresolved.length>0&&x("details",{className:"text-sm","data-testid":"architecture-unresolved",children:[x("summary",{className:"cursor-pointer text-muted-foreground",children:[t("{count} call sites could not be drawn",{count:s.unresolved.length})," ",o(me,{variant:"outline",children:s.unresolved.length})]}),o("ul",{className:"mt-2 flex flex-col gap-1 font-mono text-xs",children:s.unresolved.map(Je)})]}),e[21]=s.unresolved,e[22]=t,e[23]=c):c=e[23];let b;return e[24]!==f||e[25]!==d||e[26]!==c?(b=x("div",{className:"flex flex-col gap-6","data-testid":"architecture-panel",children:[f,d,c]}),e[24]=f,e[25]=d,e[26]=c,e[27]=b):b=e[27],b};function We(){return new Set(he)}function Ze(n){return o("option",{value:n.name,children:n.name},n.name)}function Je(n){return x("li",{children:[n.file,":",n.line," · ",n.kind," · ",n.reason]},`${n.file}:${String(n.line)}:${n.kind}:${n.reason}`)}export{mt as default};
1
+ import{c as F}from"react/compiler-runtime";import{useNavigate as pe}from"@tanstack/react-router";import{Background as ge,Controls as be,ReactFlow as xe,Handle as le,Position as oe}from"@xyflow/react";import{useState as re,useRef as Ne}from"react";import{D as ve}from"../packem_shared/diagram-export-panel-miFPsocM.mjs";import{B as me}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as Ee,a as ke}from"../packem_shared/card-By2O8ULa.mjs";import{E as ae}from"../packem_shared/empty-state-D7jEML_T.mjs";import{S as ie}from"../packem_shared/skeleton-DX1gfixl.mjs";import{b as U,e as $,T as we,c as V,a as Se,d as Ae}from"../packem_shared/table-D0SBiDu-.mjs";import{u as _e}from"../packem_shared/use-admin-spec-Cokw73Ks.mjs";import{u as ye}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{f as Le}from"../packem_shared/internal-BT5tH08j.mjs";import{c as De}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as x,jsx as o,Fragment as Ce}from"react/jsx-runtime";const he=["call","schedule","read","write","enqueue","publish","subscribe","start","trigger","invoke"],$e=new Set(["enqueue","publish","schedule","start","subscribe","trigger"]),ce={cron:1,function:2,http:0,queue:4,service:7,table:6,topic:3,workflow:5},Ie={stroke:"var(--muted-foreground)"},Te={fill:"var(--muted-foreground)",fontSize:10},Oe={fill:"var(--background)"},W="",X=260,Be=120,de=44,ee=40,ue=12,te=16,Ge=n=>{if(typeof n!="object"||n===null)return;const e=n;return["edges","nodes","modules","unresolved"].every(a=>Array.isArray(e[a]))?e:void 0},He={cron:()=>({to:"/schedule"}),function:()=>({to:"/functions"}),http:()=>({to:"/api"}),queue:()=>({to:"/queues"}),service:()=>({to:"/functions"}),table:n=>({search:{table:n.name},to:"/data"}),topic:()=>({to:"/queues"}),workflow:()=>({to:"/workflows"})},Me=n=>He[n.kind](n),R=n=>n.module??W,Pe=(n,e,a)=>{const t=new Set;for(const r of n.nodes)(e===void 0||R(r)===e)&&t.add(r.id);if(e===void 0)return t;const l=new Set(t);for(const r of n.edges)a.has(r.kind)&&(t.has(r.from)&&l.add(r.to),t.has(r.to)&&l.add(r.from));return l},Re=(n,e,a,t)=>{const l=`lane:${n}`;return[{data:{label:e},id:l,position:{x:a*(X+Be),y:0},selectable:!1,style:{height:de+t.length*(ee+ue)+te,width:X},type:"lane"},...t.map((r,u)=>({className:"flex cursor-pointer items-center truncate rounded-md border border-border bg-card px-2 text-xs text-foreground hover:border-ring",data:{label:`${r.detail??r.kind} · ${r.name}`,link:Me(r)},extent:"parent",id:r.id,parentId:l,position:{x:te,y:de+u*(ee+ue)},style:{height:ee,width:X-te*2},type:"member"}))]},Fe=(n,e)=>{const a=Pe(n,e.lane,e.kinds),t=new Map;for(const s of n.nodes)a.has(s.id)&&t.set(R(s),[...t.get(R(s))??[],s]);const l=[...n.modules.map(s=>({label:s.installed===!0?`${s.name} · ${e.componentLabel}`:s.name,lane:s.name})),{label:e.appLaneLabel,lane:W}],r=[];let u=0;for(const{label:s,lane:f}of l){const d=(t.get(f)??[]).toSorted((c,b)=>ce[c.kind]-ce[b.kind]||c.name.localeCompare(b.name));d.length>0&&(r.push(...Re(f,s,u,d)),u+=1)}const h=[];for(const s of n.edges)e.kinds.has(s.kind)&&a.has(s.from)&&a.has(s.to)&&h.push({animated:$e.has(s.kind),id:`${s.from}|${s.kind}|${s.to}`,label:s.kind,labelBgStyle:Oe,labelStyle:Te,source:s.from,style:Ie,target:s.to,type:"smoothstep"});return{edges:h,nodes:r}},se="*",qe=n=>{const e=F(2),{data:a}=n,t=String(a.label);let l;return e[0]!==t?(l=o("div",{className:"size-full rounded-lg border border-dashed border-border bg-background/60 px-3 py-2 text-xs font-medium text-muted-foreground",children:t}),e[0]=t,e[1]=l):l=e[1],l},fe={opacity:0},je=n=>{const e=F(10),{data:a}=n,t=pe(),{label:l,link:r}=a;let u;e[0]!==r||e[1]!==t?(u=()=>{Le(t(r))},e[0]=r,e[1]=t,e[2]=u):u=e[2];const h=u;let s;e[3]===Symbol.for("react.memo_cache_sentinel")?(s=o(le,{isConnectable:!1,position:oe.Left,style:fe,type:"target"}),e[3]=s):s=e[3];let f;e[4]!==l||e[5]!==h?(f=o("button",{className:"size-full cursor-pointer truncate rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",onClick:h,type:"button",children:l}),e[4]=l,e[5]=h,e[6]=f):f=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=o(le,{isConnectable:!1,position:oe.Right,style:fe,type:"source"}),e[7]=d):d=e[7];let c;return e[8]!==f?(c=x(Ce,{children:[s,f,d]}),e[8]=f,e[9]=c):c=e[9],c},Ke={lane:qe,member:je},ze=n=>{const e=Ge(n);return e===void 0?{kind:"error",message:"the response is not an architecture manifest"}:e.modules.length===0?{kind:"empty"}:{kind:"ready",spec:e}},Ye=n=>{const e=F(54),{manifest:a}=n,t=ne();let l,r,u,h,s,f,d,c,b,i;if(e[0]!==a.modules||e[1]!==a.nodes||e[2]!==t){const P=new Map;for(const g of a.nodes)g.kind==="function"&&P.set(R(g),(P.get(R(g))??0)+1);const I=g=>P.get(g)??0;s=I(W),h=Ee,i="overflow-hidden py-0",u=ke,b="px-0",r=we,d="architecture-catalog";let y;e[13]!==t?(y=t("Module"),e[13]=t,e[14]=y):y=e[14];let L;e[15]!==y?(L=o(V,{children:y}),e[15]=y,e[16]=L):L=e[16];let D;e[17]!==t?(D=t("Description"),e[17]=t,e[18]=D):D=e[18];let C;e[19]!==D?(C=o(V,{children:D}),e[19]=D,e[20]=C):C=e[20];let N;e[21]!==t?(N=t("Owned tables"),e[21]=t,e[22]=N):N=e[22];let v;e[23]!==N?(v=o(V,{children:N}),e[23]=N,e[24]=v):v=e[24];let E;e[25]!==t?(E=t("Functions"),e[25]=t,e[26]=E):E=e[26];let k;e[27]!==E?(k=o(V,{children:E}),e[27]=E,e[28]=k):k=e[28],e[29]!==v||e[30]!==k||e[31]!==L||e[32]!==C?(c=o(Se,{children:x(U,{children:[L,C,v,k]})}),e[29]=v,e[30]=k,e[31]=L,e[32]=C,e[33]=c):c=e[33],l=Ae,f=a.modules.map(g=>x(U,{"data-testid":`architecture-module-${g.name}`,children:[x($,{className:"font-mono text-xs",children:[g.name,g.installed===!0&&o(me,{className:"ml-2","data-testid":`architecture-component-${g.name}`,variant:"outline",children:t("Component")})]}),o($,{className:"text-xs text-muted-foreground",children:g.description??(g.installed===!0?t("Installed component"):"—")}),o($,{className:"font-mono text-xs text-muted-foreground",children:g.tables.length===0?"—":g.tables.join(", ")}),o($,{className:"text-xs",children:I(g.name)})]},g.name)),e[0]=a.modules,e[1]=a.nodes,e[2]=t,e[3]=l,e[4]=r,e[5]=u,e[6]=h,e[7]=s,e[8]=f,e[9]=d,e[10]=c,e[11]=b,e[12]=i}else l=e[3],r=e[4],u=e[5],h=e[6],s=e[7],f=e[8],d=e[9],c=e[10],b=e[11],i=e[12];let m;e[34]!==s||e[35]!==t?(m=s>0&&x(U,{"data-testid":"architecture-module-app",children:[o($,{className:"text-xs italic text-muted-foreground",children:t("Outside any module")}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs",children:s})]}),e[34]=s,e[35]=t,e[36]=m):m=e[36];let p;e[37]!==l||e[38]!==f||e[39]!==m?(p=x(l,{children:[f,m]}),e[37]=l,e[38]=f,e[39]=m,e[40]=p):p=e[40];let S;e[41]!==r||e[42]!==d||e[43]!==c||e[44]!==p?(S=x(r,{"data-testid":d,children:[c,p]}),e[41]=r,e[42]=d,e[43]=c,e[44]=p,e[45]=S):S=e[45];let A;e[46]!==u||e[47]!==b||e[48]!==S?(A=o(u,{className:b,children:S}),e[46]=u,e[47]=b,e[48]=S,e[49]=A):A=e[49];let _;return e[50]!==h||e[51]!==i||e[52]!==A?(_=o(h,{className:i,children:A}),e[50]=h,e[51]=i,e[52]=A,e[53]=_):_=e[53],_},Ve=n=>{const e=F(52),{manifest:a}=n,t=ne(),[l,r]=re(se),[u,h]=re(We);let s;e[0]!==a.edges?(s=w=>a.edges.some(J=>J.kind===w),e[0]=a.edges,e[1]=s):s=e[1];const f=he.filter(s);let d;e[2]!==t?(d=t("Outside any module"),e[2]=t,e[3]=d):d=e[3];const c=d;let b;e[4]!==t?(b=t("Component"),e[4]=t,e[5]=b):b=e[5];const i=b;let m;e[6]!==c||e[7]!==i||e[8]!==u||e[9]!==l||e[10]!==a?(m=Fe(a,{appLaneLabel:c,componentLabel:i,kinds:u,...l===se?{}:{lane:l}}),e[6]=c,e[7]=i,e[8]=u,e[9]=l,e[10]=a,e[11]=m):m=e[11];const{edges:p,nodes:S}=m,A=Ne(null);let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=w=>{r(w.target.value)},e[12]=_):_=e[12];const P=_;let I;e[13]===Symbol.for("react.memo_cache_sentinel")?(I=w=>{h(J=>{const Q=new Set(J);return Q.delete(w)||Q.add(w),Q})},e[13]=I):I=e[13];const y=I,L="flex flex-col gap-2",D="architecture-diagram",C="flex flex-wrap items-center gap-2";let N;e[14]!==t?(N=t("Module"),e[14]=t,e[15]=N):N=e[15];let v;e[16]!==t?(v=t("All modules"),e[16]=t,e[17]=v):v=e[17];let E;e[18]!==v?(E=o("option",{value:se,children:v}),e[18]=v,e[19]=E):E=e[19];let k;e[20]!==a.modules?(k=a.modules.map(Ze),e[20]=a.modules,e[21]=k):k=e[21];let g;e[22]!==t?(g=t("Outside any module"),e[22]=t,e[23]=g):g=e[23];let T;e[24]!==g?(T=o("option",{value:W,children:g}),e[24]=g,e[25]=T):T=e[25];let O;e[26]!==l||e[27]!==N||e[28]!==E||e[29]!==k||e[30]!==T?(O=x("select",{"aria-label":N,className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"architecture-module-filter",onChange:P,value:l,children:[E,k,T]}),e[26]=l,e[27]=N,e[28]=E,e[29]=k,e[30]=T,e[31]=O):O=e[31];let B;e[32]!==p.length||e[33]!==t?(B=t("{count} edges shown",{count:p.length}),e[32]=p.length,e[33]=t,e[34]=B):B=e[34];let G;e[35]!==B?(G=o("span",{className:"text-xs text-muted-foreground","data-testid":"architecture-edge-count",children:B}),e[35]=B,e[36]=G):G=e[36];let q;e[37]!==u?(q=w=>o("button",{"aria-pressed":u.has(w),className:De("rounded-full border border-border px-2.5 py-0.5 text-xs",u.has(w)?"bg-muted":"text-muted-foreground line-through"),"data-testid":`architecture-kind-${w}`,onClick:()=>{y(w)},type:"button",children:w},w),e[37]=u,e[38]=q):q=e[38];const Z=f.map(q);let H;e[39]!==O||e[40]!==G||e[41]!==Z?(H=x("div",{className:C,children:[O,G,Z]}),e[39]=O,e[40]=G,e[41]=Z,e[42]=H):H=e[42];let j,K,z;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=o(ge,{}),K=o(be,{showInteractive:!1}),z=o(ve,{containerRef:A,filenameBase:"architecture",testIdPrefix:"architecture"}),e[43]=j,e[44]=K,e[45]=z):(j=e[43],K=e[44],z=e[45]);let M;e[46]!==p||e[47]!==S?(M=o("div",{className:"h-[600px] w-full overflow-hidden border border-border bg-muted/20","data-testid":"architecture-canvas",ref:A,children:x(xe,{edges:p,edgesFocusable:!1,fitView:!0,minZoom:.1,nodes:S,nodesConnectable:!1,nodesDraggable:!1,nodeTypes:Ke,children:[j,K,z]})}),e[46]=p,e[47]=S,e[48]=M):M=e[48];let Y;return e[49]!==H||e[50]!==M?(Y=x("section",{className:L,"data-testid":D,children:[H,M]}),e[49]=H,e[50]=M,e[51]=Y):Y=e[51],Y},mt=n=>{const e=F(28),{manifest:a}=n,t=ne(),l=ye();let r;e[0]!==l?(r=()=>l.fetchArchitecture(),e[0]=l,e[1]=r):r=e[1];const h=_e(a,r,ze);if(h.kind==="loading"){let i;return e[2]===Symbol.for("react.memo_cache_sentinel")?(i=x("div",{className:"flex flex-col gap-4","data-testid":"architecture-loading",children:[o(ie,{className:"h-8 w-48"}),o(ie,{className:"h-64 w-full"})]}),e[2]=i):i=e[2],i}if(h.kind==="error"){let i;e[3]!==h.message||e[4]!==t?(i=t("Couldn't load the architecture manifest: {message}",{message:h.message}),e[3]=h.message,e[4]=t,e[5]=i):i=e[5];let m;e[6]!==t?(m=t("Architecture unavailable"),e[6]=t,e[7]=m):m=e[7];let p;return e[8]!==i||e[9]!==m?(p=o(ae,{description:i,testId:"architecture-error",title:m}),e[8]=i,e[9]=m,e[10]=p):p=e[10],p}if(h.kind==="empty"){let i;e[11]!==t?(i=t("Add a lunora/<folder>/module.ts that default-exports defineModule(...) and run lunora codegen to map your modules here. Installed components join the map once you declare one."),e[11]=t,e[12]=i):i=e[12];let m;e[13]!==t?(m=t("No modules declared"),e[13]=t,e[14]=m):m=e[14];let p;return e[15]!==i||e[16]!==m?(p=o(ae,{description:i,testId:"architecture-empty",title:m}),e[15]=i,e[16]=m,e[17]=p):p=e[17],p}const{spec:s}=h;let f,d;e[18]!==s?(f=o(Ye,{manifest:s}),d=o(Ve,{manifest:s}),e[18]=s,e[19]=f,e[20]=d):(f=e[19],d=e[20]);let c;e[21]!==s.unresolved||e[22]!==t?(c=s.unresolved.length>0&&x("details",{className:"text-sm","data-testid":"architecture-unresolved",children:[x("summary",{className:"cursor-pointer text-muted-foreground",children:[t("{count} call sites could not be drawn",{count:s.unresolved.length})," ",o(me,{variant:"outline",children:s.unresolved.length})]}),o("ul",{className:"mt-2 flex flex-col gap-1 font-mono text-xs",children:s.unresolved.map(Je)})]}),e[21]=s.unresolved,e[22]=t,e[23]=c):c=e[23];let b;return e[24]!==f||e[25]!==d||e[26]!==c?(b=x("div",{className:"flex flex-col gap-6","data-testid":"architecture-panel",children:[f,d,c]}),e[24]=f,e[25]=d,e[26]=c,e[27]=b):b=e[27],b};function We(){return new Set(he)}function Ze(n){return o("option",{value:n.name,children:n.name},n.name)}function Je(n){return x("li",{children:[n.file,":",n.line," · ",n.kind," · ",n.reason]},`${n.file}:${String(n.line)}:${n.kind}:${n.reason}`)}export{mt as default};