@lunora/studio 1.0.0-alpha.349 → 1.0.0-alpha.350
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.d.mts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.mjs +1 -1
- package/dist/mount.d.mts +3 -2
- package/dist/mount.d.ts +3 -2
- package/dist/mount.mjs +1 -1
- package/dist/packem_chunks/AdvisorHealthPanel.mjs +1 -1
- package/dist/packem_chunks/ApiTab.mjs +1 -1
- package/dist/packem_chunks/AuditPanel.mjs +1 -1
- package/dist/packem_chunks/DeploymentHealthPanel.mjs +1 -1
- package/dist/packem_chunks/ExportImportPanel.mjs +5 -5
- package/dist/packem_chunks/FileBrowser.mjs +3 -3
- package/dist/packem_chunks/FunctionRunner.mjs +1 -1
- package/dist/packem_chunks/FunctionStatsPanel.mjs +1 -1
- package/dist/packem_chunks/HealthPanel.mjs +1 -1
- package/dist/packem_chunks/InsightsPanel.mjs +1 -1
- package/dist/packem_chunks/LogsPanel.mjs +1 -1
- package/dist/packem_chunks/MailPanel.mjs +1 -1
- package/dist/packem_chunks/MetricsPanel.mjs +1 -1
- package/dist/packem_chunks/NotificationsPanel.mjs +1 -1
- package/dist/packem_chunks/PitrPanel.mjs +1 -1
- package/dist/packem_chunks/SchemaViewer.mjs +1 -1
- package/dist/packem_chunks/SecurityAdvisorPanel.mjs +1 -1
- package/dist/packem_chunks/SettingsPanel.mjs +1 -1
- package/dist/packem_chunks/SqlEditorPanel.mjs +7 -7
- package/dist/packem_chunks/TableEditor.mjs +1 -1
- package/dist/packem_chunks/agents-panel.mjs +1 -1
- package/dist/packem_chunks/ai-usage-panel.mjs +1 -1
- package/dist/packem_chunks/analytics-panel.mjs +1 -1
- package/dist/packem_chunks/architecture-panel.mjs +1 -1
- package/dist/packem_chunks/auth-audit-panel.mjs +1 -1
- package/dist/packem_chunks/auth-config-panel.mjs +1 -1
- package/dist/packem_chunks/auth-sessions-panel.mjs +1 -1
- package/dist/packem_chunks/containers-panel.mjs +1 -1
- package/dist/packem_chunks/dashboards-panel.mjs +1 -1
- package/dist/packem_chunks/evals-panel.mjs +1 -1
- package/dist/packem_chunks/fanout-panel.mjs +1 -1
- package/dist/packem_chunks/flags-panel.mjs +1 -1
- package/dist/packem_chunks/issues-panel.mjs +1 -1
- package/dist/packem_chunks/kv-browser.mjs +1 -1
- package/dist/packem_chunks/log-drains-panel.mjs +1 -1
- package/dist/packem_chunks/migrations-route.mjs +1 -1
- package/dist/packem_chunks/organizations-panel.mjs +1 -1
- package/dist/packem_chunks/payments-panel.mjs +1 -1
- package/dist/packem_chunks/permissions-panel.mjs +1 -1
- package/dist/packem_chunks/privacy-requests-panel.mjs +1 -1
- package/dist/packem_chunks/queues-panel.mjs +1 -1
- package/dist/packem_chunks/reactors-panel.mjs +1 -1
- package/dist/packem_chunks/rls-panel.mjs +1 -1
- package/dist/packem_chunks/schedule-panel.mjs +1 -1
- package/dist/packem_chunks/storage-rules-panel.mjs +1 -1
- package/dist/packem_chunks/subscriptions-panel.mjs +1 -1
- package/dist/packem_chunks/sync-client-panel.mjs +1 -1
- package/dist/packem_chunks/theme-indicator.mjs +1 -0
- package/dist/packem_chunks/traces-panel.mjs +1 -1
- package/dist/packem_chunks/users-panel.mjs +1 -1
- package/dist/packem_chunks/vector-browser.mjs +1 -1
- package/dist/packem_chunks/workflows-panel.mjs +1 -1
- package/dist/packem_shared/{ApiDocsPanel-Py7C4ibM.mjs → ApiDocsPanel-B_RaW7Br.mjs} +2 -2
- package/dist/packem_shared/ApiReferencePanel-u9Rrljdf.mjs +1 -0
- package/dist/packem_shared/{CommandPalette-CM1hqAOD.mjs → CommandPalette-5OsK8PNe.mjs} +1 -1
- package/dist/packem_shared/{ConfirmButton-DU4p72Er.mjs → ConfirmButton-CIXYF6Mg.mjs} +1 -1
- package/dist/packem_shared/{ConnectionBadge-B8Hj5DaE.mjs → ConnectionBadge-BfcoN-VE.mjs} +1 -1
- package/dist/packem_shared/DEFAULT_AUTO_REFRESH_MS-CG7Q45ZS.mjs +1 -0
- package/dist/packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs +1 -0
- package/dist/packem_shared/{DataBrowser-DFjQeYYF.mjs → DataBrowser-Cc1qZX-4.mjs} +1 -1
- package/dist/packem_shared/{DataFilters-faurWYyX.mjs → DataFilters--ocFTVT2.mjs} +1 -1
- package/dist/packem_shared/GlobalDataBrowser-Hq6gTlkb.mjs +1 -0
- package/dist/packem_shared/{HomePanel-C8sb1fFJ.mjs → HomePanel-DeyYLVxc.mjs} +1 -1
- package/dist/packem_shared/MigrationsPanel-CMZYYcQ5.mjs +1 -0
- package/dist/packem_shared/OpenRpcReferencePanel-E9cDfHRv.mjs +1 -0
- package/dist/packem_shared/ScheduledJobs-D4CUj7aX.mjs +1 -0
- package/dist/packem_shared/{ShardInput-C6mjgAh4.mjs → ShardInput-CoySruKZ.mjs} +1 -1
- package/dist/packem_shared/Studio-BhTqTeGb.mjs +1 -0
- package/dist/packem_shared/StudioApp-B1d0beD4.mjs +1 -0
- package/dist/packem_shared/{StudioI18nProvider-fVsCSs5L.mjs → StudioI18nProvider-CGXCPnQn.mjs} +1 -1
- package/dist/packem_shared/{advisor-view-B8oIluyS.mjs → advisor-view-fNcNYW2Q.mjs} +1 -1
- package/dist/packem_shared/{app.d-D45VvUTx.d.mts → app.d-D425h1XO.d.mts} +4 -3
- package/dist/packem_shared/{app.d-D45VvUTx.d.ts → app.d-D425h1XO.d.ts} +4 -3
- package/dist/packem_shared/{auth-pager-DiDnXsfe.mjs → auth-pager-DW77WeZw.mjs} +1 -1
- package/dist/packem_shared/{data-grid-BHTuvSI7.mjs → data-grid-r3isM8Nq.mjs} +1 -1
- package/dist/packem_shared/{diagram-export-panel-BMLzao0Y.mjs → diagram-export-panel-aBDQdX4e.mjs} +1 -1
- package/dist/packem_shared/{error-alert-CNQjdAhi.mjs → error-alert-54TiaMvZ.mjs} +1 -1
- package/dist/packem_shared/{grid-features-8DoaKdS1.mjs → grid-features-2c5SaBtH.mjs} +1 -1
- package/dist/packem_shared/{grid-pagination-DgzyzfBh.mjs → grid-pagination-DY2erU65.mjs} +1 -1
- package/dist/packem_shared/home-panel-0XMGe1hP.mjs +3 -0
- package/dist/packem_shared/{live-status-BuJdUZFU.mjs → live-status-D1GasNsH.mjs} +1 -1
- package/dist/packem_shared/{recording-client-neIRrUNz.mjs → recording-client-MbGZ28I0.mjs} +1 -1
- package/dist/packem_shared/{reference-view-BrsL8UGn.mjs → reference-view-DCEC5kjY.mjs} +4 -4
- package/dist/packem_shared/{schema-diagram-ghsOCED7.mjs → schema-diagram-k7cFl7Wp.mjs} +1 -1
- package/dist/packem_shared/{sql-result-table-COsfUSGc.mjs → sql-result-table-CatgdmMh.mjs} +1 -1
- package/dist/packem_shared/studio-CA3ZKwVK.mjs +2 -0
- package/dist/packem_shared/{table-list-sidebar-B7IOSxLN.mjs → table-list-sidebar-nA7g7uSk.mjs} +1 -1
- package/dist/packem_shared/use-admin-query-BW9IuacC.mjs +1 -0
- package/dist/packem_shared/use-auth-config-KO9tnI39.mjs +1 -0
- package/dist/packem_shared/use-sql-assistant-DXnqbBs-.mjs +1 -0
- package/dist/packem_shared/use-studio-client-DCA50tF2.mjs +1 -0
- package/dist/standalone/chunk-26OKWFLO.js +1 -0
- package/dist/standalone/chunk-2EL4EMYZ.js +1 -0
- package/dist/standalone/chunk-2O6KKVH2.js +1 -0
- package/dist/standalone/{chunk-WX647YQ7.js → chunk-2WNL74MI.js} +3 -3
- package/dist/standalone/chunk-2X6O33OX.js +1 -0
- package/dist/standalone/chunk-2ZO7XY3Z.js +1 -0
- package/dist/standalone/{chunk-Y3AYVFTK.js → chunk-3GXPALXG.js} +1 -1
- package/dist/standalone/chunk-3Y5K3IQO.js +1 -0
- package/dist/standalone/{chunk-BOMPSVRC.js → chunk-4C4THJUD.js} +1 -1
- package/dist/standalone/{chunk-WVWCUB4S.js → chunk-4IEMXFUB.js} +1 -1
- package/dist/standalone/{chunk-5B2RTXBS.js → chunk-4SQBAPY6.js} +1 -1
- package/dist/standalone/{chunk-R6U22RSY.js → chunk-5DNGK3NT.js} +1 -1
- package/dist/standalone/{chunk-WOEHFC4J.js → chunk-5J32EGHF.js} +1 -1
- package/dist/standalone/chunk-5NZWQEEJ.js +1 -0
- package/dist/standalone/chunk-6I42AM75.js +1 -0
- package/dist/standalone/{chunk-RGMVGZV4.js → chunk-6M7FLLMT.js} +1 -1
- package/dist/standalone/{chunk-IWZ7GVQO.js → chunk-6QEXGYWH.js} +1 -1
- package/dist/standalone/chunk-7AZYREIY.js +1 -0
- package/dist/standalone/{chunk-G43F7LYA.js → chunk-7F3S5OQT.js} +1 -1
- package/dist/standalone/chunk-7MN724WR.js +1 -0
- package/dist/standalone/{chunk-Q6IT6ZD7.js → chunk-7RGYCU6F.js} +1 -1
- package/dist/standalone/{chunk-NRP22GKC.js → chunk-A566HCBX.js} +1 -1
- package/dist/standalone/{chunk-253UHWDX.js → chunk-AOHKAKKL.js} +1 -1
- package/dist/standalone/{chunk-OYCUPD3Q.js → chunk-AP4PC2M4.js} +1 -1
- package/dist/standalone/chunk-B3AXFXAD.js +1 -0
- package/dist/standalone/chunk-B7MHW3A5.js +1 -0
- package/dist/standalone/{chunk-CWPBPBWJ.js → chunk-BHOLL76W.js} +6 -6
- package/dist/standalone/{chunk-I57ZVLUB.js → chunk-BTRYFPZH.js} +1 -1
- package/dist/standalone/chunk-BVKQA5OL.js +1 -0
- package/dist/standalone/chunk-CGZVMM3P.js +1 -0
- package/dist/standalone/chunk-CIVMATZK.js +3 -0
- package/dist/standalone/chunk-CLINNLLE.js +1 -0
- package/dist/standalone/chunk-CTE6RPXC.js +1 -0
- package/dist/standalone/chunk-CW57Q264.js +1 -0
- package/dist/standalone/chunk-D7JK65OK.js +1 -0
- package/dist/standalone/{chunk-FUYEZFBP.js → chunk-DBVJ5VLI.js} +1 -1
- package/dist/standalone/{chunk-XCYFP44W.js → chunk-DS7HZKZ2.js} +1 -1
- package/dist/standalone/{chunk-2WDKJ74A.js → chunk-DX55P3KZ.js} +1 -1
- package/dist/standalone/{chunk-55UGUCQ6.js → chunk-E26OT26O.js} +1 -1
- package/dist/standalone/{chunk-YUPEDAX3.js → chunk-E32FS6PE.js} +2 -2
- package/dist/standalone/chunk-E3VSRIQU.js +1 -0
- package/dist/standalone/chunk-EDGOSJXL.js +1 -0
- package/dist/standalone/chunk-EOR73TZZ.js +1 -0
- package/dist/standalone/chunk-F5LTDUMB.js +1 -0
- package/dist/standalone/chunk-FLVDICZL.js +1 -0
- package/dist/standalone/{chunk-5J4FLDJH.js → chunk-FPIUVV7Q.js} +1 -1
- package/dist/standalone/chunk-GMW2DYFU.js +1 -0
- package/dist/standalone/{chunk-VFFW3ANI.js → chunk-GPOSJNMV.js} +5 -5
- package/dist/standalone/chunk-GQYA5W5T.js +1 -0
- package/dist/standalone/chunk-HFYFYNSX.js +1 -0
- package/dist/standalone/chunk-HKLF627N.js +1 -0
- package/dist/standalone/{chunk-PSMQQV6S.js → chunk-HKPDPKXD.js} +1 -1
- package/dist/standalone/chunk-HLAAOW33.js +1 -0
- package/dist/standalone/{chunk-75M6ZLLS.js → chunk-HOPAJ5F6.js} +2 -2
- package/dist/standalone/{chunk-7Y3SY37W.js → chunk-IBJVVHV5.js} +1 -1
- package/dist/standalone/{chunk-VESGIGMQ.js → chunk-IH2CJZF2.js} +1 -1
- package/dist/standalone/chunk-JAHK7RRJ.js +1 -0
- package/dist/standalone/chunk-JG2C7SS2.js +1 -0
- package/dist/standalone/chunk-JGMQQ3S7.js +1 -0
- package/dist/standalone/{chunk-3YXASVTP.js → chunk-JTGGWF7R.js} +1 -1
- package/dist/standalone/chunk-KFNDET5D.js +1 -0
- package/dist/standalone/{chunk-NXQW5E6W.js → chunk-KRPXOSBL.js} +1 -1
- package/dist/standalone/{chunk-7Q256NLI.js → chunk-KYONGQQ4.js} +1 -1
- package/dist/standalone/{chunk-OPM7ESDV.js → chunk-LIGOLZND.js} +1 -1
- package/dist/standalone/{chunk-VQRCJJXS.js → chunk-LKCO3E2B.js} +1 -1
- package/dist/standalone/chunk-LOV52GLG.js +1 -0
- package/dist/standalone/chunk-LPINY2IJ.js +19 -0
- package/dist/standalone/{chunk-XKISL2CG.js → chunk-LRXCL6IA.js} +1 -1
- package/dist/standalone/{chunk-OQ6I6OXT.js → chunk-LUHXNZI4.js} +1 -1
- package/dist/standalone/chunk-MD67S53Z.js +1 -0
- package/dist/standalone/{chunk-HIJGQX6F.js → chunk-MDAXV2XH.js} +1 -1
- package/dist/standalone/{chunk-ZN7TURF4.js → chunk-MFNO5BFR.js} +1 -1
- package/dist/standalone/chunk-MMJTKSHL.js +1 -0
- package/dist/standalone/chunk-NMVFSJM7.js +1 -0
- package/dist/standalone/chunk-NVHHB5EV.js +2 -0
- package/dist/standalone/chunk-O3FDK56W.js +1 -0
- package/dist/standalone/{chunk-C7FJ2JKY.js → chunk-OECMBE6Q.js} +1 -1
- package/dist/standalone/chunk-OSJ7HV7B.js +1 -0
- package/dist/standalone/chunk-OUFWXYEF.js +1 -0
- package/dist/standalone/chunk-OXFKZ4BM.js +1 -0
- package/dist/standalone/{chunk-63QLK2KW.js → chunk-P5GAJKDW.js} +1 -1
- package/dist/standalone/chunk-P6L6ABWO.js +1 -0
- package/dist/standalone/chunk-PZZWUL5U.js +1 -0
- package/dist/standalone/chunk-QAQVT4FS.js +1 -0
- package/dist/standalone/{chunk-VCFEO3RI.js → chunk-R36QXQZX.js} +1 -1
- package/dist/standalone/chunk-R3KLR5EP.js +1 -0
- package/dist/standalone/chunk-RXVXXRYD.js +1 -0
- package/dist/standalone/chunk-S7XAAH7U.js +1 -0
- package/dist/standalone/{chunk-E4PXACVL.js → chunk-SDQH4HR6.js} +1 -1
- package/dist/standalone/chunk-SFY646MC.js +1 -0
- package/dist/standalone/{chunk-VDC6JP4A.js → chunk-SJLEEYCR.js} +1 -1
- package/dist/standalone/{chunk-ZKJS6EBE.js → chunk-SLIDAWNX.js} +1 -1
- package/dist/standalone/chunk-SOO2HXV6.js +1 -0
- package/dist/standalone/chunk-SXD6JQXF.js +1 -0
- package/dist/standalone/{chunk-AUGKHAMQ.js → chunk-SYGCASPT.js} +1 -1
- package/dist/standalone/{chunk-2I4NHEKA.js → chunk-TDVDZ7XQ.js} +1 -1
- package/dist/standalone/chunk-TRZTGE4R.js +1 -0
- package/dist/standalone/chunk-TWMS2TMF.js +1 -0
- package/dist/standalone/chunk-U76DVXTR.js +21 -0
- package/dist/standalone/chunk-UTX6IBA3.js +1 -0
- package/dist/standalone/chunk-UZIBQZ2F.js +1 -0
- package/dist/standalone/chunk-VB6YJKPA.js +1 -0
- package/dist/standalone/{chunk-CVXNHIQW.js → chunk-VEWQWS3J.js} +1 -1
- package/dist/standalone/{chunk-UC7MNI2F.js → chunk-W2BCSK5S.js} +1 -1
- package/dist/standalone/chunk-W2XSKODB.js +1 -0
- package/dist/standalone/{chunk-MVWZMWPD.js → chunk-W7MRISE3.js} +1 -1
- package/dist/standalone/chunk-W7Z35E2E.js +1 -0
- package/dist/standalone/chunk-WIET27J3.js +1 -0
- package/dist/standalone/chunk-WQGT24W6.js +1 -0
- package/dist/standalone/{chunk-GZEWLX7U.js → chunk-WS36BO4R.js} +1 -1
- package/dist/standalone/chunk-WZTY3ZYI.js +1 -0
- package/dist/standalone/chunk-X5KWBDTF.js +1 -0
- package/dist/standalone/chunk-X74GEPSG.js +1 -0
- package/dist/standalone/chunk-XBZUJDHD.js +1 -0
- package/dist/standalone/chunk-XMEVNOCA.js +1 -0
- package/dist/standalone/chunk-XWEDIIIT.js +1 -0
- package/dist/standalone/{chunk-GHQ2VDI2.js → chunk-XYR5NST4.js} +1 -1
- package/dist/standalone/{chunk-XGCIDUJF.js → chunk-YHTHRYP5.js} +1 -1
- package/dist/standalone/{chunk-RX755NMO.js → chunk-YJ2WHOGO.js} +1 -1
- package/dist/standalone/chunk-YJWR6ZWC.js +1 -0
- package/dist/standalone/{chunk-CGQMJYCW.js → chunk-Z5EV64KS.js} +1 -1
- package/dist/standalone/{chunk-LVIL2SFA.js → chunk-ZBFWT34B.js} +1 -1
- package/dist/standalone/{chunk-AUAECCXB.js → chunk-ZBON5T5A.js} +1 -1
- package/dist/standalone/chunk-ZGSL4DPP.js +1 -0
- package/dist/standalone/chunk-ZMQ6PKLN.js +1 -0
- package/dist/standalone/{chunk-SJQERRSZ.js → chunk-ZTOREMGH.js} +1 -1
- package/dist/standalone/chunk-ZTOXQK4V.js +1 -0
- package/dist/standalone/chunk-ZWDORIZY.js +1 -0
- package/dist/standalone/chunk-ZZAJHNZ6.js +1 -0
- package/dist/standalone/studio.js +1 -1
- package/package.json +5 -5
- package/dist/packem_chunks/sparkline.mjs +0 -1
- package/dist/packem_shared/ApiReferencePanel-DlYVADAy.mjs +0 -1
- package/dist/packem_shared/DEFAULT_AUTO_REFRESH_MS-DvhNw0BI.mjs +0 -1
- package/dist/packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs +0 -1
- package/dist/packem_shared/GlobalDataBrowser-CPfjubP_.mjs +0 -1
- package/dist/packem_shared/MigrationsPanel-Dzjf42y8.mjs +0 -1
- package/dist/packem_shared/OpenRpcReferencePanel-nYyfjjse.mjs +0 -1
- package/dist/packem_shared/ScheduledJobs-BJ1uZW1U.mjs +0 -1
- package/dist/packem_shared/Studio-CgqntIfx.mjs +0 -1
- package/dist/packem_shared/StudioApp-DfFjQPGJ.mjs +0 -1
- package/dist/packem_shared/home-panel-BJXZsAaD.mjs +0 -3
- package/dist/packem_shared/studio-CFSjGWyw.mjs +0 -2
- package/dist/packem_shared/use-admin-query-CLStXJ7v.mjs +0 -1
- package/dist/packem_shared/use-auth-config-DtZeS_qf.mjs +0 -1
- package/dist/packem_shared/use-sql-assistant-DxNeNdCs.mjs +0 -1
- package/dist/standalone/chunk-2IKDEUCX.js +0 -1
- package/dist/standalone/chunk-37WYCOQ2.js +0 -1
- package/dist/standalone/chunk-4H5PBJNF.js +0 -1
- package/dist/standalone/chunk-4UBF7HMZ.js +0 -1
- package/dist/standalone/chunk-533J6WYA.js +0 -1
- package/dist/standalone/chunk-5QR2SQIS.js +0 -1
- package/dist/standalone/chunk-5ZNIQENA.js +0 -1
- package/dist/standalone/chunk-63Z6OJ6G.js +0 -1
- package/dist/standalone/chunk-74IYYDDI.js +0 -19
- package/dist/standalone/chunk-7EHAUFJY.js +0 -2
- package/dist/standalone/chunk-7G4Z6Q7X.js +0 -1
- package/dist/standalone/chunk-7RKB5KS7.js +0 -1
- package/dist/standalone/chunk-7TN6VTTF.js +0 -1
- package/dist/standalone/chunk-AWWECTQT.js +0 -1
- package/dist/standalone/chunk-AXL4YZJR.js +0 -1
- package/dist/standalone/chunk-COK5BCWN.js +0 -1
- package/dist/standalone/chunk-CULVXE3K.js +0 -1
- package/dist/standalone/chunk-E4BAGQ53.js +0 -1
- package/dist/standalone/chunk-EBTYSPZB.js +0 -1
- package/dist/standalone/chunk-EC5PMSQ6.js +0 -1
- package/dist/standalone/chunk-ECY2JC5F.js +0 -1
- package/dist/standalone/chunk-EWMBX5N2.js +0 -1
- package/dist/standalone/chunk-FPI7AMQJ.js +0 -1
- package/dist/standalone/chunk-GC5UHRDR.js +0 -1
- package/dist/standalone/chunk-GRHO2IUN.js +0 -1
- package/dist/standalone/chunk-GUDC24NJ.js +0 -1
- package/dist/standalone/chunk-H467GBSD.js +0 -1
- package/dist/standalone/chunk-HBO4SMAO.js +0 -15
- package/dist/standalone/chunk-HBTGWHTW.js +0 -1
- package/dist/standalone/chunk-HCTJKP5J.js +0 -1
- package/dist/standalone/chunk-HZTJLEIJ.js +0 -1
- package/dist/standalone/chunk-I26MS5PJ.js +0 -1
- package/dist/standalone/chunk-IRKWOUXO.js +0 -1
- package/dist/standalone/chunk-IUSKFS3B.js +0 -1
- package/dist/standalone/chunk-K2EHRNYW.js +0 -1
- package/dist/standalone/chunk-L5MI4PTP.js +0 -1
- package/dist/standalone/chunk-LXCVA5SP.js +0 -1
- package/dist/standalone/chunk-LYQZERWS.js +0 -1
- package/dist/standalone/chunk-MPEIBWCJ.js +0 -1
- package/dist/standalone/chunk-NCFYQR4L.js +0 -1
- package/dist/standalone/chunk-NCPW7WHO.js +0 -1
- package/dist/standalone/chunk-NOS2OC45.js +0 -1
- package/dist/standalone/chunk-NQZALRU3.js +0 -1
- package/dist/standalone/chunk-OQ2ORNN6.js +0 -1
- package/dist/standalone/chunk-OVBYLXPD.js +0 -1
- package/dist/standalone/chunk-OWQHP4KI.js +0 -1
- package/dist/standalone/chunk-PKSRXFSZ.js +0 -1
- package/dist/standalone/chunk-Q6ED4KUL.js +0 -1
- package/dist/standalone/chunk-QAQDMS6R.js +0 -1
- package/dist/standalone/chunk-QC2GLF3I.js +0 -1
- package/dist/standalone/chunk-QFK4UI4Q.js +0 -1
- package/dist/standalone/chunk-QJ4AALXU.js +0 -1
- package/dist/standalone/chunk-QJLHH3ET.js +0 -1
- package/dist/standalone/chunk-R3RBUT32.js +0 -1
- package/dist/standalone/chunk-RNYOBPQA.js +0 -1
- package/dist/standalone/chunk-RWVIV3U7.js +0 -1
- package/dist/standalone/chunk-RYBLB23Z.js +0 -1
- package/dist/standalone/chunk-S3EWTSAN.js +0 -1
- package/dist/standalone/chunk-S4AR74DJ.js +0 -3
- package/dist/standalone/chunk-S4Z7K55A.js +0 -1
- package/dist/standalone/chunk-SA2OGF3F.js +0 -1
- package/dist/standalone/chunk-SFMIR4YV.js +0 -1
- package/dist/standalone/chunk-SROQCZ3P.js +0 -1
- package/dist/standalone/chunk-T4SIZOJG.js +0 -1
- package/dist/standalone/chunk-U37BPX5J.js +0 -1
- package/dist/standalone/chunk-UFZVSXRW.js +0 -1
- package/dist/standalone/chunk-UQWGBWQ3.js +0 -1
- package/dist/standalone/chunk-V6LPISRQ.js +0 -1
- package/dist/standalone/chunk-WEPM5G3R.js +0 -1
- package/dist/standalone/chunk-WGBAHXMK.js +0 -1
- package/dist/standalone/chunk-WGUN4FNJ.js +0 -1
- package/dist/standalone/chunk-WJRYEML4.js +0 -1
- package/dist/standalone/chunk-WNMY5ZKL.js +0 -1
- package/dist/standalone/chunk-YBDF3DET.js +0 -7
- package/dist/standalone/chunk-YJI56OCF.js +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{c as X}from"react/compiler-runtime";import{
|
|
1
|
+
import{c as X}from"react/compiler-runtime";import{useState as se,useMemo as Ae,useCallback as Xe,useEffect as me,useRef as ue,useId as Ze}from"react";import{u as Te}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{ADMIN_FUNCTIONS as we}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{u as Ee,n as Be,b as Re,r as be,s as et}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{d as ye,f as ce,c as Ce,b as tt}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as nt}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{u as st}from"../packem_shared/use-sql-assistant-DXnqbBs-.mjs";import ot from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{useT as re}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{c as ie}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as B,jsx as f,Fragment as he}from"react/jsx-runtime";import{I as Pe}from"../packem_shared/input-CXhxesPC.mjs";import{diffLines as lt}from"diff";import{S as rt,a as it}from"../packem_shared/sql-result-table-CatgdmMh.mjs";import{ShardInput as at}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{A as ct}from"../packem_shared/alert-PB5W11MM.mjs";import{E as dt}from"../packem_shared/grid-features-2c5SaBtH.mjs";const ut="x",qe=" ",ft={'"':'"',"'":"'","[":"]","`":"`"},He=(l,e)=>{let n=e+2;for(;n<l.length&&l[n]!==`
|
|
2
2
|
`;)n+=1;return n},Fe=(l,e)=>{const n=l.indexOf("*/",e+2);return n===-1?-1:n+2},We=l=>{const e=l.split("");let n=0;for(;n<l.length;){const t=l[n]??"",o=ft[t];if(t==="-"&&l[n+1]==="-"){const s=He(l,n);e.fill(qe,n,s),n=s}else if(t==="/"&&l[n+1]==="*"){const s=Fe(l,n);if(s===-1)return;e.fill(qe,n,s),n=s}else if(o!==void 0){let s=n+1;for(;s<l.length;)if(l[s]!==o)s+=1;else if(o!=="]"&&l[s+1]===o)s+=2;else break;if(s>=l.length)return;e.fill(ut,n,s+1),n=s+1}else n+=1}for(let t=0;t<l.length;t+=1)l[t]===`
|
|
3
3
|
`&&(e[t]=`
|
|
4
|
-
`);return e.join("")},mt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,pt=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|truncate|update|vacuum)\b|\breplace\b(?!\s*\()/iu,ht=/^\w+/u,bt=/;\s*$/u,gt=/\s/u,Ke=l=>{let e=0;for(;e<l.length;){const n=l[e];if(n!==void 0&>.test(n))e+=1;else if(n==="-"&&l[e+1]==="-")e=He(l,e);else if(n==="/"&&l[e+1]==="*"){const t=Fe(l,e);if(t===-1)break;e=t}else break}return e},xt=l=>{const e=Ke(l),n=l.slice(e).trimEnd();if(n==="")return{code:"SQL_EMPTY",message:"the query is empty"};const o=(We(n)??n).replace(bt,""),s=n.slice(0,o.length),r=o.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const c="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!mt.test(s))return{code:"SQL_NOT_READONLY",length:ht.exec(s)?.[0].length??1,message:c,offset:e};const a=pt.exec(s);if(a!==null)return{code:"SQL_NOT_READONLY",length:a[0].length,message:`${c} (\`${a[0].toUpperCase()}\` is not allowed)`,offset:e+a.index}},vt=/^explain\b/iu,yt=l=>vt.test(l.slice(Ke(l)))?l:`EXPLAIN QUERY PLAN ${l}`,ke=(l,e)=>{const n=l.trim();if(n==="")return[];const t=e+l.indexOf(n),o=xt(n);return o?.code==="SQL_EMPTY"?[]:[o===void 0?{offset:t,sql:n}:{offset:t,rejection:o,sql:n}]},ze=l=>{const e=We(l);if(e===void 0)return ke(l,0);const n=[];let t=0;for(let o=0;o<=e.length;o+=1)o!==e.length&&e[o]!==";"||(n.push(...ke(l.slice(t,o),t)),t=o+1);return n},St=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],wt=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Se=String.fromCodePoint(0),
|
|
5
|
-
${l}`})),kt=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,o=>(e.push(o),`${Se}${(e.length-1).toString()}${Se}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:o,replacement:s}of
|
|
6
|
-
`,e);return t===-1?l.length:t}if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);return t===-1?l.length:t+2}return-1},At=l=>{let e="",n=0;for(;n<l.length;){const t=_t(l,n);t===-1?(e+=l.slice(n,n+1),n+=1):(e+=l.slice(n,t).replaceAll(Lt," "),n=t)}return e},qt=l=>{const e=new Set;for(const n of l.matchAll(Rt))e.add((n[1]??"").toLowerCase());return e},Dt=(l,e)=>{const n=new Map;for(const t of l.matchAll(Tt)){const o=(t[1]??"").toLowerCase(),s=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),s!==""&&!It.has(s)&&n.set(s,o))}return n},Ue=(l,e)=>{const n=At(l),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:qt(n),masked:n,targets:Dt(n,t)}},Ot=/^(?:__lunora|sqlite_)/iu,Mt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,$t=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Bt=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Pt=(l,e,n)=>{const t=[];for(const o of l.matchAll(Mt)){const s=o[1]??"",r=s.toLowerCase();!e.has(r)&&!n.has(r)&&!Bt.has(r)&&!Ot.test(s)&&t.push({length:s.length,message:`unknown table \`${s}\``,offset:o.index+o[0].length-s.length,severity:"error",source:"schema"})}return t},Ht=(l,e,n)=>{const t=[],o=new Map;for(const[s,r]of Object.entries(e.columns))o.set(s.toLowerCase(),new Set(r.map(c=>c.toLowerCase())));for(const s of l.matchAll($t)){const r=(s[1]??"").toLowerCase(),c=s[2]??"",a=n.get(r),i=a===void 0?void 0:o.get(a);i!==void 0&&!i.has(c.toLowerCase())&&t.push({length:c.length,message:`\`${a??""}\` has no column \`${c}\``,offset:s.index+s[0].length-c.length,severity:"error",source:"schema"})}return t},Ft=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,Wt=/\bas\s+"?([a-z_][\w$]*)"?/giu,Kt=(l,e,n,t)=>{const o=[...new Set(n.values())],s=new Map,r=new Set;for(const i of o){for(const u of e.columns[i]??[])r.add(u.toLowerCase());for(const u of e.docFields?.[i]??[])s.set(u.toLowerCase(),u)}if(s.size===0)return[];const c=new Set([...l.matchAll(Wt)].map(i=>(i[1]??"").toLowerCase())),a=[];for(const i of l.matchAll(Ft)){const u=i[1],g=u??i[2]??"",d=g.toLowerCase(),y=s.get(d);y===void 0||r.has(d)||c.has(d)||t.has(d)||n.has(d)||a.push({length:g.length,message:`\`${y}\` is a \`__doc__\` field, not a column — use \`json_extract(__doc__, '$.${y}')\``,offset:i.index+(u===void 0?0:1),severity:"error",source:"schema"})}return a},zt=(l,e)=>{if(l.trim()==="")return[];const n=ze(l),t=new Set(e.tables.map(s=>s.toLowerCase())),o=[];for(const s of n){const{offset:r,rejection:c}=s;if(c!==void 0){o.push({length:c.length,message:c.message,offset:c.offset===void 0?r:r+c.offset,severity:"error",source:"gate"});continue}const{ctes:a,masked:i,targets:u}=Ue(s.sql,e.tables);o.push(...[...Pt(i,t,a),...Ht(i,e,u),...Kt(i,e,u,a)].map(g=>({...g,offset:g.offset===void 0?r:r+g.offset})))}return o},Ut=Ne(we.lintSql),jt=600,Qt=(l,e,n)=>{const t=Te(),[o,s]=se([]),r=Ae(()=>zt(l,e),[l,e]),c=ot(l,jt),i=r.some(d=>d.source==="gate")||c.trim()==="",u=Xe(async d=>{try{const y=await t.query(Ut,{sql:c},ye(n));d.cancelled||s(y.diagnostics??[])}catch{d.cancelled||s([])}},[t,c,n]);me(()=>{if(i){s([]);return}const d={cancelled:!1};return ce(u(d)),()=>{d.cancelled=!0}},[u,i]);const g=c===l;return Ae(()=>g?[...r,...o]:r,[r,o,g])},ge=8,Yt=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],Gt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Jt=/[\w$]/,je=l=>l!==void 0&&Jt.test(l),Qe=l=>{let e=l.length;for(;e>0&&je(l[e-1]);)e-=1;return l.slice(e)},Ye=(l,e)=>{let n=e;for(;n>0&&je(l[n-1]);)n-=1;return{end:e,start:n,text:l.slice(n,e)}},De=(l,e)=>{const n=l.slice(0,e).trimEnd();return n.endsWith(".")||Gt.has(Qe(n).toUpperCase())},Vt=(l,e,n)=>{const t=l.slice(0,e);if(!t.endsWith("."))return;const o=Qe(t.slice(0,-1));if(o!=="")return Ue(l,n).targets.get(o.toLowerCase())??o},Ie=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Oe=(l,e,n,t)=>{const o=[];for(const s of l)if(Ie(s,e)&&(o.push(t(s)),o.length>=n))break;return o},Xt=(l,e,n)=>{const t=new Map;for(const[o,s]of Object.entries(l.columns))for(const r of s)if(Ie(r,e)&&!t.has(r)&&(t.set(r,o),t.size>=n))return[...t].map(([c,a])=>({detail:a,kind:"column",label:c}));return[...t].map(([o,s])=>({detail:s,kind:"column",label:o}))},Zt=(l,e,n)=>{const t=Ye(l,e),o=Vt(l,t.start,n.tables);if(o!==void 0){const i=n.columns[o]??n.columns[o.toLowerCase()]??[];return Oe(i,t.text,ge,u=>({detail:o,kind:"column",label:u}))}if(t.text===""&&!De(l,t.start))return[];const s=Oe(n.tables,t.text,ge,i=>({kind:"table",label:i})),r=Xt(n,t.text,ge),c=Yt.flatMap(i=>t.text!==""&&Ie(i,t.text)&&i.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:i}]:[]);return(De(l,t.start)?[...r,...s,...c]:[...s,...r,...c]).slice(0,ge)},en=(l,e,n)=>{const t=Ye(l,e),o=l.slice(0,t.start)+n.label+l.slice(t.end);return{caret:t.start+n.label.length,value:o}},tn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],nn=(l,e)=>{const n=globalThis.getComputedStyle(l),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(const a of tn)o[a]=n[a];t.textContent=l.value.slice(0,Math.max(0,e));const s=globalThis.document.createElement("span");s.textContent=l.value.slice(Math.max(0,e))||".",t.append(s),globalThis.document.body.append(t);const r=s.offsetLeft-l.scrollLeft,c=s.offsetTop-l.scrollTop;return t.remove(),{left:r,top:c}},sn=(l,e,n)=>{const t=X(16),[o,s]=se(null);let r;t[0]!==l||t[1]!==e?(r=(x,p)=>{const N=Zt(x,p,l);if(N.length===0){s(null);return}const v=e.current,{left:S,top:h}=v===null?{left:0,top:0}:nn(v,p);s(w=>w!==null&&w.active===0&&w.left===S&&w.top===h&&w.suggestions.length===N.length&&w.suggestions.every((I,R)=>{const E=N.at(R);return I.kind===E?.kind&&I.label===E.label&&I.detail===E.detail})?w:{active:0,left:S,suggestions:N,top:h})},t[0]=l,t[1]=e,t[2]=r):r=t[2];const c=r;let a;t[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{s(null)},t[3]=a):a=t[3];const i=a;let u;t[4]===Symbol.for("react.memo_cache_sentinel")?(u=x=>{s(p=>{if(p===null)return p;const N=p.suggestions.length,v=(p.active+x+N)%N;return{...p,active:v}})},t[4]=u):u=t[4];const g=u;let d;t[5]!==n||t[6]!==o||t[7]!==e?(d=x=>{const p=e.current;if(o===null||p===null)return!1;const N=o.suggestions[x??o.active];if(N===void 0)return!1;const v=en(p.value,p.selectionStart,N);return n(v.value),s(null),requestAnimationFrame(()=>{const S=e.current;S!==null&&(S.focus(),S.setSelectionRange(v.caret,v.caret))}),!0},t[5]=n,t[6]=o,t[7]=e,t[8]=d):d=t[8];const y=d;let b;t[9]!==y?(b=()=>y(),t[9]=y,t[10]=b):b=t[10];const C=b;let m;return t[11]!==C||t[12]!==y||t[13]!==c||t[14]!==o?(m={close:i,commit:C,commitAt:y,move:g,refresh:c,state:o},t[11]=C,t[12]=y,t[13]=c,t[14]=o,t[15]=m):m=t[15],m},on={column:"column",keyword:"keyword",table:"table"},ln=20,rn=l=>{const e=X(17),{listboxId:n,onPick:t,state:o}=l,s=re();let r;e[0]!==o?(r=o===null?void 0:{left:o.left,top:o.top+ln},e[0]=o,e[1]=r):r=e[1];const c=r;if(o===null)return null;let a;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==s){let u;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==s?(u=(g,d)=>B("li",{"aria-selected":d===o.active,className:ie("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",d===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${d.toString()}`,onMouseDown:y=>{y.preventDefault(),t(d)},role:"option",children:[f("span",{className:"truncate font-mono",children:g.label}),g.detail!==void 0&&f("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:g.detail}),f("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:s(on[g.kind])})]},`${g.kind}:${g.label}`),e[8]=n,e[9]=t,e[10]=o.active,e[11]=s,e[12]=u):u=e[12],a=o.suggestions.map(u),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=s,e[7]=a}else a=e[7];let i;return e[13]!==n||e[14]!==c||e[15]!==a?(i=f("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:n,role:"listbox",style:c,children:a}),e[13]=n,e[14]=c,e[15]=a,e[16]=i):i=e[16],i},an=Ne(we.listTables),cn=Ne(we.readTablePage),dn=l=>{const e=X(18),n=Te();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[o,s]=se(t);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={},e[1]=r):r=e[1];const[c,a]=se(r);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={},e[2]=i):i=e[2];const[u,g]=se(i);let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[3]=d):d=e[3];const y=ue(d);let b,C;e[4]!==n||e[5]!==l?(b=()=>{const S={cancelled:!1};return ce((async()=>{try{const w=await n.query(an,{},ye(l));S.cancelled||(s(w.map(fn)),a({}),g({}),y.current=new Set)}catch{S.cancelled||(s([]),a({}),g({}),y.current=new Set)}})()),()=>{S.cancelled=!0}},C=[n,l],e[4]=n,e[5]=l,e[6]=b,e[7]=C):(b=e[6],C=e[7]),me(b,C);let m;e[8]!==n||e[9]!==l?(m=S=>{if(y.current.has(S))return;y.current.add(S),ce((async()=>{try{const w=await n.query(cn,{limit:1,offset:0,table:S},ye(l)),{sqlColumns:T}=w;if(T===void 0){y.current.delete(S);return}const I=new Set(T),R=w.columns.filter(E=>!I.has(E));a(E=>({...E,[S]:T})),g(E=>({...E,[S]:R}))}catch{y.current.delete(S)}})())},e[8]=n,e[9]=l,e[10]=m):m=e[10];const x=m;let p;e[11]!==c||e[12]!==u||e[13]!==o?(p={columns:c,docFields:u,tables:o},e[11]=c,e[12]=u,e[13]=o,e[14]=p):p=e[14];const N=p;let v;return e[15]!==x||e[16]!==N?(v={probe:x,schema:N},e[15]=x,e[16]=N,e[17]=v):v=e[17],v},Ce=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,un=l=>{const e=new Set;Ce.lastIndex=0;let n=Ce.exec(l);for(;n!==null;)e.add(n[1]??n[2]),n=Ce.exec(l);return[...e]};function fn(l){return l.name}const mn=l=>(l.metaKey||l.ctrlKey)&&!l.shiftKey&&!l.altKey&&l.key.toLowerCase()==="i",pn=l=>{const e=X(44),{inlineEditEnabled:n,onSubmit:t,probe:o,schema:s,setDraft:r}=l,c=Ze(),[a,i]=se(null),u=ue(null),g=ue(null),d=ue(null),y=sn(s,d,r),{close:b,commit:C,commitAt:m,move:x,refresh:p,state:N}=y;let v;e[0]!==m?(v=q=>{m(q)},e[0]=m,e[1]=v):v=e[1];const S=v;let h;e[2]!==p?(h=()=>{const q=d.current;q!==null&&q===document.activeElement&&p(q.value,q.selectionStart)},e[2]=p,e[3]=h):h=e[3];let w;e[4]!==p||e[5]!==s?(w=[p,s],e[4]=p,e[5]=s,e[6]=w):w=e[6],me(h,w);let T;e[7]!==o||e[8]!==p||e[9]!==r?(T=q=>{const{selectionStart:j,value:J}=q.target;r(J),i(null);for(const V of un(J))o(V);p(J,j)},e[7]=o,e[8]=p,e[9]=r,e[10]=T):T=e[10];const I=T;let R;e[11]!==p?(R=q=>{const j=q.currentTarget;p(j.value,j.selectionStart)},e[11]=p,e[12]=R):R=e[12];const E=R;let _;e[13]!==b||e[14]!==C||e[15]!==x?(_=q=>q.key==="ArrowDown"?(q.preventDefault(),x(1),!0):q.key==="ArrowUp"?(q.preventDefault(),x(-1),!0):q.key==="Escape"?(q.preventDefault(),b(),!0):(q.key==="Enter"||q.key==="Tab")&&!q.metaKey&&!q.ctrlKey&&C()?(q.preventDefault(),!0):!1,e[13]=b,e[14]=C,e[15]=x,e[16]=_):_=e[16];const L=_;let A;e[17]!==N||e[18]!==b||e[19]!==n||e[20]!==L||e[21]!==t?(A=q=>{if(!(N!==null&&L(q))){if((q.metaKey||q.ctrlKey)&&q.key==="Enter"){q.preventDefault(),t();return}if(n&&mn(q)){q.preventDefault(),b();const{selectionEnd:j,selectionStart:J,value:V}=q.currentTarget,[U,G]=J===j?[0,V.length]:[J,j];i({end:G,start:U,text:V.slice(U,G)})}}},e[17]=N,e[18]=b,e[19]=n,e[20]=L,e[21]=t,e[22]=A):A=e[22];const M=A;let W;e[23]!==b?(W=()=>{requestAnimationFrame(()=>{b()})},e[23]=b,e[24]=W):W=e[24];const K=W;let $;e[25]===Symbol.for("react.memo_cache_sentinel")?($=q=>{const{scrollLeft:j,scrollTop:J}=q.currentTarget;u.current!==null&&(u.current.scrollTop=J),g.current!==null&&(g.current.scrollTop=J,g.current.scrollLeft=j)},e[25]=$):$=e[25];const F=$;let H;e[26]===Symbol.for("react.memo_cache_sentinel")?(H=q=>{const j=d.current;j===null||q.offset===void 0||(j.focus(),j.setSelectionRange(q.offset,q.offset+(q.length??0)))},e[26]=H):H=e[26];const k=H;let D;e[27]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{i(null),d.current?.focus()},e[27]=D):D=e[27];const z=D;let P;e[28]!==a||e[29]!==r?(P=q=>{const j=d.current;if(a===null||j===null)return;const{end:J,start:V,text:U}=a;if(j.value.slice(V,J)!==U){z();return}r(j.value.slice(0,V)+q+j.value.slice(J)),i(null),j.focus(),requestAnimationFrame(()=>{j.setSelectionRange(V,V+q.length)})},e[28]=a,e[29]=r,e[30]=P):P=e[30];const oe=P;let Z;e[31]!==I||e[32]!==K||e[33]!==M||e[34]!==E?(Z={onBlur:K,onChange:I,onKeyDown:M,onScroll:F,onSelect:E},e[31]=I,e[32]=K,e[33]=M,e[34]=E,e[35]=Z):Z=e[35];let ne;return e[36]!==oe||e[37]!==N||e[38]!==b||e[39]!==a||e[40]!==c||e[41]!==S||e[42]!==Z?(ne={acceptInlineEdit:oe,autocompleteState:N,closeAutocomplete:b,closeInlineEdit:z,inlineEdit:a,handlers:Z,listboxId:c,onPickSuggestion:S,editorRef:d,gutterRef:u,overlayRef:g,revealDiagnostic:k},e[36]=oe,e[37]=N,e[38]=b,e[39]=a,e[40]=c,e[41]=S,e[42]=Z,e[43]=ne):ne=e[43],ne},hn="lunora-studio-sql-tabs",bn="lunora-studio-sql-active-tab",Le=12,pe=(l="",e="")=>({activeId:null,id:Be("tab"),name:e,sql:l}),gn=()=>Re(bn,""),xn=l=>{const e=X(16),[n,t]=Ee(hn),[o,s]=gn(),[r]=se(l);let c,a;e[0]!==r||e[1]!==t||e[2]!==n.length?(c=()=>{n.length===0&&t([r])},a=[r,t,n.length],e[0]=r,e[1]=t,e[2]=n.length,e[3]=c,e[4]=a):(c=e[3],a=e[4]),me(c,a);let i;e[5]!==r||e[6]!==n?(i=n.length===0?[r]:n,e[5]=r,e[6]=n,e[7]=i):i=e[7];const u=i;let g;e[8]!==o||e[9]!==u?(g=u.some(b=>b.id===o)?o:u[0]?.id??"",e[8]=o,e[9]=u,e[10]=g):g=e[10];const d=g;let y;return e[11]!==d||e[12]!==s||e[13]!==t||e[14]!==u?(y={activeId:d,setActiveId:s,setTabs:t,tabs:u},e[11]=d,e[12]=s,e[13]=t,e[14]=u,e[15]=y):y=e[15],y},Ge=l=>l.activeId===null&&l.sql.trim()!=="",vn=(l,e)=>[...l,e].slice(-Le),yn=(l,e,n)=>{const t=l.findIndex(r=>r.id===e);if(t===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const o=l.filter(r=>r.id!==e);if(o.length===0){const r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},Sn=(l,e)=>{const n=l.filter(t=>t.id===e);return n.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:n}},wn=(l,e,n)=>{const t=l.findIndex(s=>s.id===e);if(t===-1)return{activeId:n,tabs:[...l]};const o=l.slice(0,t+1);return{activeId:o.some(s=>s.id===n)?n:e,tabs:o}},Nn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Cn=(l,e,n)=>{if(l==="others")return e.filter(t=>t.id!==n);if(l==="right"){const t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},Me={error:null,pane:"results",result:null,running:!1},En=l=>{const e=X(66),{activeId:n,setActiveId:t,setTabs:o,tabs:s}=xn(l);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},e[0]=r):r=e[0];const[c,a]=se(r),[i,u]=se(null),[g,d]=se(null);let y;e[1]!==n||e[2]!==s?(y=s.find(O=>O.id===n)??s[0]??pe(),e[1]=n,e[2]=s,e[3]=y):y=e[3];const b=y,C=c[b.id]??Me;let m;e[4]!==b.id||e[5]!==o?(m=O=>{o(Q=>Q.map(ee=>ee.id===b.id?{...ee,...O}:ee))},e[4]=b.id,e[5]=o,e[6]=m):m=e[6];const x=m;let p;e[7]!==b.id?(p=O=>{a(Q=>{const ee=Q[b.id]??Me;return{...Q,[b.id]:{...ee,...O}}})},e[7]=b.id,e[8]=p):p=e[8];const N=p;let v;e[9]!==t||e[10]!==o||e[11]!==s.length?(v=()=>{if(s.length>=Le)return;const O=pe();o(Q=>vn(Q,O)),t(O.id)},e[9]=t,e[10]=o,e[11]=s.length,e[12]=v):v=e[12];const S=v;let h;e[13]!==t||e[14]!==o?(h=O=>{u(null),d(null),o(O.tabs),t(O.activeId);const Q=new Set(O.tabs.map(kn));a(ee=>Object.fromEntries(Object.entries(ee).filter(ae=>{const[de]=ae;return Q.has(de)})))},e[13]=t,e[14]=o,e[15]=h):h=e[15];const w=h;let T;e[16]!==w||e[17]!==s?(T=O=>{w(yn(s,O,pe))},e[16]=w,e[17]=s,e[18]=T):T=e[18];const I=T;let R;e[19]!==n||e[20]!==w||e[21]!==s?(R=(O,Q)=>{w(O==="others"?Sn(s,Q):O==="right"?wn(s,Q,n):Nn(pe))},e[19]=n,e[20]=w,e[21]=s,e[22]=R):R=e[22];const E=R;let _;e[23]!==E||e[24]!==i||e[25]!==s?(_=O=>{i!==null&&(Cn(O,s,i.id).some(Tn)?d(O):E(O,i.id))},e[23]=E,e[24]=i,e[25]=s,e[26]=_):_=e[26];const L=_;let A;e[27]===Symbol.for("react.memo_cache_sentinel")?(A=(O,Q)=>{Q.preventDefault(),d(null),u({id:O,x:Q.clientX,y:Q.clientY})},e[27]=A):A=e[27];const M=A;let W;e[28]===Symbol.for("react.memo_cache_sentinel")?(W=()=>{u(null),d(null)},e[28]=W):W=e[28];const K=W;let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=O=>{O.preventDefault(),u(null),d(null)},e[29]=$):$=e[29];const F=$;let H;e[30]!==L?(H=()=>{L("others")},e[30]=L,e[31]=H):H=e[31];const k=H;let D;e[32]!==L?(D=()=>{L("right")},e[32]=L,e[33]=D):D=e[33];const z=D;let P;e[34]!==L?(P=()=>{L("all")},e[34]=L,e[35]=P):P=e[35];const oe=P;let Z;e[36]!==E||e[37]!==g||e[38]!==i?(Z=()=>{i!==null&&g!==null&&E(g,i.id),d(null)},e[36]=E,e[37]=g,e[38]=i,e[39]=Z):Z=e[39];const ne=Z;let q;e[40]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{d(null)},e[40]=q):q=e[40];const j=q;let J;e[41]!==i?(J=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=J):J=e[42];const V=J;let U;e[43]!==o?(U=O=>{o(Q=>Q.map(ee=>ee.activeId===O?{...ee,activeId:null}:ee))},e[43]=o,e[44]=U):U=e[44];const G=U;let Y;e[45]!==o?(Y=(O,Q)=>{o(ee=>ee.map(ae=>ae.id===O?{...ae,name:Q}:ae))},e[45]=o,e[46]=Y):Y=e[46];const te=Y;let le;return e[47]!==b||e[48]!==n||e[49]!==S||e[50]!==I||e[51]!==ne||e[52]!==oe||e[53]!==k||e[54]!==z||e[55]!==C||e[56]!==N||e[57]!==x||e[58]!==g||e[59]!==te||e[60]!==t||e[61]!==i||e[62]!==V||e[63]!==s||e[64]!==G?(le={activeTab:b,activeTabId:n,addEditorTab:S,cancelBulk:j,closeEditorTab:I,closeTabMenu:K,confirmBulk:ne,menuStyle:V,onBackdropContextMenu:F,onCloseAll:oe,onCloseOthers:k,onCloseToRight:z,openTabMenu:M,output:C,patchActiveOutput:N,patchActiveTab:x,pendingBulk:g,renameTab:te,setActiveTabId:t,tabMenu:i,tabs:s,unlinkQuery:G},e[47]=b,e[48]=n,e[49]=S,e[50]=I,e[51]=ne,e[52]=oe,e[53]=k,e[54]=z,e[55]=C,e[56]=N,e[57]=x,e[58]=g,e[59]=te,e[60]=t,e[61]=i,e[62]=V,e[63]=s,e[64]=G,e[65]=le):le=e[65],le};function kn(l){return l.id}function Tn(l){return Ge(l)}const Rn="lunora-studio-sql-queries",fe="lunora-studio-sql-history",In="lunora-studio-sql-remember-history",Ln=25,_n=l=>{const e=X(41),{loadIntoActiveTab:n,unlinkQuery:t}=l,o=re(),[s,r]=Ee(Rn),[c,a]=Re(In,!1),[i,u]=Ee(fe,c?"local":"session");let g,d;e[0]!==c?(g=()=>{c||be(fe,"local")},d=[c],e[0]=c,e[1]=g,e[2]=d):(g=e[1],d=e[2]),me(g,d);const[y,b]=se(""),C=ue(null);let m;e[3]!==u?(m=k=>{u(D=>D[0]?.sql===k?D:[{at:Date.now(),sql:k},...D.filter(P=>P.sql!==k)].slice(0,Ln))},e[3]=u,e[4]=m):m=e[4];const x=m;let p;e[5]!==n||e[6]!==r||e[7]!==o?(p=()=>{const k={id:Be("q"),name:o("Untitled query"),sql:""};r(D=>[k,...D]),n("",k.id)},e[5]=n,e[6]=r,e[7]=o,e[8]=p):p=e[8];const N=p;let v;e[9]!==n||e[10]!==s?(v=k=>{const D=s.find(z=>z.id===k);D!==void 0&&(n(D.sql,k),C.current?.querySelector(`[data-testid="sql-query-${k}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=n,e[10]=s,e[11]=v):v=e[11];const S=v;let h;e[12]!==r||e[13]!==t?(h=k=>{r(D=>D.filter(z=>z.id!==k)),t(k)},e[12]=r,e[13]=t,e[14]=h):h=e[14];const w=h;let T;e[15]!==n?(T=k=>{n(k.currentTarget.dataset.sql??"",null)},e[15]=n,e[16]=T):T=e[16];const I=T;let R;e[17]!==n?(R=k=>{n(k.currentTarget.dataset.sql??"",null)},e[17]=n,e[18]=R):R=e[18];const E=R;let _;e[19]!==u?(_=()=>{u([]),be(fe,"local"),be(fe,"session")},e[19]=u,e[20]=_):_=e[20];const L=_;let A;e[21]!==i||e[22]!==a?(A=k=>{et(fe,i,k?"local":"session"),k||be(fe,"local"),a(k)},e[21]=i,e[22]=a,e[23]=A):A=e[23];const M=A;let W;e[24]===Symbol.for("react.memo_cache_sentinel")?(W=k=>{b(k.target.value)},e[24]=W):W=e[24];const K=W;let $;e[25]!==r?($=(k,D)=>{r(z=>z.map(P=>P.id===k?{...P,sql:D}:P))},e[25]=r,e[26]=$):$=e[26];const F=$;let H;return e[27]!==L||e[28]!==w||e[29]!==i||e[30]!==E||e[31]!==I||e[32]!==N||e[33]!==s||e[34]!==x||e[35]!==c||e[36]!==y||e[37]!==S||e[38]!==M||e[39]!==F?(H={clearHistory:L,deleteQuery:w,history:i,listRef:C,loadFromHistory:E,loadTemplate:I,newQuery:N,onSearchChange:K,queries:s,recordHistory:x,rememberHistory:c,search:y,selectQuery:S,setRememberHistory:M,updateQuerySql:F},e[27]=L,e[28]=w,e[29]=i,e[30]=E,e[31]=I,e[32]=N,e[33]=s,e[34]=x,e[35]=c,e[36]=y,e[37]=S,e[38]=M,e[39]=F,e[40]=H):H=e[40],H},_e="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",An=(l,e)=>{const n=[];for(const o of l){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;const s=Math.max(0,Math.min(o.offset,e)),r=Math.max(s,Math.min(o.offset+o.length,e));s!==r&&n.push({end:r,severity:o.severity,start:s})}n.sort((o,s)=>o.start-s.start);const t=[];for(const o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},Je=(l,e)=>e(l==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":l==="too-long"?"The statement is too long to rewrite. Select a shorter part of it.":l==="empty-response"?"The model returned nothing usable.":"The model could not be reached."),qn=l=>{const e=X(51),{assistant:n,failed:t,onGenerated:o}=l,s=re(),[r,c]=se("");if(n.unavailable)return null;let a;e[0]!==n?(a=n.pending("sql"),e[0]=n,e[1]=a):a=e[1];const i=a;let u;if(e[2]!==n||e[3]!==t||e[4]!==o||e[5]!==i||e[6]!==r||e[7]!==s){const g=n.reason("sql");let d;e[9]!==n||e[10]!==t||e[11]!==o||e[12]!==r?(d=E=>{const _=r.trim();if(_===""&&!E)return;ce((async()=>{const A=await n.generate(_===""?"fix the failing statement":_,E?t:void 0);A!==void 0&&o(A)})())},e[9]=n,e[10]=t,e[11]=o,e[12]=r,e[13]=d):d=e[13];const y=d;let b;e[14]!==s?(b=s("Describe the query you want"),e[14]=s,e[15]=b):b=e[15];let C;e[16]===Symbol.for("react.memo_cache_sentinel")?(C=E=>{c(E.target.value)},e[16]=C):C=e[16];let m;e[17]!==y?(m=E=>{E.key==="Enter"&&(E.preventDefault(),y(!1))},e[17]=y,e[18]=m):m=e[18];let x;e[19]!==s?(x=s("Describe the query you want"),e[19]=s,e[20]=x):x=e[20];let p;e[21]!==i||e[22]!==r||e[23]!==b||e[24]!==m||e[25]!==x?(p=f(Pe,{"aria-label":b,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:i,onChange:C,onKeyDown:m,placeholder:x,value:r}),e[21]=i,e[22]=r,e[23]=b,e[24]=m,e[25]=x,e[26]=p):p=e[26];const N=i&&"opacity-60";let v;e[27]!==N?(v=ie("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",N),e[27]=N,e[28]=v):v=e[28];let S;e[29]!==i||e[30]!==r?(S=i||r.trim()==="",e[29]=i,e[30]=r,e[31]=S):S=e[31];let h;e[32]!==y?(h=()=>{y(!1)},e[32]=y,e[33]=h):h=e[33];let w;e[34]!==i||e[35]!==s?(w=s(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=s,e[36]=w):w=e[36];let T;e[37]!==v||e[38]!==S||e[39]!==h||e[40]!==w?(T=f("button",{className:v,"data-testid":"sql-assistant-generate",disabled:S,onClick:h,type:"button",children:w}),e[37]=v,e[38]=S,e[39]=h,e[40]=w,e[41]=T):T=e[41];let I;e[42]!==t||e[43]!==i||e[44]!==y||e[45]!==s?(I=t!==void 0&&f("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:i,onClick:()=>{y(!0)},type:"button",children:s("Fix this")}),e[42]=t,e[43]=i,e[44]=y,e[45]=s,e[46]=I):I=e[46];let R;e[47]!==T||e[48]!==I||e[49]!==p?(R=B("div",{className:"flex items-center gap-2",children:[p,T,I]}),e[47]=T,e[48]=I,e[49]=p,e[50]=R):R=e[50],u=B("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,g!==void 0&&f("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Je(g,s)})]}),e[2]=n,e[3]=t,e[4]=o,e[5]=i,e[6]=r,e[7]=s,e[8]=u}else u=e[8];return u},Dn=l=>{const e=X(8),{diagnostics:n,draft:t,scrollRef:o}=l;let s,r;if(e[0]!==n||e[1]!==t){r=Symbol.for("react.early_return_sentinel");e:{const i=An(n,t.length);if(i.length===0){r=null;break e}s=[];let u=0;for(const[g,d]of i.entries())d.start>u&&s.push(t.slice(u,d.start)),s.push(f("span",{className:ie("decoration-wavy underline underline-offset-4",d.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(d.start,d.end)},`${d.start.toString()}-${g.toString()}`)),u=d.end;s.push(t.slice(u))}e[0]=n,e[1]=t,e[2]=s,e[3]=r}else s=e[2],r=e[3];if(r!==Symbol.for("react.early_return_sentinel"))return r;let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=ie("pointer-events-none absolute inset-0 overflow-hidden text-transparent",_e),e[4]=c):c=e[4];let a;return e[5]!==s||e[6]!==o?(a=f("div",{"aria-hidden":"true",className:c,"data-testid":"sql-diagnostics-overlay",ref:o,children:s}),e[5]=s,e[6]=o,e[7]=a):a=e[7],a},On={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Mn=l=>{const e=X(10),{diagnostics:n,onSelect:t}=l,o=re();if(n.length===0)return null;let s;e[0]!==o?(s=o("SQL problems"),e[0]=o,e[1]=s):s=e[1];let r;if(e[2]!==n||e[3]!==t){let a;e[5]!==t?(a=(i,u)=>f("li",{children:B("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{t(i)},type:"button",children:[f("span",{className:ie("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",i.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:On[i.source]}),f("span",{className:"min-w-0 text-muted-foreground",children:i.message})]})},`${i.source}-${(i.offset??u).toString()}-${u.toString()}`),e[5]=t,e[6]=a):a=e[6],r=n.map(a),e[2]=n,e[3]=t,e[4]=r}else r=e[4];let c;return e[7]!==s||e[8]!==r?(c=f("ul",{"aria-label":s,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:r}),e[7]=s,e[8]=r,e[9]=c):c=e[9],c},$n=l=>(l.endsWith(`
|
|
4
|
+
`);return e.join("")},mt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,pt=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|truncate|update|vacuum)\b|\breplace\b(?!\s*\()/iu,ht=/^\w+/u,bt=/;\s*$/u,gt=/\s/u,Ke=l=>{let e=0;for(;e<l.length;){const n=l[e];if(n!==void 0&>.test(n))e+=1;else if(n==="-"&&l[e+1]==="-")e=He(l,e);else if(n==="/"&&l[e+1]==="*"){const t=Fe(l,e);if(t===-1)break;e=t}else break}return e},xt=l=>{const e=Ke(l),n=l.slice(e).trimEnd();if(n==="")return{code:"SQL_EMPTY",message:"the query is empty"};const o=(We(n)??n).replace(bt,""),s=n.slice(0,o.length),r=o.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const c="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!mt.test(s))return{code:"SQL_NOT_READONLY",length:ht.exec(s)?.[0].length??1,message:c,offset:e};const a=pt.exec(s);if(a!==null)return{code:"SQL_NOT_READONLY",length:a[0].length,message:`${c} (\`${a[0].toUpperCase()}\` is not allowed)`,offset:e+a.index}},vt=/^explain\b/iu,yt=l=>vt.test(l.slice(Ke(l)))?l:`EXPLAIN QUERY PLAN ${l}`,ke=(l,e)=>{const n=l.trim();if(n==="")return[];const t=e+l.indexOf(n),o=xt(n);return o?.code==="SQL_EMPTY"?[]:[o===void 0?{offset:t,sql:n}:{offset:t,rejection:o,sql:n}]},ze=l=>{const e=We(l);if(e===void 0)return ke(l,0);const n=[];let t=0;for(let o=0;o<=e.length;o+=1)o!==e.length&&e[o]!==";"||(n.push(...ke(l.slice(t,o),t)),t=o+1);return n},St=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],wt=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Se=String.fromCodePoint(0),Ct=new RegExp(`${Se}${String.raw`(\d+)`}${Se}`,"gu"),Nt=St.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),Et=wt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
|
|
5
|
+
${l}`})),kt=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,o=>(e.push(o),`${Se}${(e.length-1).toString()}${Se}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:o,replacement:s}of Nt)t=t.replaceAll(o,s);for(const{pattern:o,replacement:s}of Et)t=t.replaceAll(o,s);return t=t.replaceAll(Ct,(o,s)=>e[Number(s)]??""),t},Tt=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Rt=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,It=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),Lt=/[^\n]/gu,_t=(l,e)=>{const n=l[e];if(n==="'"){let t=e+1;for(;t<l.length&&l[t]!=="'";)t+=1;return Math.min(t+1,l.length)}if(n==="-"&&l[e+1]==="-"){const t=l.indexOf(`
|
|
6
|
+
`,e);return t===-1?l.length:t}if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);return t===-1?l.length:t+2}return-1},At=l=>{let e="",n=0;for(;n<l.length;){const t=_t(l,n);t===-1?(e+=l.slice(n,n+1),n+=1):(e+=l.slice(n,t).replaceAll(Lt," "),n=t)}return e},qt=l=>{const e=new Set;for(const n of l.matchAll(Rt))e.add((n[1]??"").toLowerCase());return e},Dt=(l,e)=>{const n=new Map;for(const t of l.matchAll(Tt)){const o=(t[1]??"").toLowerCase(),s=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),s!==""&&!It.has(s)&&n.set(s,o))}return n},Ue=(l,e)=>{const n=At(l),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:qt(n),masked:n,targets:Dt(n,t)}},Ot=/^(?:__lunora|sqlite_)/iu,Mt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,$t=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Bt=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Pt=(l,e,n)=>{const t=[];for(const o of l.matchAll(Mt)){const s=o[1]??"",r=s.toLowerCase();!e.has(r)&&!n.has(r)&&!Bt.has(r)&&!Ot.test(s)&&t.push({length:s.length,message:`unknown table \`${s}\``,offset:o.index+o[0].length-s.length,severity:"error",source:"schema"})}return t},Ht=(l,e,n)=>{const t=[],o=new Map;for(const[s,r]of Object.entries(e.columns))o.set(s.toLowerCase(),new Set(r.map(c=>c.toLowerCase())));for(const s of l.matchAll($t)){const r=(s[1]??"").toLowerCase(),c=s[2]??"",a=n.get(r),i=a===void 0?void 0:o.get(a);i!==void 0&&!i.has(c.toLowerCase())&&t.push({length:c.length,message:`\`${a??""}\` has no column \`${c}\``,offset:s.index+s[0].length-c.length,severity:"error",source:"schema"})}return t},Ft=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,Wt=/\bas\s+"?([a-z_][\w$]*)"?/giu,Kt=(l,e,n,t)=>{const o=[...new Set(n.values())],s=new Map,r=new Set;for(const i of o){for(const u of e.columns[i]??[])r.add(u.toLowerCase());for(const u of e.docFields?.[i]??[])s.set(u.toLowerCase(),u)}if(s.size===0)return[];const c=new Set([...l.matchAll(Wt)].map(i=>(i[1]??"").toLowerCase())),a=[];for(const i of l.matchAll(Ft)){const u=i[1],g=u??i[2]??"",d=g.toLowerCase(),y=s.get(d);y===void 0||r.has(d)||c.has(d)||t.has(d)||n.has(d)||a.push({length:g.length,message:`\`${y}\` is a \`__doc__\` field, not a column — use \`json_extract(__doc__, '$.${y}')\``,offset:i.index+(u===void 0?0:1),severity:"error",source:"schema"})}return a},zt=(l,e)=>{if(l.trim()==="")return[];const n=ze(l),t=new Set(e.tables.map(s=>s.toLowerCase())),o=[];for(const s of n){const{offset:r,rejection:c}=s;if(c!==void 0){o.push({length:c.length,message:c.message,offset:c.offset===void 0?r:r+c.offset,severity:"error",source:"gate"});continue}const{ctes:a,masked:i,targets:u}=Ue(s.sql,e.tables);o.push(...[...Pt(i,t,a),...Ht(i,e,u),...Kt(i,e,u,a)].map(g=>({...g,offset:g.offset===void 0?r:r+g.offset})))}return o},Ut=Ce(we.lintSql),jt=600,Qt=(l,e,n)=>{const t=Te(),[o,s]=se([]),r=Ae(()=>zt(l,e),[l,e]),c=ot(l,jt),i=r.some(d=>d.source==="gate")||c.trim()==="",u=Xe(async d=>{try{const y=await t.query(Ut,{sql:c},ye(n));d.cancelled||s(y.diagnostics??[])}catch{d.cancelled||s([])}},[t,c,n]);me(()=>{if(i){s([]);return}const d={cancelled:!1};return ce(u(d)),()=>{d.cancelled=!0}},[u,i]);const g=c===l;return Ae(()=>g?[...r,...o]:r,[r,o,g])},ge=8,Yt=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],Gt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Jt=/[\w$]/,je=l=>l!==void 0&&Jt.test(l),Qe=l=>{let e=l.length;for(;e>0&&je(l[e-1]);)e-=1;return l.slice(e)},Ye=(l,e)=>{let n=e;for(;n>0&&je(l[n-1]);)n-=1;return{end:e,start:n,text:l.slice(n,e)}},De=(l,e)=>{const n=l.slice(0,e).trimEnd();return n.endsWith(".")||Gt.has(Qe(n).toUpperCase())},Vt=(l,e,n)=>{const t=l.slice(0,e);if(!t.endsWith("."))return;const o=Qe(t.slice(0,-1));if(o!=="")return Ue(l,n).targets.get(o.toLowerCase())??o},Ie=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Oe=(l,e,n,t)=>{const o=[];for(const s of l)if(Ie(s,e)&&(o.push(t(s)),o.length>=n))break;return o},Xt=(l,e,n)=>{const t=new Map;for(const[o,s]of Object.entries(l.columns))for(const r of s)if(Ie(r,e)&&!t.has(r)&&(t.set(r,o),t.size>=n))return[...t].map(([c,a])=>({detail:a,kind:"column",label:c}));return[...t].map(([o,s])=>({detail:s,kind:"column",label:o}))},Zt=(l,e,n)=>{const t=Ye(l,e),o=Vt(l,t.start,n.tables);if(o!==void 0){const i=n.columns[o]??n.columns[o.toLowerCase()]??[];return Oe(i,t.text,ge,u=>({detail:o,kind:"column",label:u}))}if(t.text===""&&!De(l,t.start))return[];const s=Oe(n.tables,t.text,ge,i=>({kind:"table",label:i})),r=Xt(n,t.text,ge),c=Yt.flatMap(i=>t.text!==""&&Ie(i,t.text)&&i.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:i}]:[]);return(De(l,t.start)?[...r,...s,...c]:[...s,...r,...c]).slice(0,ge)},en=(l,e,n)=>{const t=Ye(l,e),o=l.slice(0,t.start)+n.label+l.slice(t.end);return{caret:t.start+n.label.length,value:o}},tn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],nn=(l,e)=>{const n=globalThis.getComputedStyle(l),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(const a of tn)o[a]=n[a];t.textContent=l.value.slice(0,Math.max(0,e));const s=globalThis.document.createElement("span");s.textContent=l.value.slice(Math.max(0,e))||".",t.append(s),globalThis.document.body.append(t);const r=s.offsetLeft-l.scrollLeft,c=s.offsetTop-l.scrollTop;return t.remove(),{left:r,top:c}},sn=(l,e,n)=>{const t=X(16),[o,s]=se(null);let r;t[0]!==l||t[1]!==e?(r=(x,p)=>{const C=Zt(x,p,l);if(C.length===0){s(null);return}const v=e.current,{left:S,top:h}=v===null?{left:0,top:0}:nn(v,p);s(w=>w!==null&&w.active===0&&w.left===S&&w.top===h&&w.suggestions.length===C.length&&w.suggestions.every((I,R)=>{const E=C.at(R);return I.kind===E?.kind&&I.label===E.label&&I.detail===E.detail})?w:{active:0,left:S,suggestions:C,top:h})},t[0]=l,t[1]=e,t[2]=r):r=t[2];const c=r;let a;t[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{s(null)},t[3]=a):a=t[3];const i=a;let u;t[4]===Symbol.for("react.memo_cache_sentinel")?(u=x=>{s(p=>{if(p===null)return p;const C=p.suggestions.length,v=(p.active+x+C)%C;return{...p,active:v}})},t[4]=u):u=t[4];const g=u;let d;t[5]!==n||t[6]!==o||t[7]!==e?(d=x=>{const p=e.current;if(o===null||p===null)return!1;const C=o.suggestions[x??o.active];if(C===void 0)return!1;const v=en(p.value,p.selectionStart,C);return n(v.value),s(null),requestAnimationFrame(()=>{const S=e.current;S!==null&&(S.focus(),S.setSelectionRange(v.caret,v.caret))}),!0},t[5]=n,t[6]=o,t[7]=e,t[8]=d):d=t[8];const y=d;let b;t[9]!==y?(b=()=>y(),t[9]=y,t[10]=b):b=t[10];const N=b;let m;return t[11]!==N||t[12]!==y||t[13]!==c||t[14]!==o?(m={close:i,commit:N,commitAt:y,move:g,refresh:c,state:o},t[11]=N,t[12]=y,t[13]=c,t[14]=o,t[15]=m):m=t[15],m},on={column:"column",keyword:"keyword",table:"table"},ln=20,rn=l=>{const e=X(17),{listboxId:n,onPick:t,state:o}=l,s=re();let r;e[0]!==o?(r=o===null?void 0:{left:o.left,top:o.top+ln},e[0]=o,e[1]=r):r=e[1];const c=r;if(o===null)return null;let a;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==s){let u;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==s?(u=(g,d)=>B("li",{"aria-selected":d===o.active,className:ie("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",d===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${d.toString()}`,onMouseDown:y=>{y.preventDefault(),t(d)},role:"option",children:[f("span",{className:"truncate font-mono",children:g.label}),g.detail!==void 0&&f("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:g.detail}),f("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:s(on[g.kind])})]},`${g.kind}:${g.label}`),e[8]=n,e[9]=t,e[10]=o.active,e[11]=s,e[12]=u):u=e[12],a=o.suggestions.map(u),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=s,e[7]=a}else a=e[7];let i;return e[13]!==n||e[14]!==c||e[15]!==a?(i=f("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:n,role:"listbox",style:c,children:a}),e[13]=n,e[14]=c,e[15]=a,e[16]=i):i=e[16],i},an=Ce(we.listTables),cn=Ce(we.readTablePage),dn=l=>{const e=X(18),n=Te();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[o,s]=se(t);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={},e[1]=r):r=e[1];const[c,a]=se(r);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={},e[2]=i):i=e[2];const[u,g]=se(i);let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[3]=d):d=e[3];const y=ue(d);let b,N;e[4]!==n||e[5]!==l?(b=()=>{const S={cancelled:!1};return ce((async()=>{try{const w=await n.query(an,{},ye(l));S.cancelled||(s(w.map(fn)),a({}),g({}),y.current=new Set)}catch{S.cancelled||(s([]),a({}),g({}),y.current=new Set)}})()),()=>{S.cancelled=!0}},N=[n,l],e[4]=n,e[5]=l,e[6]=b,e[7]=N):(b=e[6],N=e[7]),me(b,N);let m;e[8]!==n||e[9]!==l?(m=S=>{if(y.current.has(S))return;y.current.add(S),ce((async()=>{try{const w=await n.query(cn,{limit:1,offset:0,table:S},ye(l)),{sqlColumns:T}=w;if(T===void 0){y.current.delete(S);return}const I=new Set(T),R=w.columns.filter(E=>!I.has(E));a(E=>({...E,[S]:T})),g(E=>({...E,[S]:R}))}catch{y.current.delete(S)}})())},e[8]=n,e[9]=l,e[10]=m):m=e[10];const x=m;let p;e[11]!==c||e[12]!==u||e[13]!==o?(p={columns:c,docFields:u,tables:o},e[11]=c,e[12]=u,e[13]=o,e[14]=p):p=e[14];const C=p;let v;return e[15]!==x||e[16]!==C?(v={probe:x,schema:C},e[15]=x,e[16]=C,e[17]=v):v=e[17],v},Ne=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,un=l=>{const e=new Set;Ne.lastIndex=0;let n=Ne.exec(l);for(;n!==null;)e.add(n[1]??n[2]),n=Ne.exec(l);return[...e]};function fn(l){return l.name}const mn=l=>(l.metaKey||l.ctrlKey)&&!l.shiftKey&&!l.altKey&&l.key.toLowerCase()==="i",pn=l=>{const e=X(44),{inlineEditEnabled:n,onSubmit:t,probe:o,schema:s,setDraft:r}=l,c=Ze(),[a,i]=se(null),u=ue(null),g=ue(null),d=ue(null),y=sn(s,d,r),{close:b,commit:N,commitAt:m,move:x,refresh:p,state:C}=y;let v;e[0]!==m?(v=q=>{m(q)},e[0]=m,e[1]=v):v=e[1];const S=v;let h;e[2]!==p?(h=()=>{const q=d.current;q!==null&&q===document.activeElement&&p(q.value,q.selectionStart)},e[2]=p,e[3]=h):h=e[3];let w;e[4]!==p||e[5]!==s?(w=[p,s],e[4]=p,e[5]=s,e[6]=w):w=e[6],me(h,w);let T;e[7]!==o||e[8]!==p||e[9]!==r?(T=q=>{const{selectionStart:j,value:J}=q.target;r(J),i(null);for(const V of un(J))o(V);p(J,j)},e[7]=o,e[8]=p,e[9]=r,e[10]=T):T=e[10];const I=T;let R;e[11]!==p?(R=q=>{const j=q.currentTarget;p(j.value,j.selectionStart)},e[11]=p,e[12]=R):R=e[12];const E=R;let _;e[13]!==b||e[14]!==N||e[15]!==x?(_=q=>q.key==="ArrowDown"?(q.preventDefault(),x(1),!0):q.key==="ArrowUp"?(q.preventDefault(),x(-1),!0):q.key==="Escape"?(q.preventDefault(),b(),!0):(q.key==="Enter"||q.key==="Tab")&&!q.metaKey&&!q.ctrlKey&&N()?(q.preventDefault(),!0):!1,e[13]=b,e[14]=N,e[15]=x,e[16]=_):_=e[16];const L=_;let A;e[17]!==C||e[18]!==b||e[19]!==n||e[20]!==L||e[21]!==t?(A=q=>{if(!(C!==null&&L(q))){if((q.metaKey||q.ctrlKey)&&q.key==="Enter"){q.preventDefault(),t();return}if(n&&mn(q)){q.preventDefault(),b();const{selectionEnd:j,selectionStart:J,value:V}=q.currentTarget,[U,G]=J===j?[0,V.length]:[J,j];i({end:G,start:U,text:V.slice(U,G)})}}},e[17]=C,e[18]=b,e[19]=n,e[20]=L,e[21]=t,e[22]=A):A=e[22];const M=A;let W;e[23]!==b?(W=()=>{requestAnimationFrame(()=>{b()})},e[23]=b,e[24]=W):W=e[24];const K=W;let $;e[25]===Symbol.for("react.memo_cache_sentinel")?($=q=>{const{scrollLeft:j,scrollTop:J}=q.currentTarget;u.current!==null&&(u.current.scrollTop=J),g.current!==null&&(g.current.scrollTop=J,g.current.scrollLeft=j)},e[25]=$):$=e[25];const F=$;let H;e[26]===Symbol.for("react.memo_cache_sentinel")?(H=q=>{const j=d.current;j===null||q.offset===void 0||(j.focus(),j.setSelectionRange(q.offset,q.offset+(q.length??0)))},e[26]=H):H=e[26];const k=H;let D;e[27]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{i(null),d.current?.focus()},e[27]=D):D=e[27];const z=D;let P;e[28]!==a||e[29]!==r?(P=q=>{const j=d.current;if(a===null||j===null)return;const{end:J,start:V,text:U}=a;if(j.value.slice(V,J)!==U){z();return}r(j.value.slice(0,V)+q+j.value.slice(J)),i(null),j.focus(),requestAnimationFrame(()=>{j.setSelectionRange(V,V+q.length)})},e[28]=a,e[29]=r,e[30]=P):P=e[30];const oe=P;let Z;e[31]!==I||e[32]!==K||e[33]!==M||e[34]!==E?(Z={onBlur:K,onChange:I,onKeyDown:M,onScroll:F,onSelect:E},e[31]=I,e[32]=K,e[33]=M,e[34]=E,e[35]=Z):Z=e[35];let ne;return e[36]!==oe||e[37]!==C||e[38]!==b||e[39]!==a||e[40]!==c||e[41]!==S||e[42]!==Z?(ne={acceptInlineEdit:oe,autocompleteState:C,closeAutocomplete:b,closeInlineEdit:z,inlineEdit:a,handlers:Z,listboxId:c,onPickSuggestion:S,editorRef:d,gutterRef:u,overlayRef:g,revealDiagnostic:k},e[36]=oe,e[37]=C,e[38]=b,e[39]=a,e[40]=c,e[41]=S,e[42]=Z,e[43]=ne):ne=e[43],ne},hn="lunora-studio-sql-tabs",bn="lunora-studio-sql-active-tab",Le=12,pe=(l="",e="")=>({activeId:null,id:Be("tab"),name:e,sql:l}),gn=()=>Re(bn,""),xn=l=>{const e=X(16),[n,t]=Ee(hn),[o,s]=gn(),[r]=se(l);let c,a;e[0]!==r||e[1]!==t||e[2]!==n.length?(c=()=>{n.length===0&&t([r])},a=[r,t,n.length],e[0]=r,e[1]=t,e[2]=n.length,e[3]=c,e[4]=a):(c=e[3],a=e[4]),me(c,a);let i;e[5]!==r||e[6]!==n?(i=n.length===0?[r]:n,e[5]=r,e[6]=n,e[7]=i):i=e[7];const u=i;let g;e[8]!==o||e[9]!==u?(g=u.some(b=>b.id===o)?o:u[0]?.id??"",e[8]=o,e[9]=u,e[10]=g):g=e[10];const d=g;let y;return e[11]!==d||e[12]!==s||e[13]!==t||e[14]!==u?(y={activeId:d,setActiveId:s,setTabs:t,tabs:u},e[11]=d,e[12]=s,e[13]=t,e[14]=u,e[15]=y):y=e[15],y},Ge=l=>l.activeId===null&&l.sql.trim()!=="",vn=(l,e)=>[...l,e].slice(-Le),yn=(l,e,n)=>{const t=l.findIndex(r=>r.id===e);if(t===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const o=l.filter(r=>r.id!==e);if(o.length===0){const r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},Sn=(l,e)=>{const n=l.filter(t=>t.id===e);return n.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:n}},wn=(l,e,n)=>{const t=l.findIndex(s=>s.id===e);if(t===-1)return{activeId:n,tabs:[...l]};const o=l.slice(0,t+1);return{activeId:o.some(s=>s.id===n)?n:e,tabs:o}},Cn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Nn=(l,e,n)=>{if(l==="others")return e.filter(t=>t.id!==n);if(l==="right"){const t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},Me={error:null,pane:"results",result:null,running:!1},En=l=>{const e=X(66),{activeId:n,setActiveId:t,setTabs:o,tabs:s}=xn(l);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},e[0]=r):r=e[0];const[c,a]=se(r),[i,u]=se(null),[g,d]=se(null);let y;e[1]!==n||e[2]!==s?(y=s.find(O=>O.id===n)??s[0]??pe(),e[1]=n,e[2]=s,e[3]=y):y=e[3];const b=y,N=c[b.id]??Me;let m;e[4]!==b.id||e[5]!==o?(m=O=>{o(Q=>Q.map(ee=>ee.id===b.id?{...ee,...O}:ee))},e[4]=b.id,e[5]=o,e[6]=m):m=e[6];const x=m;let p;e[7]!==b.id?(p=O=>{a(Q=>{const ee=Q[b.id]??Me;return{...Q,[b.id]:{...ee,...O}}})},e[7]=b.id,e[8]=p):p=e[8];const C=p;let v;e[9]!==t||e[10]!==o||e[11]!==s.length?(v=()=>{if(s.length>=Le)return;const O=pe();o(Q=>vn(Q,O)),t(O.id)},e[9]=t,e[10]=o,e[11]=s.length,e[12]=v):v=e[12];const S=v;let h;e[13]!==t||e[14]!==o?(h=O=>{u(null),d(null),o(O.tabs),t(O.activeId);const Q=new Set(O.tabs.map(kn));a(ee=>Object.fromEntries(Object.entries(ee).filter(ae=>{const[de]=ae;return Q.has(de)})))},e[13]=t,e[14]=o,e[15]=h):h=e[15];const w=h;let T;e[16]!==w||e[17]!==s?(T=O=>{w(yn(s,O,pe))},e[16]=w,e[17]=s,e[18]=T):T=e[18];const I=T;let R;e[19]!==n||e[20]!==w||e[21]!==s?(R=(O,Q)=>{w(O==="others"?Sn(s,Q):O==="right"?wn(s,Q,n):Cn(pe))},e[19]=n,e[20]=w,e[21]=s,e[22]=R):R=e[22];const E=R;let _;e[23]!==E||e[24]!==i||e[25]!==s?(_=O=>{i!==null&&(Nn(O,s,i.id).some(Tn)?d(O):E(O,i.id))},e[23]=E,e[24]=i,e[25]=s,e[26]=_):_=e[26];const L=_;let A;e[27]===Symbol.for("react.memo_cache_sentinel")?(A=(O,Q)=>{Q.preventDefault(),d(null),u({id:O,x:Q.clientX,y:Q.clientY})},e[27]=A):A=e[27];const M=A;let W;e[28]===Symbol.for("react.memo_cache_sentinel")?(W=()=>{u(null),d(null)},e[28]=W):W=e[28];const K=W;let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=O=>{O.preventDefault(),u(null),d(null)},e[29]=$):$=e[29];const F=$;let H;e[30]!==L?(H=()=>{L("others")},e[30]=L,e[31]=H):H=e[31];const k=H;let D;e[32]!==L?(D=()=>{L("right")},e[32]=L,e[33]=D):D=e[33];const z=D;let P;e[34]!==L?(P=()=>{L("all")},e[34]=L,e[35]=P):P=e[35];const oe=P;let Z;e[36]!==E||e[37]!==g||e[38]!==i?(Z=()=>{i!==null&&g!==null&&E(g,i.id),d(null)},e[36]=E,e[37]=g,e[38]=i,e[39]=Z):Z=e[39];const ne=Z;let q;e[40]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{d(null)},e[40]=q):q=e[40];const j=q;let J;e[41]!==i?(J=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=J):J=e[42];const V=J;let U;e[43]!==o?(U=O=>{o(Q=>Q.map(ee=>ee.activeId===O?{...ee,activeId:null}:ee))},e[43]=o,e[44]=U):U=e[44];const G=U;let Y;e[45]!==o?(Y=(O,Q)=>{o(ee=>ee.map(ae=>ae.id===O?{...ae,name:Q}:ae))},e[45]=o,e[46]=Y):Y=e[46];const te=Y;let le;return e[47]!==b||e[48]!==n||e[49]!==S||e[50]!==I||e[51]!==ne||e[52]!==oe||e[53]!==k||e[54]!==z||e[55]!==N||e[56]!==C||e[57]!==x||e[58]!==g||e[59]!==te||e[60]!==t||e[61]!==i||e[62]!==V||e[63]!==s||e[64]!==G?(le={activeTab:b,activeTabId:n,addEditorTab:S,cancelBulk:j,closeEditorTab:I,closeTabMenu:K,confirmBulk:ne,menuStyle:V,onBackdropContextMenu:F,onCloseAll:oe,onCloseOthers:k,onCloseToRight:z,openTabMenu:M,output:N,patchActiveOutput:C,patchActiveTab:x,pendingBulk:g,renameTab:te,setActiveTabId:t,tabMenu:i,tabs:s,unlinkQuery:G},e[47]=b,e[48]=n,e[49]=S,e[50]=I,e[51]=ne,e[52]=oe,e[53]=k,e[54]=z,e[55]=N,e[56]=C,e[57]=x,e[58]=g,e[59]=te,e[60]=t,e[61]=i,e[62]=V,e[63]=s,e[64]=G,e[65]=le):le=e[65],le};function kn(l){return l.id}function Tn(l){return Ge(l)}const Rn="lunora-studio-sql-queries",fe="lunora-studio-sql-history",In="lunora-studio-sql-remember-history",Ln=25,_n=l=>{const e=X(41),{loadIntoActiveTab:n,unlinkQuery:t}=l,o=re(),[s,r]=Ee(Rn),[c,a]=Re(In,!1),[i,u]=Ee(fe,c?"local":"session");let g,d;e[0]!==c?(g=()=>{c||be(fe,"local")},d=[c],e[0]=c,e[1]=g,e[2]=d):(g=e[1],d=e[2]),me(g,d);const[y,b]=se(""),N=ue(null);let m;e[3]!==u?(m=k=>{u(D=>D[0]?.sql===k?D:[{at:Date.now(),sql:k},...D.filter(P=>P.sql!==k)].slice(0,Ln))},e[3]=u,e[4]=m):m=e[4];const x=m;let p;e[5]!==n||e[6]!==r||e[7]!==o?(p=()=>{const k={id:Be("q"),name:o("Untitled query"),sql:""};r(D=>[k,...D]),n("",k.id)},e[5]=n,e[6]=r,e[7]=o,e[8]=p):p=e[8];const C=p;let v;e[9]!==n||e[10]!==s?(v=k=>{const D=s.find(z=>z.id===k);D!==void 0&&(n(D.sql,k),N.current?.querySelector(`[data-testid="sql-query-${k}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=n,e[10]=s,e[11]=v):v=e[11];const S=v;let h;e[12]!==r||e[13]!==t?(h=k=>{r(D=>D.filter(z=>z.id!==k)),t(k)},e[12]=r,e[13]=t,e[14]=h):h=e[14];const w=h;let T;e[15]!==n?(T=k=>{n(k.currentTarget.dataset.sql??"",null)},e[15]=n,e[16]=T):T=e[16];const I=T;let R;e[17]!==n?(R=k=>{n(k.currentTarget.dataset.sql??"",null)},e[17]=n,e[18]=R):R=e[18];const E=R;let _;e[19]!==u?(_=()=>{u([]),be(fe,"local"),be(fe,"session")},e[19]=u,e[20]=_):_=e[20];const L=_;let A;e[21]!==i||e[22]!==a?(A=k=>{et(fe,i,k?"local":"session"),k||be(fe,"local"),a(k)},e[21]=i,e[22]=a,e[23]=A):A=e[23];const M=A;let W;e[24]===Symbol.for("react.memo_cache_sentinel")?(W=k=>{b(k.target.value)},e[24]=W):W=e[24];const K=W;let $;e[25]!==r?($=(k,D)=>{r(z=>z.map(P=>P.id===k?{...P,sql:D}:P))},e[25]=r,e[26]=$):$=e[26];const F=$;let H;return e[27]!==L||e[28]!==w||e[29]!==i||e[30]!==E||e[31]!==I||e[32]!==C||e[33]!==s||e[34]!==x||e[35]!==c||e[36]!==y||e[37]!==S||e[38]!==M||e[39]!==F?(H={clearHistory:L,deleteQuery:w,history:i,listRef:N,loadFromHistory:E,loadTemplate:I,newQuery:C,onSearchChange:K,queries:s,recordHistory:x,rememberHistory:c,search:y,selectQuery:S,setRememberHistory:M,updateQuerySql:F},e[27]=L,e[28]=w,e[29]=i,e[30]=E,e[31]=I,e[32]=C,e[33]=s,e[34]=x,e[35]=c,e[36]=y,e[37]=S,e[38]=M,e[39]=F,e[40]=H):H=e[40],H},_e="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",An=(l,e)=>{const n=[];for(const o of l){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;const s=Math.max(0,Math.min(o.offset,e)),r=Math.max(s,Math.min(o.offset+o.length,e));s!==r&&n.push({end:r,severity:o.severity,start:s})}n.sort((o,s)=>o.start-s.start);const t=[];for(const o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},Je=(l,e)=>e(l==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":l==="too-long"?"The statement is too long to rewrite. Select a shorter part of it.":l==="empty-response"?"The model returned nothing usable.":"The model could not be reached."),qn=l=>{const e=X(51),{assistant:n,failed:t,onGenerated:o}=l,s=re(),[r,c]=se("");if(n.unavailable)return null;let a;e[0]!==n?(a=n.pending("sql"),e[0]=n,e[1]=a):a=e[1];const i=a;let u;if(e[2]!==n||e[3]!==t||e[4]!==o||e[5]!==i||e[6]!==r||e[7]!==s){const g=n.reason("sql");let d;e[9]!==n||e[10]!==t||e[11]!==o||e[12]!==r?(d=E=>{const _=r.trim();if(_===""&&!E)return;ce((async()=>{const A=await n.generate(_===""?"fix the failing statement":_,E?t:void 0);A!==void 0&&o(A)})())},e[9]=n,e[10]=t,e[11]=o,e[12]=r,e[13]=d):d=e[13];const y=d;let b;e[14]!==s?(b=s("Describe the query you want"),e[14]=s,e[15]=b):b=e[15];let N;e[16]===Symbol.for("react.memo_cache_sentinel")?(N=E=>{c(E.target.value)},e[16]=N):N=e[16];let m;e[17]!==y?(m=E=>{E.key==="Enter"&&(E.preventDefault(),y(!1))},e[17]=y,e[18]=m):m=e[18];let x;e[19]!==s?(x=s("Describe the query you want"),e[19]=s,e[20]=x):x=e[20];let p;e[21]!==i||e[22]!==r||e[23]!==b||e[24]!==m||e[25]!==x?(p=f(Pe,{"aria-label":b,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:i,onChange:N,onKeyDown:m,placeholder:x,value:r}),e[21]=i,e[22]=r,e[23]=b,e[24]=m,e[25]=x,e[26]=p):p=e[26];const C=i&&"opacity-60";let v;e[27]!==C?(v=ie("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",C),e[27]=C,e[28]=v):v=e[28];let S;e[29]!==i||e[30]!==r?(S=i||r.trim()==="",e[29]=i,e[30]=r,e[31]=S):S=e[31];let h;e[32]!==y?(h=()=>{y(!1)},e[32]=y,e[33]=h):h=e[33];let w;e[34]!==i||e[35]!==s?(w=s(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=s,e[36]=w):w=e[36];let T;e[37]!==v||e[38]!==S||e[39]!==h||e[40]!==w?(T=f("button",{className:v,"data-testid":"sql-assistant-generate",disabled:S,onClick:h,type:"button",children:w}),e[37]=v,e[38]=S,e[39]=h,e[40]=w,e[41]=T):T=e[41];let I;e[42]!==t||e[43]!==i||e[44]!==y||e[45]!==s?(I=t!==void 0&&f("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:i,onClick:()=>{y(!0)},type:"button",children:s("Fix this")}),e[42]=t,e[43]=i,e[44]=y,e[45]=s,e[46]=I):I=e[46];let R;e[47]!==T||e[48]!==I||e[49]!==p?(R=B("div",{className:"flex items-center gap-2",children:[p,T,I]}),e[47]=T,e[48]=I,e[49]=p,e[50]=R):R=e[50],u=B("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,g!==void 0&&f("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Je(g,s)})]}),e[2]=n,e[3]=t,e[4]=o,e[5]=i,e[6]=r,e[7]=s,e[8]=u}else u=e[8];return u},Dn=l=>{const e=X(8),{diagnostics:n,draft:t,scrollRef:o}=l;let s,r;if(e[0]!==n||e[1]!==t){r=Symbol.for("react.early_return_sentinel");e:{const i=An(n,t.length);if(i.length===0){r=null;break e}s=[];let u=0;for(const[g,d]of i.entries())d.start>u&&s.push(t.slice(u,d.start)),s.push(f("span",{className:ie("decoration-wavy underline underline-offset-4",d.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(d.start,d.end)},`${d.start.toString()}-${g.toString()}`)),u=d.end;s.push(t.slice(u))}e[0]=n,e[1]=t,e[2]=s,e[3]=r}else s=e[2],r=e[3];if(r!==Symbol.for("react.early_return_sentinel"))return r;let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=ie("pointer-events-none absolute inset-0 overflow-hidden text-transparent",_e),e[4]=c):c=e[4];let a;return e[5]!==s||e[6]!==o?(a=f("div",{"aria-hidden":"true",className:c,"data-testid":"sql-diagnostics-overlay",ref:o,children:s}),e[5]=s,e[6]=o,e[7]=a):a=e[7],a},On={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Mn=l=>{const e=X(10),{diagnostics:n,onSelect:t}=l,o=re();if(n.length===0)return null;let s;e[0]!==o?(s=o("SQL problems"),e[0]=o,e[1]=s):s=e[1];let r;if(e[2]!==n||e[3]!==t){let a;e[5]!==t?(a=(i,u)=>f("li",{children:B("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{t(i)},type:"button",children:[f("span",{className:ie("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",i.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:On[i.source]}),f("span",{className:"min-w-0 text-muted-foreground",children:i.message})]})},`${i.source}-${(i.offset??u).toString()}-${u.toString()}`),e[5]=t,e[6]=a):a=e[6],r=n.map(a),e[2]=n,e[3]=t,e[4]=r}else r=e[4];let c;return e[7]!==s||e[8]!==r?(c=f("ul",{"aria-label":s,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:r}),e[7]=s,e[8]=r,e[9]=c):c=e[9],c},$n=l=>(l.endsWith(`
|
|
7
7
|
`)?l.slice(0,-1):l).split(`
|
|
8
|
-
`),Bn=(l,e)=>{const n=[];let t=1,o=1;for(const s of lt(l,e,{ignoreNewlineAtEof:!0}))for(const r of $n(s.value))s.added?(n.push({after:o,kind:"added",text:r}),o+=1):s.removed?(n.push({before:t,kind:"removed",text:r}),t+=1):(n.push({after:o,before:t,kind:"context",text:r}),t+=1,o+=1);return n},Pn={added:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400",context:"text-muted-foreground",removed:"bg-destructive/10 text-destructive"},Hn={added:"+",context:" ",removed:"-"},Fn=l=>{const e=X(11),{lines:n}=l,t=re();let o;e[0]!==t?(o=t("Proposed edit"),e[0]=t,e[1]=o):o=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=ie("max-h-48 overflow-auto rounded-md border border-border bg-background",_e),e[2]=s):s=e[2];let r;if(e[3]!==n||e[4]!==t){let a;e[6]!==t?(a=i=>B("li",{className:ie("flex gap-2",Pn[i.kind]),"data-kind":i.kind,children:[f("span",{"aria-hidden":"true",className:"shrink-0 select-none opacity-60",children:Hn[i.kind]}),i.kind!=="context"&&f("span",{className:"sr-only",children:i.kind==="added"?t("Added"):t("Removed")}),f("span",{className:"min-w-0",children:i.text===""?" ":i.text})]},`${String(i.before)}:${String(i.after)}`),e[6]=t,e[7]=a):a=e[7],r=n.map(a),e[3]=n,e[4]=t,e[5]=r}else r=e[5];let c;return e[8]!==o||e[9]!==r?(c=f("ul",{"aria-label":o,className:s,"data-testid":"sql-inline-diff",children:r}),e[8]=o,e[9]=r,e[10]=c):c=e[10],c},xe="rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",Wn=l=>{const e=X(41),{onAccept:n,onCancel:t,rpc:o,source:s,whole:r}=l,c=re(),a=ue(null),i=ue(null),[u,g]=se(""),[d,y]=se(null);let b,
|
|
9
|
-
`).length;I="flex min-h-0 min-w-0 flex-1 flex-col",e[17]!==n||e[18]!==r||e[19]!==b?(R=f(qn,{assistant:n,failed:r,onGenerated:b}),e[17]=n,e[18]=r,e[19]=b,e[20]=R):R=e[20],e[21]!==n||e[22]!==s.length||e[23]!==u||e[24]!==d||e[25]!==y?(E=u!==null&&f(Wn,{onAccept:d,onCancel:y,rpc:n,source:u.text,whole:u.start===0&&u.end===s.length},`${u.start.toString()}-${u.end.toString()}`),e[21]=n,e[22]=s.length,e[23]=u,e[24]=d,e[25]=y,e[26]=E):E=e[26],T="flex min-h-0 min-w-0 flex-1",N="true",v="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",S=i,h=Kn,w=Array.from({length:P},Un),e[0]=n,e[1]=s,e[2]=r,e[3]=i,e[4]=u,e[5]=d,e[6]=y,e[7]=b,e[8]=N,e[9]=v,e[10]=S,e[11]=h,e[12]=w,e[13]=T,e[14]=I,e[15]=R,e[16]=E}else N=e[8],v=e[9],S=e[10],h=e[11],w=e[12],T=e[13],I=e[14],R=e[15],E=e[16];let _;e[27]!==N||e[28]!==v||e[29]!==S||e[30]!==h||e[31]!==w?(_=f("div",{"aria-hidden":N,className:v,ref:S,style:h,children:w}),e[27]=N,e[28]=v,e[29]=S,e[30]=h,e[31]=w,e[32]=_):_=e[32];let L;e[33]!==o||e[34]!==s||e[35]!==x?(L=f(Dn,{diagnostics:o,draft:s,scrollRef:x}),e[33]=o,e[34]=s,e[35]=x,e[36]=L):L=e[36];let A;e[37]!==t||e[38]!==g?(A=t===null?void 0:`${g}-opt-${t.active.toString()}`,e[37]=t,e[38]=g,e[39]=A):A=e[39];const M=t===null?void 0:g,W=t!==null;let K;e[40]!==p?(K=p("SQL query"),e[40]=p,e[41]=K):K=e[41];let $;e[42]!==s||e[43]!==a||e[44]!==c.onBlur||e[45]!==c.onChange||e[46]!==c.onKeyDown||e[47]!==c.onScroll||e[48]!==c.onSelect||e[49]!==A||e[50]!==M||e[51]!==W||e[52]!==K?($=f("textarea",{"aria-activedescendant":A,"aria-autocomplete":"list","aria-controls":M,"aria-expanded":W,"aria-label":K,className:`relative size-full resize-none bg-transparent outline-none ${_e}`,"data-testid":"sql-input",onBlur:c.onBlur,onChange:c.onChange,onKeyDown:c.onKeyDown,onScroll:c.onScroll,onSelect:c.onSelect,placeholder:"SELECT * FROM …",ref:a,role:"combobox",spellCheck:!1,value:s}),e[42]=s,e[43]=a,e[44]=c.onBlur,e[45]=c.onChange,e[46]=c.onKeyDown,e[47]=c.onScroll,e[48]=c.onSelect,e[49]=A,e[50]=M,e[51]=W,e[52]=K,e[53]=$):$=e[53];let F;e[54]!==t||e[55]!==g||e[56]!==C?(F=f(rn,{listboxId:g,onPick:C,state:t}),e[54]=t,e[55]=g,e[56]=C,e[57]=F):F=e[57];let H;e[58]!==L||e[59]!==$||e[60]!==F?(H=B("div",{className:"relative min-w-0 flex-1 bg-background",children:[L,$,F]}),e[58]=L,e[59]=$,e[60]=F,e[61]=H):H=e[61];let k;e[62]!==_||e[63]!==H||e[64]!==T?(k=B("div",{className:T,children:[_,H]}),e[62]=_,e[63]=H,e[64]=T,e[65]=k):k=e[65];let D;e[66]!==o||e[67]!==m?(D=f(Mn,{diagnostics:o,onSelect:m}),e[66]=o,e[67]=m,e[68]=D):D=e[68];let z;return e[69]!==k||e[70]!==D||e[71]!==I||e[72]!==R||e[73]!==E?(z=B("div",{className:I,children:[R,E,k,D]}),e[69]=k,e[70]=D,e[71]=I,e[72]=R,e[73]=E,e[74]=z):z=e[74],z};function Un(l,e){return f("div",{children:e+1},e)}const Ve=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],jn=l=>{const e=X(29),{active:n,onDelete:t,onSelect:o,query:s}=l,r=re();let c;e[0]!==o||e[1]!==s.id?(c=()=>{o(s.id)},e[0]=o,e[1]=s.id,e[2]=c):c=e[2];const a=c;let i;e[3]!==t||e[4]!==s.id?(i=h=>{h.stopPropagation(),t(s.id)},e[3]=t,e[4]=s.id,e[5]=i):i=e[5];const u=i,g=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let d;e[6]!==g?(d=ie("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[6]=g,e[7]=d):d=e[7];const y=`sql-query-${s.id}`;let b;e[8]===Symbol.for("react.memo_cache_sentinel")?(b=f("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=b):b=e[8];let C;e[9]!==s.name?(C=f("span",{className:"truncate",children:s.name}),e[9]=s.name,e[10]=C):C=e[10];let m;e[11]!==n||e[12]!==a||e[13]!==d||e[14]!==y||e[15]!==C?(m=B("button",{"aria-pressed":n,className:d,"data-testid":y,onClick:a,type:"button",children:[b,C]}),e[11]=n,e[12]=a,e[13]=d,e[14]=y,e[15]=C,e[16]=m):m=e[16];let x;e[17]!==r?(x=r("Delete query"),e[17]=r,e[18]=x):x=e[18];let p;e[19]!==r?(p=r("Delete query"),e[19]=r,e[20]=p):p=e[20];let N;e[21]===Symbol.for("react.memo_cache_sentinel")?(N=f("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=N):N=e[21];let v;e[22]!==u||e[23]!==p||e[24]!==x?(v=f("button",{"aria-label":x,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:u,title:p,type:"button",children:N}),e[22]=u,e[23]=p,e[24]=x,e[25]=v):v=e[25];let S;return e[26]!==v||e[27]!==m?(S=B("li",{className:"group/q flex items-center",children:[m,v]}),e[26]=v,e[27]=m,e[28]=S):S=e[28],S},$e="sql-history-remember",Qn=(l,e)=>{const n=e.trim().toLowerCase();return n===""?[...l]:l.filter(t=>t.name.toLowerCase().includes(n))},Yn=l=>{const e=X(66),{activeId:n,history:t,listRef:o,onClearHistory:s,onDelete:r,onLoadHistory:c,onLoadTemplate:a,onNew:i,onSearchChange:u,onSelect:g,onToggleRememberHistory:d,queries:y,rememberHistory:b,search:C}=l,m=re();let x,p,N,v,S;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i||e[4]!==u||e[5]!==g||e[6]!==d||e[7]!==y||e[8]!==C||e[9]!==m){const A=Qn(y,C);let M;e[15]!==d?(M=P=>{d(P.target.checked)},e[15]=d,e[16]=M):M=e[16],x=M,N="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let W;e[17]!==m?(W=m("Search queries…"),e[17]=m,e[18]=W):W=e[18];let K;e[19]!==u||e[20]!==C||e[21]!==W?(K=f("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:u,placeholder:W,type:"text",value:C}),e[19]=u,e[20]=C,e[21]=W,e[22]=K):K=e[22];let $;e[23]!==m?($=m("New query"),e[23]=m,e[24]=$):$=e[24];let F;e[25]!==m?(F=m("New query"),e[25]=m,e[26]=F):F=e[26];let H;e[27]===Symbol.for("react.memo_cache_sentinel")?(H=f("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:f("path",{d:"M12 5v14M5 12h14"})}),e[27]=H):H=e[27];let k;e[28]!==i||e[29]!==$||e[30]!==F?(k=f("button",{"aria-label":$,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:i,title:F,type:"button",children:H}),e[28]=i,e[29]=$,e[30]=F,e[31]=k):k=e[31],e[32]!==k||e[33]!==K?(v=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[K,k]}),e[32]=k,e[33]=K,e[34]=v):v=e[34],p="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let D;e[35]!==m?(D=m("Private"),e[35]=m,e[36]=D):D=e[36];let z;e[37]!==D?(z=f("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[37]=D,e[38]=z):z=e[38],S=B("div",{children:[z,A.length===0?f("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:m("No saved queries yet — they save to this browser as you type.")}):f("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:A.map(P=>f(jn,{active:n===P.id,onDelete:r,onSelect:g,query:P},P.id))})]}),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=u,e[5]=g,e[6]=d,e[7]=y,e[8]=C,e[9]=m,e[10]=x,e[11]=p,e[12]=N,e[13]=v,e[14]=S}else x=e[10],p=e[11],N=e[12],v=e[13],S=e[14];let h;e[39]!==m?(h=m("Reference"),e[39]=m,e[40]=h):h=e[40];let w;e[41]!==h?(w=f("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:h}),e[41]=h,e[42]=w):w=e[42];let T;e[43]!==a?(T=Ve.map(A=>f("li",{children:B("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":A.sql,onClick:a,type:"button",children:[f("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),A.label]})},A.label)),e[43]=a,e[44]=T):T=e[44];let I;e[45]!==T?(I=f("ul",{className:"flex flex-col gap-px",children:T}),e[45]=T,e[46]=I):I=e[46];let R;e[47]!==w||e[48]!==I?(R=B("div",{children:[w,I]}),e[47]=w,e[48]=I,e[49]=R):R=e[49];let E;e[50]!==t||e[51]!==s||e[52]!==c||e[53]!==x||e[54]!==b||e[55]!==m?(E=t.length>0&&B("div",{children:[B("div",{className:"flex items-center justify-between px-1 pb-1",children:[f("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m("History")}),f("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:s,type:"button",children:m("Clear history")})]}),B("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:$e,children:[f("input",{checked:b,"data-testid":"sql-history-remember",id:$e,onChange:x,type:"checkbox"}),m("Keep history on this browser")]}),f("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(A=>f("li",{children:B("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":A.sql,"data-testid":"sql-history-item",onClick:c,title:A.sql,type:"button",children:[f("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),f("span",{className:"truncate font-mono",children:A.sql})]})},`${A.at.toString()}:${A.sql}`))})]}),e[50]=t,e[51]=s,e[52]=c,e[53]=x,e[54]=b,e[55]=m,e[56]=E):E=e[56];let _;e[57]!==p||e[58]!==E||e[59]!==S||e[60]!==R?(_=B("div",{className:p,children:[S,R,E]}),e[57]=p,e[58]=E,e[59]=S,e[60]=R,e[61]=_):_=e[61];let L;return e[62]!==_||e[63]!==N||e[64]!==v?(L=B("aside",{className:N,children:[v,_]}),e[62]=_,e[63]=N,e[64]=v,e[65]=L):L=e[65],L},ve=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,Gn=l=>{const e=X(97),{assistant:n,chart:t,className:o,durationMs:s,error:r,onFormat:c,onInferChart:a,onRun:i,onSelectStatement:u,onShardKeyChange:g,onShowChart:d,onShowExplain:y,onShowResults:b,onToggleSplit:C,pane:m,result:x,running:p,script:N,shardKey:v,splitView:S}=l,h=re(),w=m==="results";let T;e[0]!==w?(T=ve(w),e[0]=w,e[1]=T):T=e[1];let I;e[2]!==h?(I=h("Results"),e[2]=h,e[3]=I):I=e[3];let R;e[4]!==b||e[5]!==T||e[6]!==I?(R=f("button",{className:T,"data-testid":"sql-tab-results",onClick:b,type:"button",children:I}),e[4]=b,e[5]=T,e[6]=I,e[7]=R):R=e[7];const E=m==="chart";let _;e[8]!==E?(_=ve(E),e[8]=E,e[9]=_):_=e[9];let L;e[10]!==h?(L=h("Chart"),e[10]=h,e[11]=L):L=e[11];let A;e[12]!==d||e[13]!==_||e[14]!==L?(A=f("button",{className:_,"data-testid":"sql-tab-chart",onClick:d,type:"button",children:L}),e[12]=d,e[13]=_,e[14]=L,e[15]=A):A=e[15];let M;e[16]!==n||e[17]!==a||e[18]!==m||e[19]!==x||e[20]!==h?(M=!n.unavailable&&m==="chart"&&x!==null&&f("button",{className:ve(!1),"data-testid":"sql-infer-chart",disabled:n.pending("chart"),onClick:a,type:"button",children:n.pending("chart")?h("Thinking…"):h("Suggest chart")}),e[16]=n,e[17]=a,e[18]=m,e[19]=x,e[20]=h,e[21]=M):M=e[21];const W=m==="explain";let K;e[22]!==W?(K=ve(W),e[22]=W,e[23]=K):K=e[23];let $;e[24]!==h?($=h("Explain"),e[24]=h,e[25]=$):$=e[25];let F;e[26]!==y||e[27]!==K||e[28]!==$?(F=f("button",{className:K,"data-testid":"sql-tab-explain",onClick:y,type:"button",children:$}),e[26]=y,e[27]=K,e[28]=$,e[29]=F):F=e[29];let H;e[30]!==h?(H=h("Split editor and results"),e[30]=h,e[31]=H):H=e[31];const k=`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${S?"bg-accent text-foreground":"text-muted-foreground"}`;let D;e[32]!==h?(D=h("Split editor and results"),e[32]=h,e[33]=D):D=e[33];let z;e[34]===Symbol.for("react.memo_cache_sentinel")?(z=B("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[f("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),f("path",{d:"M12 4v16"})]}),e[34]=z):z=e[34];let P;e[35]!==C||e[36]!==S||e[37]!==H||e[38]!==k||e[39]!==D?(P=f("button",{"aria-label":H,"aria-pressed":S,className:k,"data-testid":"sql-split-toggle",onClick:C,title:D,type:"button",children:z}),e[35]=C,e[36]=S,e[37]=H,e[38]=k,e[39]=D,e[40]=P):P=e[40];let oe;e[41]!==x?(oe=x!==null&&x.columns.length>0&&f(dt,{columns:x.columns,name:"query-result",rows:x.rows}),e[41]=x,e[42]=oe):oe=e[42];let Z;e[43]!==h?(Z=h("Format"),e[43]=h,e[44]=Z):Z=e[44];let ne;e[45]!==c||e[46]!==p||e[47]!==Z?(ne=f("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:p,onClick:c,type:"button",children:Z}),e[45]=c,e[46]=p,e[47]=Z,e[48]=ne):ne=e[48];let q;e[49]!==g||e[50]!==v?(q=f(at,{onChange:g,testId:"sql-shard-input",value:v}),e[49]=g,e[50]=v,e[51]=q):q=e[51];let j;e[52]!==p||e[53]!==h?(j=h(p?"Running…":"Run"),e[52]=p,e[53]=h,e[54]=j):j=e[54];let J;e[55]===Symbol.for("react.memo_cache_sentinel")?(J=f("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=J):J=e[55];let V;e[56]!==i||e[57]!==p||e[58]!==j?(V=B("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:p,onClick:i,type:"button",children:[j,J]}),e[56]=i,e[57]=p,e[58]=j,e[59]=V):V=e[59];let U;e[60]!==P||e[61]!==oe||e[62]!==ne||e[63]!==q||e[64]!==V?(U=B("div",{className:"ms-auto flex items-center gap-2",children:[P,oe,ne,q,V]}),e[60]=P,e[61]=oe,e[62]=ne,e[63]=q,e[64]=V,e[65]=U):U=e[65];let G;e[66]!==F||e[67]!==U||e[68]!==R||e[69]!==A||e[70]!==M?(G=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[R,A,M,F,U]}),e[66]=F,e[67]=U,e[68]=R,e[69]=A,e[70]=M,e[71]=G):G=e[71];let Y;e[72]!==u||e[73]!==N?(Y=N!==void 0&&f("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:N.runs.map((ae,de)=>f("button",{"aria-pressed":de===N.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${de===N.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${ae.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${de.toString()}`,onClick:()=>{u(de)},title:ae.sql,type:"button",children:de+1},`${de.toString()}:${ae.sql}`))}),e[72]=u,e[73]=N,e[74]=Y):Y=e[74];let te;e[75]!==r?(te=r!==null&&f(ct,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:r}),e[75]=r,e[76]=te):te=e[76];let le;e[77]!==r||e[78]!==x||e[79]!==h?(le=r===null&&x===null&&f("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:h("Click Run to execute your query.")}),e[77]=r,e[78]=x,e[79]=h,e[80]=le):le=e[80];let O;e[81]!==t||e[82]!==s||e[83]!==r||e[84]!==m||e[85]!==x||e[86]!==h?(O=r===null&&x!==null&&B("div",{"data-testid":"sql-result",children:[m==="chart"?f(rt,{axes:t,result:x}):f(it,{result:x}),B("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:[x.truncated?h("Showing the first {max} rows.",{max:x.rows.length}):h("{count} rows",{count:x.rowCount}),s!==void 0&&` · ${h("{ms} ms",{ms:Math.round(s)})}`]})]}),e[81]=t,e[82]=s,e[83]=r,e[84]=m,e[85]=x,e[86]=h,e[87]=O):O=e[87];let Q;e[88]!==te||e[89]!==le||e[90]!==O?(Q=B("div",{className:"min-h-0 flex-1 overflow-auto",children:[te,le,O]}),e[88]=te,e[89]=le,e[90]=O,e[91]=Q):Q=e[91];let ee;return e[92]!==o||e[93]!==G||e[94]!==Y||e[95]!==Q?(ee=B("div",{className:o,children:[G,Y,Q]}),e[92]=o,e[93]=G,e[94]=Y,e[95]=Q,e[96]=ee):ee=e[96],ee},Jn=(l,e)=>l.trim()===""?e:(l.split(`
|
|
10
|
-
`)[0]??l).slice(0,24),Vn=l=>{l?.focus(),l?.select()},Xn=l=>{const e=X(14),{initial:n,onCancel:t,onCommit:o,placeholder:s,testId:r}=l,c=re();let a;e[0]!==o?(a=b=>{o(b.currentTarget.value.trim())},e[0]=o,e[1]=a):a=e[1];const i=a;let u;e[2]!==t||e[3]!==o?(u=b=>{b.key==="Enter"?o(b.currentTarget.value.trim()):b.key==="Escape"&&t()},e[2]=t,e[3]=o,e[4]=u):u=e[4];const g=u;let d;e[5]!==c?(d=c("Tab title"),e[5]=c,e[6]=d):d=e[6];let y;return e[7]!==n||e[8]!==i||e[9]!==g||e[10]!==s||e[11]!==d||e[12]!==r?(y=f("input",{"aria-label":d,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":r,defaultValue:n,onBlur:i,onKeyDown:g,placeholder:s,ref:Vn,type:"text"}),e[7]=n,e[8]=i,e[9]=g,e[10]=s,e[11]=d,e[12]=r,e[13]=y):y=e[13],y},Zn=l=>{const e=X(29),{idBase:n,onDiscard:t,onKeep:o}=l,s=re(),r=`sql-tab-close-prompt-${n}`;let c;e[0]!==s?(c=s("Discard?"),e[0]=s,e[1]=c):c=e[1];let a;e[2]!==c?(a=f("span",{className:"text-[11px] text-muted-foreground",children:c}),e[2]=c,e[3]=a):a=e[3];let i;e[4]!==s?(i=s("Discard changes"),e[4]=s,e[5]=i):i=e[5];const u=`sql-tab-close-confirm-${n}`;let g;e[6]!==s?(g=s("Discard changes"),e[6]=s,e[7]=g):g=e[7];let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=f("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:f("path",{d:"M5 13l4 4L19 7"})}),e[8]=d):d=e[8];let y;e[9]!==t||e[10]!==i||e[11]!==u||e[12]!==g?(y=f("button",{"aria-label":i,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":u,onClick:t,title:g,type:"button",children:d}),e[9]=t,e[10]=i,e[11]=u,e[12]=g,e[13]=y):y=e[13];let b;e[14]!==s?(b=s("Keep editing"),e[14]=s,e[15]=b):b=e[15];const C=`sql-tab-close-cancel-${n}`;let m;e[16]!==s?(m=s("Keep editing"),e[16]=s,e[17]=m):m=e[17];let x;e[18]===Symbol.for("react.memo_cache_sentinel")?(x=f("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:f("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=x):x=e[18];let p;e[19]!==o||e[20]!==C||e[21]!==m||e[22]!==b?(p=f("button",{"aria-label":b,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":C,onClick:o,title:m,type:"button",children:x}),e[19]=o,e[20]=C,e[21]=m,e[22]=b,e[23]=p):p=e[23];let N;return e[24]!==r||e[25]!==p||e[26]!==a||e[27]!==y?(N=B("span",{className:"flex shrink-0 items-center gap-1","data-testid":r,role:"group",children:[a,y,p]}),e[24]=r,e[25]=p,e[26]=a,e[27]=y,e[28]=N):N=e[28],N},es=l=>{const e=X(47),{active:n,canClose:t,onClose:o,onMenu:s,onRename:r,onSelect:c,tab:a}=l,i=re(),[u,g]=se(!1),[d,y]=se(!1);let b;e[0]!==s||e[1]!==a.id?(b=P=>{s(a.id,P)},e[0]=s,e[1]=a.id,e[2]=b):b=e[2];const C=b;let m;e[3]!==c||e[4]!==a.id?(m=()=>{c(a.id)},e[3]=c,e[4]=a.id,e[5]=m):m=e[5];const x=m;let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{g(!0)},e[6]=p):p=e[6];const N=p;let v;e[7]!==o||e[8]!==a?(v=P=>{P.stopPropagation(),Ge(a)?y(!0):o(a.id)},e[7]=o,e[8]=a,e[9]=v):v=e[9];const S=v;let h;e[10]!==o||e[11]!==a.id?(h=P=>{P.stopPropagation(),y(!1),o(a.id)},e[10]=o,e[11]=a.id,e[12]=h):h=e[12];const w=h;let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=P=>{P.stopPropagation(),y(!1)},e[13]=T):T=e[13];const I=T;let R;e[14]!==r||e[15]!==a.id?(R=P=>{r(a.id,P),g(!1)},e[14]=r,e[15]=a.id,e[16]=R):R=e[16];const E=R;let _;e[17]===Symbol.for("react.memo_cache_sentinel")?(_=()=>{g(!1)},e[17]=_):_=e[17];const L=_;let A;e[18]!==a.name?(A=a.name.trim(),e[18]=a.name,e[19]=A):A=e[19];const M=A;let W;e[20]!==i||e[21]!==a.sql?(W=Jn(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=W):W=e[22];const K=W,$=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let F;e[23]!==$?(F=ie("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",$),e[23]=$,e[24]=F):F=e[24];const H=`sql-tab-${a.id}`;let k;e[25]!==n||e[26]!==E||e[27]!==M||e[28]!==K||e[29]!==u||e[30]!==x||e[31]!==i||e[32]!==a.id?(k=u?f(Xn,{initial:M,onCancel:L,onCommit:E,placeholder:K,testId:`sql-tab-rename-${a.id}`}):f("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:x,onDoubleClick:N,title:i("Double-click to rename"),type:"button",children:M===""?K:M}),e[25]=n,e[26]=E,e[27]=M,e[28]=K,e[29]=u,e[30]=x,e[31]=i,e[32]=a.id,e[33]=k):k=e[33];let D;e[34]!==t||e[35]!==w||e[36]!==d||e[37]!==S||e[38]!==i||e[39]!==a.id?(D=t&&(d?f(Zn,{idBase:a.id,onDiscard:w,onKeep:I}):f("button",{"aria-label":i("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${a.id}`,onClick:S,title:i("Close tab"),type:"button",children:f("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:f("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=w,e[36]=d,e[37]=S,e[38]=i,e[39]=a.id,e[40]=D):D=e[40];let z;return e[41]!==C||e[42]!==F||e[43]!==H||e[44]!==k||e[45]!==D?(z=B("div",{className:F,"data-testid":H,onContextMenu:C,children:[k,D]}),e[41]=C,e[42]=F,e[43]=H,e[44]=k,e[45]=D,e[46]=z):z=e[46],z},ts=l=>{const e=X(43),{model:n,onSelect:t}=l,o=re(),{activeTab:s,addEditorTab:r,cancelBulk:c,closeEditorTab:a,closeTabMenu:i,confirmBulk:u,menuStyle:g,onBackdropContextMenu:d,onCloseAll:y,onCloseOthers:b,onCloseToRight:C,openTabMenu:m,pendingBulk:x,renameTab:p,tabMenu:N,tabs:v}=n;let S;if(e[0]!==s||e[1]!==a||e[2]!==t||e[3]!==m||e[4]!==p||e[5]!==v){let A;e[7]!==s||e[8]!==a||e[9]!==t||e[10]!==m||e[11]!==p||e[12]!==v.length?(A=M=>f(es,{active:M.id===s.id,canClose:v.length>1,onClose:a,onMenu:m,onRename:p,onSelect:t,tab:M},M.id),e[7]=s,e[8]=a,e[9]=t,e[10]=m,e[11]=p,e[12]=v.length,e[13]=A):A=e[13],S=v.map(A),e[0]=s,e[1]=a,e[2]=t,e[3]=m,e[4]=p,e[5]=v,e[6]=S}else S=e[6];let h;e[14]!==o?(h=o("New tab"),e[14]=o,e[15]=h):h=e[15];const w=v.length>=Le;let T;e[16]!==o?(T=o("New tab"),e[16]=o,e[17]=T):T=e[17];let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=f("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:f("path",{d:"M12 5v14M5 12h14"})}),e[18]=I):I=e[18];let R;e[19]!==r||e[20]!==h||e[21]!==w||e[22]!==T?(R=f("button",{"aria-label":h,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:w,onClick:r,title:T,type:"button",children:I}),e[19]=r,e[20]=h,e[21]=w,e[22]=T,e[23]=R):R=e[23];let E;e[24]!==S||e[25]!==R?(E=B("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[S,R]}),e[24]=S,e[25]=R,e[26]=E):E=e[26];let _;e[27]!==c||e[28]!==i||e[29]!==u||e[30]!==g||e[31]!==d||e[32]!==y||e[33]!==b||e[34]!==C||e[35]!==x||e[36]!==o||e[37]!==N||e[38]!==v?(_=N!==null&&B(he,{children:[f("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:i,onContextMenu:d,role:"presentation"}),f("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:g,children:x===null?B(he,{children:[f("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:v.length<=1,onClick:b,role:"menuitem",type:"button",children:o("Close other tabs")}),f("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:v.findIndex(A=>A.id===N.id)>=v.length-1,onClick:C,role:"menuitem",type:"button",children:o("Close tabs to the right")}),f("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:y,role:"menuitem",type:"button",children:o("Close all tabs")})]}):B("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[f("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),B("div",{className:"flex items-center gap-1.5",children:[f("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:u,type:"button",children:o("Discard")}),f("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:c,type:"button",children:o("Cancel")})]})]})})]}),e[27]=c,e[28]=i,e[29]=u,e[30]=g,e[31]=d,e[32]=y,e[33]=b,e[34]=C,e[35]=x,e[36]=o,e[37]=N,e[38]=v,e[39]=_):_=e[39];let L;return e[40]!==E||e[41]!==_?(L=B(he,{children:[E,_]}),e[40]=E,e[41]=_,e[42]=L):L=e[42],L},ns=Ne(we.runSql),ss="lunora-studio-sql-split-view",os=()=>pe(Ve[0]?.sql??""),ls=()=>performance.now(),rs=()=>{const l=X(2);let e;l[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Map,l[0]=e):e=l[0];const n=ue(e);let t;return l[1]===Symbol.for("react.memo_cache_sentinel")?(t={advance:o=>{n.current.set(o,(n.current.get(o)??0)+1)},begin:o=>{const s=n.current.get(o)??0;return()=>(n.current.get(o)??0)===s}},l[1]=t):t=l[1],t},Es=({initialShardKey:l,now:e=ls})=>{const n=Te(),t=En(os),{activeTab:o,output:s,patchActiveOutput:r,patchActiveTab:c,setActiveTabId:a,unlinkQuery:i}=t,u=rs(),d=_n({loadIntoActiveTab:(U,G)=>{u.advance(o.id),c({activeId:G,sql:U}),r({chart:void 0,durationMs:void 0,error:null,failed:void 0,result:null,running:!1,script:void 0})},unlinkQuery:i}),{recordHistory:y,updateQuerySql:b}=d,C=o.sql,{activeId:m}=o,{chart:x,error:p,failed:N,result:v,running:S}=s,h=s.pane,[w,T]=se(l??""),[I,R]=Re(ss,!1),{probe:E,schema:_}=dn(w),L=U=>{c({sql:U}),m!==null&&b(m,U)},A=Qt(C,_,w),M=st(w),W=()=>{if(v===null)return;ce((async()=>{const G=await M.inferChart({columns:v.columns,rowCount:v.rowCount,types:Object.fromEntries(v.columns.map(Y=>[Y,typeof(v.rows[0]?.[Y]??"")]))});r({chart:G})})())},K=async U=>{const G=e();try{const Y=await n.query(ns,{sql:U},ye(w)),te=e()-G;return y(U),{durationMs:te,error:null,result:Y,sql:U}}catch(Y){return{error:tt(Y),result:null,sql:U}}},$=async U=>{if(C.trim()==="")return;const G=u.begin(o.id);r({running:!0});const Y=U==="explain"?ke(yt(C),0):ze(C),te=[];for(const Q of Y){const ee={error:Q.rejection?.message??"",result:null,sql:Q.sql};te.push(Q.rejection===void 0?await K(Q.sql):ee)}if(nt(w),!G())return;const le=Math.max(te.length-1,0),O=te[le];r({chart:void 0,durationMs:O?.durationMs,error:O?.error??null,failed:O?.error===null||O===void 0?void 0:{error:O.error,sql:O.sql},pane:U,result:O?.result??null,running:!1,script:te.length>1?{runs:te,selected:le}:void 0})},F=U=>{const G=s.script?.runs,Y=G?.[U];G===void 0||Y===void 0||r({chart:void 0,durationMs:Y.durationMs,error:Y.error,failed:Y.error===null?void 0:{error:Y.error,sql:Y.sql},result:Y.result,script:{runs:G,selected:U}})},H=()=>{ce($("results"))},k=pn({inlineEditEnabled:!M.unavailable,onSubmit:()=>{ce($(s.pane))},probe:E,schema:_,setDraft:L}),{closeAutocomplete:D,closeInlineEdit:z}=k,P=()=>{L(kt(C))},oe=U=>{D(),z(),a(U)},Z=()=>{r({pane:"results"})},ne=()=>{ce($("explain"))},q=()=>{r({pane:"chart"})},j=()=>{R(!I)},J=I?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",V=I?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";return B("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[f(Yn,{activeId:m,history:d.history,listRef:d.listRef,onClearHistory:d.clearHistory,onDelete:d.deleteQuery,onLoadHistory:d.loadFromHistory,onLoadTemplate:d.loadTemplate,onNew:d.newQuery,onSearchChange:d.onSearchChange,onSelect:d.selectQuery,onToggleRememberHistory:d.setRememberHistory,queries:d.queries,rememberHistory:d.rememberHistory,search:d.search}),B("div",{className:"flex min-w-0 flex-1 flex-col",children:[f(ts,{model:t,onSelect:oe}),B("div",{className:J,children:[f(zn,{assistant:M,autocomplete:k.autocompleteState,diagnostics:A,draft:C,editorRef:k.editorRef,failed:N,gutterRef:k.gutterRef,handlers:k.handlers,inlineEdit:k.inlineEdit,listboxId:k.listboxId,onAcceptInlineEdit:k.acceptInlineEdit,onCancelInlineEdit:k.closeInlineEdit,onGenerated:L,onPickSuggestion:k.onPickSuggestion,onRevealDiagnostic:k.revealDiagnostic,overlayRef:k.overlayRef}),f(Gn,{assistant:M,chart:x,className:V,durationMs:s.durationMs,error:p,onFormat:P,onInferChart:W,onRun:H,onSelectStatement:F,onShardKeyChange:T,onShowChart:q,onShowExplain:ne,onShowResults:Z,onToggleSplit:j,pane:h,result:v,running:S,script:s.script,shardKey:w,splitView:I})]})]})]})};export{Es as SqlEditorPanel};
|
|
8
|
+
`),Bn=(l,e)=>{const n=[];let t=1,o=1;for(const s of lt(l,e,{ignoreNewlineAtEof:!0}))for(const r of $n(s.value))s.added?(n.push({after:o,kind:"added",text:r}),o+=1):s.removed?(n.push({before:t,kind:"removed",text:r}),t+=1):(n.push({after:o,before:t,kind:"context",text:r}),t+=1,o+=1);return n},Pn={added:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400",context:"text-muted-foreground",removed:"bg-destructive/10 text-destructive"},Hn={added:"+",context:" ",removed:"-"},Fn=l=>{const e=X(11),{lines:n}=l,t=re();let o;e[0]!==t?(o=t("Proposed edit"),e[0]=t,e[1]=o):o=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=ie("max-h-48 overflow-auto rounded-md border border-border bg-background",_e),e[2]=s):s=e[2];let r;if(e[3]!==n||e[4]!==t){let a;e[6]!==t?(a=i=>B("li",{className:ie("flex gap-2",Pn[i.kind]),"data-kind":i.kind,children:[f("span",{"aria-hidden":"true",className:"shrink-0 select-none opacity-60",children:Hn[i.kind]}),i.kind!=="context"&&f("span",{className:"sr-only",children:i.kind==="added"?t("Added"):t("Removed")}),f("span",{className:"min-w-0",children:i.text===""?" ":i.text})]},`${String(i.before)}:${String(i.after)}`),e[6]=t,e[7]=a):a=e[7],r=n.map(a),e[3]=n,e[4]=t,e[5]=r}else r=e[5];let c;return e[8]!==o||e[9]!==r?(c=f("ul",{"aria-label":o,className:s,"data-testid":"sql-inline-diff",children:r}),e[8]=o,e[9]=r,e[10]=c):c=e[10],c},xe="rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",Wn=l=>{const e=X(41),{onAccept:n,onCancel:t,rpc:o,source:s,whole:r}=l,c=re(),a=ue(null),i=ue(null),[u,g]=se(""),[d,y]=se(null);let b,N;if(e[0]!==d?(b=()=>{d===null?a.current?.focus():i.current?.focus()},N=[d],e[0]=d,e[1]=b,e[2]=N):(b=e[1],N=e[2]),me(b,N),o.unavailable)return null;let m;e[3]!==o?(m=o.pending("sql"),e[3]=o,e[4]=m):m=e[4];const x=m;let p;if(e[5]!==u||e[6]!==n||e[7]!==t||e[8]!==x||e[9]!==d||e[10]!==o||e[11]!==s||e[12]!==c||e[13]!==r){const C=o.reason("sql");let v;e[15]!==u||e[16]!==o||e[17]!==s?(v=()=>{const L=u.trim();if(L===""||s.trim()==="")return;ce((async()=>{const M=await o.rewrite(L,s);M!==void 0&&y(M)})())},e[15]=u,e[16]=o,e[17]=s,e[18]=v):v=e[18];const S=v;let h;e[19]!==t?(h=L=>{L.key==="Escape"&&(L.preventDefault(),t())},e[19]=t,e[20]=h):h=e[20];const w=h;let T;e[21]!==c||e[22]!==r?(T=c(r?"Whole query":"Selection"),e[21]=c,e[22]=r,e[23]=T):T=e[23];let I;e[24]!==T?(I=f("span",{className:"shrink-0 rounded bg-muted px-1 font-mono text-[10px] uppercase text-muted-foreground","data-testid":"sql-inline-edit-scope",children:T}),e[24]=T,e[25]=I):I=e[25];let R;e[26]!==u||e[27]!==n||e[28]!==t||e[29]!==w||e[30]!==x||e[31]!==d||e[32]!==S||e[33]!==c?(R=d===null?B(he,{children:[f(Pe,{"aria-label":c("Tell the model what to change"),className:"h-7 flex-1 text-xs","data-testid":"sql-inline-edit-prompt",disabled:x,onChange:L=>{g(L.target.value)},onKeyDown:L=>{if(L.key==="Enter"){L.preventDefault(),S();return}w(L)},placeholder:c("Tell the model what to change"),ref:a,value:u}),f("button",{className:ie(xe,x&&"opacity-60"),"data-testid":"sql-inline-edit-submit",disabled:x||u.trim()==="",onClick:S,onKeyDown:w,type:"button",children:c(x?"Thinking…":"Rewrite")}),f("button",{className:xe,"data-testid":"sql-inline-edit-cancel",onClick:t,onKeyDown:w,type:"button",children:c("Cancel")})]}):B(he,{children:[f("span",{className:"flex-1 text-xs text-muted-foreground",children:c("Proposed edit")}),f("button",{className:xe,"data-testid":"sql-inline-edit-accept",onClick:()=>{n(d)},onKeyDown:w,ref:i,type:"button",children:c("Accept")}),f("button",{className:xe,"data-testid":"sql-inline-edit-reject",onClick:()=>{y(null)},onKeyDown:w,type:"button",children:c("Reject")})]}),e[26]=u,e[27]=n,e[28]=t,e[29]=w,e[30]=x,e[31]=d,e[32]=S,e[33]=c,e[34]=R):R=e[34];let E;e[35]!==I||e[36]!==R?(E=B("div",{className:"flex items-center gap-2",children:[I,R]}),e[35]=I,e[36]=R,e[37]=E):E=e[37];let _;e[38]!==d||e[39]!==s?(_=d!==null&&f(Fn,{lines:Bn(s,d)}),e[38]=d,e[39]=s,e[40]=_):_=e[40],p=B("div",{className:"flex flex-col gap-1 border-b border-border bg-muted/20 px-3 py-2","data-testid":"sql-inline-edit",children:[E,_,C!==void 0&&f("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-inline-edit-reason",role:"status",children:Je(C,c)})]}),e[5]=u,e[6]=n,e[7]=t,e[8]=x,e[9]=d,e[10]=o,e[11]=s,e[12]=c,e[13]=r,e[14]=p}else p=e[14];return p},Kn={minWidth:"2.75rem",paddingInline:"0.5rem"},zn=l=>{const e=X(75),{assistant:n,autocomplete:t,diagnostics:o,draft:s,failed:r,handlers:c,editorRef:a,gutterRef:i,inlineEdit:u,listboxId:g,onAcceptInlineEdit:d,onCancelInlineEdit:y,onGenerated:b,onPickSuggestion:N,onRevealDiagnostic:m,overlayRef:x}=l,p=re();let C,v,S,h,w,T,I,R,E;if(e[0]!==n||e[1]!==s||e[2]!==r||e[3]!==i||e[4]!==u||e[5]!==d||e[6]!==y||e[7]!==b){const P=s.split(`
|
|
9
|
+
`).length;I="flex min-h-0 min-w-0 flex-1 flex-col",e[17]!==n||e[18]!==r||e[19]!==b?(R=f(qn,{assistant:n,failed:r,onGenerated:b}),e[17]=n,e[18]=r,e[19]=b,e[20]=R):R=e[20],e[21]!==n||e[22]!==s.length||e[23]!==u||e[24]!==d||e[25]!==y?(E=u!==null&&f(Wn,{onAccept:d,onCancel:y,rpc:n,source:u.text,whole:u.start===0&&u.end===s.length},`${u.start.toString()}-${u.end.toString()}`),e[21]=n,e[22]=s.length,e[23]=u,e[24]=d,e[25]=y,e[26]=E):E=e[26],T="flex min-h-0 min-w-0 flex-1",C="true",v="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",S=i,h=Kn,w=Array.from({length:P},Un),e[0]=n,e[1]=s,e[2]=r,e[3]=i,e[4]=u,e[5]=d,e[6]=y,e[7]=b,e[8]=C,e[9]=v,e[10]=S,e[11]=h,e[12]=w,e[13]=T,e[14]=I,e[15]=R,e[16]=E}else C=e[8],v=e[9],S=e[10],h=e[11],w=e[12],T=e[13],I=e[14],R=e[15],E=e[16];let _;e[27]!==C||e[28]!==v||e[29]!==S||e[30]!==h||e[31]!==w?(_=f("div",{"aria-hidden":C,className:v,ref:S,style:h,children:w}),e[27]=C,e[28]=v,e[29]=S,e[30]=h,e[31]=w,e[32]=_):_=e[32];let L;e[33]!==o||e[34]!==s||e[35]!==x?(L=f(Dn,{diagnostics:o,draft:s,scrollRef:x}),e[33]=o,e[34]=s,e[35]=x,e[36]=L):L=e[36];let A;e[37]!==t||e[38]!==g?(A=t===null?void 0:`${g}-opt-${t.active.toString()}`,e[37]=t,e[38]=g,e[39]=A):A=e[39];const M=t===null?void 0:g,W=t!==null;let K;e[40]!==p?(K=p("SQL query"),e[40]=p,e[41]=K):K=e[41];let $;e[42]!==s||e[43]!==a||e[44]!==c.onBlur||e[45]!==c.onChange||e[46]!==c.onKeyDown||e[47]!==c.onScroll||e[48]!==c.onSelect||e[49]!==A||e[50]!==M||e[51]!==W||e[52]!==K?($=f("textarea",{"aria-activedescendant":A,"aria-autocomplete":"list","aria-controls":M,"aria-expanded":W,"aria-label":K,className:`relative size-full resize-none bg-transparent outline-none ${_e}`,"data-testid":"sql-input",onBlur:c.onBlur,onChange:c.onChange,onKeyDown:c.onKeyDown,onScroll:c.onScroll,onSelect:c.onSelect,placeholder:"SELECT * FROM …",ref:a,role:"combobox",spellCheck:!1,value:s}),e[42]=s,e[43]=a,e[44]=c.onBlur,e[45]=c.onChange,e[46]=c.onKeyDown,e[47]=c.onScroll,e[48]=c.onSelect,e[49]=A,e[50]=M,e[51]=W,e[52]=K,e[53]=$):$=e[53];let F;e[54]!==t||e[55]!==g||e[56]!==N?(F=f(rn,{listboxId:g,onPick:N,state:t}),e[54]=t,e[55]=g,e[56]=N,e[57]=F):F=e[57];let H;e[58]!==L||e[59]!==$||e[60]!==F?(H=B("div",{className:"relative min-w-0 flex-1 bg-background",children:[L,$,F]}),e[58]=L,e[59]=$,e[60]=F,e[61]=H):H=e[61];let k;e[62]!==_||e[63]!==H||e[64]!==T?(k=B("div",{className:T,children:[_,H]}),e[62]=_,e[63]=H,e[64]=T,e[65]=k):k=e[65];let D;e[66]!==o||e[67]!==m?(D=f(Mn,{diagnostics:o,onSelect:m}),e[66]=o,e[67]=m,e[68]=D):D=e[68];let z;return e[69]!==k||e[70]!==D||e[71]!==I||e[72]!==R||e[73]!==E?(z=B("div",{className:I,children:[R,E,k,D]}),e[69]=k,e[70]=D,e[71]=I,e[72]=R,e[73]=E,e[74]=z):z=e[74],z};function Un(l,e){return f("div",{children:e+1},e)}const Ve=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],jn=l=>{const e=X(29),{active:n,onDelete:t,onSelect:o,query:s}=l,r=re();let c;e[0]!==o||e[1]!==s.id?(c=()=>{o(s.id)},e[0]=o,e[1]=s.id,e[2]=c):c=e[2];const a=c;let i;e[3]!==t||e[4]!==s.id?(i=h=>{h.stopPropagation(),t(s.id)},e[3]=t,e[4]=s.id,e[5]=i):i=e[5];const u=i,g=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let d;e[6]!==g?(d=ie("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[6]=g,e[7]=d):d=e[7];const y=`sql-query-${s.id}`;let b;e[8]===Symbol.for("react.memo_cache_sentinel")?(b=f("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=b):b=e[8];let N;e[9]!==s.name?(N=f("span",{className:"truncate",children:s.name}),e[9]=s.name,e[10]=N):N=e[10];let m;e[11]!==n||e[12]!==a||e[13]!==d||e[14]!==y||e[15]!==N?(m=B("button",{"aria-pressed":n,className:d,"data-testid":y,onClick:a,type:"button",children:[b,N]}),e[11]=n,e[12]=a,e[13]=d,e[14]=y,e[15]=N,e[16]=m):m=e[16];let x;e[17]!==r?(x=r("Delete query"),e[17]=r,e[18]=x):x=e[18];let p;e[19]!==r?(p=r("Delete query"),e[19]=r,e[20]=p):p=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=f("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=C):C=e[21];let v;e[22]!==u||e[23]!==p||e[24]!==x?(v=f("button",{"aria-label":x,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:u,title:p,type:"button",children:C}),e[22]=u,e[23]=p,e[24]=x,e[25]=v):v=e[25];let S;return e[26]!==v||e[27]!==m?(S=B("li",{className:"group/q flex items-center",children:[m,v]}),e[26]=v,e[27]=m,e[28]=S):S=e[28],S},$e="sql-history-remember",Qn=(l,e)=>{const n=e.trim().toLowerCase();return n===""?[...l]:l.filter(t=>t.name.toLowerCase().includes(n))},Yn=l=>{const e=X(66),{activeId:n,history:t,listRef:o,onClearHistory:s,onDelete:r,onLoadHistory:c,onLoadTemplate:a,onNew:i,onSearchChange:u,onSelect:g,onToggleRememberHistory:d,queries:y,rememberHistory:b,search:N}=l,m=re();let x,p,C,v,S;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i||e[4]!==u||e[5]!==g||e[6]!==d||e[7]!==y||e[8]!==N||e[9]!==m){const A=Qn(y,N);let M;e[15]!==d?(M=P=>{d(P.target.checked)},e[15]=d,e[16]=M):M=e[16],x=M,C="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let W;e[17]!==m?(W=m("Search queries…"),e[17]=m,e[18]=W):W=e[18];let K;e[19]!==u||e[20]!==N||e[21]!==W?(K=f("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:u,placeholder:W,type:"text",value:N}),e[19]=u,e[20]=N,e[21]=W,e[22]=K):K=e[22];let $;e[23]!==m?($=m("New query"),e[23]=m,e[24]=$):$=e[24];let F;e[25]!==m?(F=m("New query"),e[25]=m,e[26]=F):F=e[26];let H;e[27]===Symbol.for("react.memo_cache_sentinel")?(H=f("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:f("path",{d:"M12 5v14M5 12h14"})}),e[27]=H):H=e[27];let k;e[28]!==i||e[29]!==$||e[30]!==F?(k=f("button",{"aria-label":$,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:i,title:F,type:"button",children:H}),e[28]=i,e[29]=$,e[30]=F,e[31]=k):k=e[31],e[32]!==k||e[33]!==K?(v=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[K,k]}),e[32]=k,e[33]=K,e[34]=v):v=e[34],p="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let D;e[35]!==m?(D=m("Private"),e[35]=m,e[36]=D):D=e[36];let z;e[37]!==D?(z=f("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[37]=D,e[38]=z):z=e[38],S=B("div",{children:[z,A.length===0?f("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:m("No saved queries yet — they save to this browser as you type.")}):f("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:A.map(P=>f(jn,{active:n===P.id,onDelete:r,onSelect:g,query:P},P.id))})]}),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=u,e[5]=g,e[6]=d,e[7]=y,e[8]=N,e[9]=m,e[10]=x,e[11]=p,e[12]=C,e[13]=v,e[14]=S}else x=e[10],p=e[11],C=e[12],v=e[13],S=e[14];let h;e[39]!==m?(h=m("Reference"),e[39]=m,e[40]=h):h=e[40];let w;e[41]!==h?(w=f("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:h}),e[41]=h,e[42]=w):w=e[42];let T;e[43]!==a?(T=Ve.map(A=>f("li",{children:B("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":A.sql,onClick:a,type:"button",children:[f("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),A.label]})},A.label)),e[43]=a,e[44]=T):T=e[44];let I;e[45]!==T?(I=f("ul",{className:"flex flex-col gap-px",children:T}),e[45]=T,e[46]=I):I=e[46];let R;e[47]!==w||e[48]!==I?(R=B("div",{children:[w,I]}),e[47]=w,e[48]=I,e[49]=R):R=e[49];let E;e[50]!==t||e[51]!==s||e[52]!==c||e[53]!==x||e[54]!==b||e[55]!==m?(E=t.length>0&&B("div",{children:[B("div",{className:"flex items-center justify-between px-1 pb-1",children:[f("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m("History")}),f("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:s,type:"button",children:m("Clear history")})]}),B("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:$e,children:[f("input",{checked:b,"data-testid":"sql-history-remember",id:$e,onChange:x,type:"checkbox"}),m("Keep history on this browser")]}),f("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(A=>f("li",{children:B("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":A.sql,"data-testid":"sql-history-item",onClick:c,title:A.sql,type:"button",children:[f("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:f("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),f("span",{className:"truncate font-mono",children:A.sql})]})},`${A.at.toString()}:${A.sql}`))})]}),e[50]=t,e[51]=s,e[52]=c,e[53]=x,e[54]=b,e[55]=m,e[56]=E):E=e[56];let _;e[57]!==p||e[58]!==E||e[59]!==S||e[60]!==R?(_=B("div",{className:p,children:[S,R,E]}),e[57]=p,e[58]=E,e[59]=S,e[60]=R,e[61]=_):_=e[61];let L;return e[62]!==_||e[63]!==C||e[64]!==v?(L=B("aside",{className:C,children:[v,_]}),e[62]=_,e[63]=C,e[64]=v,e[65]=L):L=e[65],L},ve=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,Gn=l=>{const e=X(97),{assistant:n,chart:t,className:o,durationMs:s,error:r,onFormat:c,onInferChart:a,onRun:i,onSelectStatement:u,onShardKeyChange:g,onShowChart:d,onShowExplain:y,onShowResults:b,onToggleSplit:N,pane:m,result:x,running:p,script:C,shardKey:v,splitView:S}=l,h=re(),w=m==="results";let T;e[0]!==w?(T=ve(w),e[0]=w,e[1]=T):T=e[1];let I;e[2]!==h?(I=h("Results"),e[2]=h,e[3]=I):I=e[3];let R;e[4]!==b||e[5]!==T||e[6]!==I?(R=f("button",{className:T,"data-testid":"sql-tab-results",onClick:b,type:"button",children:I}),e[4]=b,e[5]=T,e[6]=I,e[7]=R):R=e[7];const E=m==="chart";let _;e[8]!==E?(_=ve(E),e[8]=E,e[9]=_):_=e[9];let L;e[10]!==h?(L=h("Chart"),e[10]=h,e[11]=L):L=e[11];let A;e[12]!==d||e[13]!==_||e[14]!==L?(A=f("button",{className:_,"data-testid":"sql-tab-chart",onClick:d,type:"button",children:L}),e[12]=d,e[13]=_,e[14]=L,e[15]=A):A=e[15];let M;e[16]!==n||e[17]!==a||e[18]!==m||e[19]!==x||e[20]!==h?(M=!n.unavailable&&m==="chart"&&x!==null&&f("button",{className:ve(!1),"data-testid":"sql-infer-chart",disabled:n.pending("chart"),onClick:a,type:"button",children:n.pending("chart")?h("Thinking…"):h("Suggest chart")}),e[16]=n,e[17]=a,e[18]=m,e[19]=x,e[20]=h,e[21]=M):M=e[21];const W=m==="explain";let K;e[22]!==W?(K=ve(W),e[22]=W,e[23]=K):K=e[23];let $;e[24]!==h?($=h("Explain"),e[24]=h,e[25]=$):$=e[25];let F;e[26]!==y||e[27]!==K||e[28]!==$?(F=f("button",{className:K,"data-testid":"sql-tab-explain",onClick:y,type:"button",children:$}),e[26]=y,e[27]=K,e[28]=$,e[29]=F):F=e[29];let H;e[30]!==h?(H=h("Split editor and results"),e[30]=h,e[31]=H):H=e[31];const k=`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${S?"bg-accent text-foreground":"text-muted-foreground"}`;let D;e[32]!==h?(D=h("Split editor and results"),e[32]=h,e[33]=D):D=e[33];let z;e[34]===Symbol.for("react.memo_cache_sentinel")?(z=B("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[f("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),f("path",{d:"M12 4v16"})]}),e[34]=z):z=e[34];let P;e[35]!==N||e[36]!==S||e[37]!==H||e[38]!==k||e[39]!==D?(P=f("button",{"aria-label":H,"aria-pressed":S,className:k,"data-testid":"sql-split-toggle",onClick:N,title:D,type:"button",children:z}),e[35]=N,e[36]=S,e[37]=H,e[38]=k,e[39]=D,e[40]=P):P=e[40];let oe;e[41]!==x?(oe=x!==null&&x.columns.length>0&&f(dt,{columns:x.columns,name:"query-result",rows:x.rows}),e[41]=x,e[42]=oe):oe=e[42];let Z;e[43]!==h?(Z=h("Format"),e[43]=h,e[44]=Z):Z=e[44];let ne;e[45]!==c||e[46]!==p||e[47]!==Z?(ne=f("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:p,onClick:c,type:"button",children:Z}),e[45]=c,e[46]=p,e[47]=Z,e[48]=ne):ne=e[48];let q;e[49]!==g||e[50]!==v?(q=f(at,{onChange:g,testId:"sql-shard-input",value:v}),e[49]=g,e[50]=v,e[51]=q):q=e[51];let j;e[52]!==p||e[53]!==h?(j=h(p?"Running…":"Run"),e[52]=p,e[53]=h,e[54]=j):j=e[54];let J;e[55]===Symbol.for("react.memo_cache_sentinel")?(J=f("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=J):J=e[55];let V;e[56]!==i||e[57]!==p||e[58]!==j?(V=B("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:p,onClick:i,type:"button",children:[j,J]}),e[56]=i,e[57]=p,e[58]=j,e[59]=V):V=e[59];let U;e[60]!==P||e[61]!==oe||e[62]!==ne||e[63]!==q||e[64]!==V?(U=B("div",{className:"ms-auto flex items-center gap-2",children:[P,oe,ne,q,V]}),e[60]=P,e[61]=oe,e[62]=ne,e[63]=q,e[64]=V,e[65]=U):U=e[65];let G;e[66]!==F||e[67]!==U||e[68]!==R||e[69]!==A||e[70]!==M?(G=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[R,A,M,F,U]}),e[66]=F,e[67]=U,e[68]=R,e[69]=A,e[70]=M,e[71]=G):G=e[71];let Y;e[72]!==u||e[73]!==C?(Y=C!==void 0&&f("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:C.runs.map((ae,de)=>f("button",{"aria-pressed":de===C.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${de===C.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${ae.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${de.toString()}`,onClick:()=>{u(de)},title:ae.sql,type:"button",children:de+1},`${de.toString()}:${ae.sql}`))}),e[72]=u,e[73]=C,e[74]=Y):Y=e[74];let te;e[75]!==r?(te=r!==null&&f(ct,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:r}),e[75]=r,e[76]=te):te=e[76];let le;e[77]!==r||e[78]!==x||e[79]!==h?(le=r===null&&x===null&&f("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:h("Click Run to execute your query.")}),e[77]=r,e[78]=x,e[79]=h,e[80]=le):le=e[80];let O;e[81]!==t||e[82]!==s||e[83]!==r||e[84]!==m||e[85]!==x||e[86]!==h?(O=r===null&&x!==null&&B("div",{"data-testid":"sql-result",children:[m==="chart"?f(rt,{axes:t,result:x}):f(it,{result:x}),B("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:[x.truncated?h("Showing the first {max} rows.",{max:x.rows.length}):h("{count} rows",{count:x.rowCount}),s!==void 0&&` · ${h("{ms} ms",{ms:Math.round(s)})}`]})]}),e[81]=t,e[82]=s,e[83]=r,e[84]=m,e[85]=x,e[86]=h,e[87]=O):O=e[87];let Q;e[88]!==te||e[89]!==le||e[90]!==O?(Q=B("div",{className:"min-h-0 flex-1 overflow-auto",children:[te,le,O]}),e[88]=te,e[89]=le,e[90]=O,e[91]=Q):Q=e[91];let ee;return e[92]!==o||e[93]!==G||e[94]!==Y||e[95]!==Q?(ee=B("div",{className:o,children:[G,Y,Q]}),e[92]=o,e[93]=G,e[94]=Y,e[95]=Q,e[96]=ee):ee=e[96],ee},Jn=(l,e)=>l.trim()===""?e:(l.split(`
|
|
10
|
+
`)[0]??l).slice(0,24),Vn=l=>{l?.focus(),l?.select()},Xn=l=>{const e=X(14),{initial:n,onCancel:t,onCommit:o,placeholder:s,testId:r}=l,c=re();let a;e[0]!==o?(a=b=>{o(b.currentTarget.value.trim())},e[0]=o,e[1]=a):a=e[1];const i=a;let u;e[2]!==t||e[3]!==o?(u=b=>{b.key==="Enter"?o(b.currentTarget.value.trim()):b.key==="Escape"&&t()},e[2]=t,e[3]=o,e[4]=u):u=e[4];const g=u;let d;e[5]!==c?(d=c("Tab title"),e[5]=c,e[6]=d):d=e[6];let y;return e[7]!==n||e[8]!==i||e[9]!==g||e[10]!==s||e[11]!==d||e[12]!==r?(y=f("input",{"aria-label":d,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":r,defaultValue:n,onBlur:i,onKeyDown:g,placeholder:s,ref:Vn,type:"text"}),e[7]=n,e[8]=i,e[9]=g,e[10]=s,e[11]=d,e[12]=r,e[13]=y):y=e[13],y},Zn=l=>{const e=X(29),{idBase:n,onDiscard:t,onKeep:o}=l,s=re(),r=`sql-tab-close-prompt-${n}`;let c;e[0]!==s?(c=s("Discard?"),e[0]=s,e[1]=c):c=e[1];let a;e[2]!==c?(a=f("span",{className:"text-[11px] text-muted-foreground",children:c}),e[2]=c,e[3]=a):a=e[3];let i;e[4]!==s?(i=s("Discard changes"),e[4]=s,e[5]=i):i=e[5];const u=`sql-tab-close-confirm-${n}`;let g;e[6]!==s?(g=s("Discard changes"),e[6]=s,e[7]=g):g=e[7];let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=f("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:f("path",{d:"M5 13l4 4L19 7"})}),e[8]=d):d=e[8];let y;e[9]!==t||e[10]!==i||e[11]!==u||e[12]!==g?(y=f("button",{"aria-label":i,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":u,onClick:t,title:g,type:"button",children:d}),e[9]=t,e[10]=i,e[11]=u,e[12]=g,e[13]=y):y=e[13];let b;e[14]!==s?(b=s("Keep editing"),e[14]=s,e[15]=b):b=e[15];const N=`sql-tab-close-cancel-${n}`;let m;e[16]!==s?(m=s("Keep editing"),e[16]=s,e[17]=m):m=e[17];let x;e[18]===Symbol.for("react.memo_cache_sentinel")?(x=f("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:f("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=x):x=e[18];let p;e[19]!==o||e[20]!==N||e[21]!==m||e[22]!==b?(p=f("button",{"aria-label":b,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":N,onClick:o,title:m,type:"button",children:x}),e[19]=o,e[20]=N,e[21]=m,e[22]=b,e[23]=p):p=e[23];let C;return e[24]!==r||e[25]!==p||e[26]!==a||e[27]!==y?(C=B("span",{className:"flex shrink-0 items-center gap-1","data-testid":r,role:"group",children:[a,y,p]}),e[24]=r,e[25]=p,e[26]=a,e[27]=y,e[28]=C):C=e[28],C},es=l=>{const e=X(47),{active:n,canClose:t,onClose:o,onMenu:s,onRename:r,onSelect:c,tab:a}=l,i=re(),[u,g]=se(!1),[d,y]=se(!1);let b;e[0]!==s||e[1]!==a.id?(b=P=>{s(a.id,P)},e[0]=s,e[1]=a.id,e[2]=b):b=e[2];const N=b;let m;e[3]!==c||e[4]!==a.id?(m=()=>{c(a.id)},e[3]=c,e[4]=a.id,e[5]=m):m=e[5];const x=m;let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{g(!0)},e[6]=p):p=e[6];const C=p;let v;e[7]!==o||e[8]!==a?(v=P=>{P.stopPropagation(),Ge(a)?y(!0):o(a.id)},e[7]=o,e[8]=a,e[9]=v):v=e[9];const S=v;let h;e[10]!==o||e[11]!==a.id?(h=P=>{P.stopPropagation(),y(!1),o(a.id)},e[10]=o,e[11]=a.id,e[12]=h):h=e[12];const w=h;let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=P=>{P.stopPropagation(),y(!1)},e[13]=T):T=e[13];const I=T;let R;e[14]!==r||e[15]!==a.id?(R=P=>{r(a.id,P),g(!1)},e[14]=r,e[15]=a.id,e[16]=R):R=e[16];const E=R;let _;e[17]===Symbol.for("react.memo_cache_sentinel")?(_=()=>{g(!1)},e[17]=_):_=e[17];const L=_;let A;e[18]!==a.name?(A=a.name.trim(),e[18]=a.name,e[19]=A):A=e[19];const M=A;let W;e[20]!==i||e[21]!==a.sql?(W=Jn(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=W):W=e[22];const K=W,$=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let F;e[23]!==$?(F=ie("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",$),e[23]=$,e[24]=F):F=e[24];const H=`sql-tab-${a.id}`;let k;e[25]!==n||e[26]!==E||e[27]!==M||e[28]!==K||e[29]!==u||e[30]!==x||e[31]!==i||e[32]!==a.id?(k=u?f(Xn,{initial:M,onCancel:L,onCommit:E,placeholder:K,testId:`sql-tab-rename-${a.id}`}):f("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:x,onDoubleClick:C,title:i("Double-click to rename"),type:"button",children:M===""?K:M}),e[25]=n,e[26]=E,e[27]=M,e[28]=K,e[29]=u,e[30]=x,e[31]=i,e[32]=a.id,e[33]=k):k=e[33];let D;e[34]!==t||e[35]!==w||e[36]!==d||e[37]!==S||e[38]!==i||e[39]!==a.id?(D=t&&(d?f(Zn,{idBase:a.id,onDiscard:w,onKeep:I}):f("button",{"aria-label":i("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${a.id}`,onClick:S,title:i("Close tab"),type:"button",children:f("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:f("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=w,e[36]=d,e[37]=S,e[38]=i,e[39]=a.id,e[40]=D):D=e[40];let z;return e[41]!==N||e[42]!==F||e[43]!==H||e[44]!==k||e[45]!==D?(z=B("div",{className:F,"data-testid":H,onContextMenu:N,children:[k,D]}),e[41]=N,e[42]=F,e[43]=H,e[44]=k,e[45]=D,e[46]=z):z=e[46],z},ts=l=>{const e=X(43),{model:n,onSelect:t}=l,o=re(),{activeTab:s,addEditorTab:r,cancelBulk:c,closeEditorTab:a,closeTabMenu:i,confirmBulk:u,menuStyle:g,onBackdropContextMenu:d,onCloseAll:y,onCloseOthers:b,onCloseToRight:N,openTabMenu:m,pendingBulk:x,renameTab:p,tabMenu:C,tabs:v}=n;let S;if(e[0]!==s||e[1]!==a||e[2]!==t||e[3]!==m||e[4]!==p||e[5]!==v){let A;e[7]!==s||e[8]!==a||e[9]!==t||e[10]!==m||e[11]!==p||e[12]!==v.length?(A=M=>f(es,{active:M.id===s.id,canClose:v.length>1,onClose:a,onMenu:m,onRename:p,onSelect:t,tab:M},M.id),e[7]=s,e[8]=a,e[9]=t,e[10]=m,e[11]=p,e[12]=v.length,e[13]=A):A=e[13],S=v.map(A),e[0]=s,e[1]=a,e[2]=t,e[3]=m,e[4]=p,e[5]=v,e[6]=S}else S=e[6];let h;e[14]!==o?(h=o("New tab"),e[14]=o,e[15]=h):h=e[15];const w=v.length>=Le;let T;e[16]!==o?(T=o("New tab"),e[16]=o,e[17]=T):T=e[17];let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=f("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:f("path",{d:"M12 5v14M5 12h14"})}),e[18]=I):I=e[18];let R;e[19]!==r||e[20]!==h||e[21]!==w||e[22]!==T?(R=f("button",{"aria-label":h,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:w,onClick:r,title:T,type:"button",children:I}),e[19]=r,e[20]=h,e[21]=w,e[22]=T,e[23]=R):R=e[23];let E;e[24]!==S||e[25]!==R?(E=B("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[S,R]}),e[24]=S,e[25]=R,e[26]=E):E=e[26];let _;e[27]!==c||e[28]!==i||e[29]!==u||e[30]!==g||e[31]!==d||e[32]!==y||e[33]!==b||e[34]!==N||e[35]!==x||e[36]!==o||e[37]!==C||e[38]!==v?(_=C!==null&&B(he,{children:[f("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:i,onContextMenu:d,role:"presentation"}),f("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:g,children:x===null?B(he,{children:[f("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:v.length<=1,onClick:b,role:"menuitem",type:"button",children:o("Close other tabs")}),f("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:v.findIndex(A=>A.id===C.id)>=v.length-1,onClick:N,role:"menuitem",type:"button",children:o("Close tabs to the right")}),f("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:y,role:"menuitem",type:"button",children:o("Close all tabs")})]}):B("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[f("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),B("div",{className:"flex items-center gap-1.5",children:[f("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:u,type:"button",children:o("Discard")}),f("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:c,type:"button",children:o("Cancel")})]})]})})]}),e[27]=c,e[28]=i,e[29]=u,e[30]=g,e[31]=d,e[32]=y,e[33]=b,e[34]=N,e[35]=x,e[36]=o,e[37]=C,e[38]=v,e[39]=_):_=e[39];let L;return e[40]!==E||e[41]!==_?(L=B(he,{children:[E,_]}),e[40]=E,e[41]=_,e[42]=L):L=e[42],L},ns=Ce(we.runSql),ss="lunora-studio-sql-split-view",os=()=>pe(Ve[0]?.sql??""),ls=()=>performance.now(),rs=()=>{const l=X(2);let e;l[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Map,l[0]=e):e=l[0];const n=ue(e);let t;return l[1]===Symbol.for("react.memo_cache_sentinel")?(t={advance:o=>{n.current.set(o,(n.current.get(o)??0)+1)},begin:o=>{const s=n.current.get(o)??0;return()=>(n.current.get(o)??0)===s}},l[1]=t):t=l[1],t},Es=({initialShardKey:l,now:e=ls})=>{const n=Te(),t=En(os),{activeTab:o,output:s,patchActiveOutput:r,patchActiveTab:c,setActiveTabId:a,unlinkQuery:i}=t,u=rs(),d=_n({loadIntoActiveTab:(U,G)=>{u.advance(o.id),c({activeId:G,sql:U}),r({chart:void 0,durationMs:void 0,error:null,failed:void 0,result:null,running:!1,script:void 0})},unlinkQuery:i}),{recordHistory:y,updateQuerySql:b}=d,N=o.sql,{activeId:m}=o,{chart:x,error:p,failed:C,result:v,running:S}=s,h=s.pane,[w,T]=se(l??""),[I,R]=Re(ss,!1),{probe:E,schema:_}=dn(w),L=U=>{c({sql:U}),m!==null&&b(m,U)},A=Qt(N,_,w),M=st(w),W=()=>{if(v===null)return;ce((async()=>{const G=await M.inferChart({columns:v.columns,rowCount:v.rowCount,types:Object.fromEntries(v.columns.map(Y=>[Y,typeof(v.rows[0]?.[Y]??"")]))});r({chart:G})})())},K=async U=>{const G=e();try{const Y=await n.query(ns,{sql:U},ye(w)),te=e()-G;return y(U),{durationMs:te,error:null,result:Y,sql:U}}catch(Y){return{error:tt(Y),result:null,sql:U}}},$=async U=>{if(N.trim()==="")return;const G=u.begin(o.id);r({running:!0});const Y=U==="explain"?ke(yt(N),0):ze(N),te=[];for(const Q of Y){const ee={error:Q.rejection?.message??"",result:null,sql:Q.sql};te.push(Q.rejection===void 0?await K(Q.sql):ee)}if(nt(w),!G())return;const le=Math.max(te.length-1,0),O=te[le];r({chart:void 0,durationMs:O?.durationMs,error:O?.error??null,failed:O?.error===null||O===void 0?void 0:{error:O.error,sql:O.sql},pane:U,result:O?.result??null,running:!1,script:te.length>1?{runs:te,selected:le}:void 0})},F=U=>{const G=s.script?.runs,Y=G?.[U];G===void 0||Y===void 0||r({chart:void 0,durationMs:Y.durationMs,error:Y.error,failed:Y.error===null?void 0:{error:Y.error,sql:Y.sql},result:Y.result,script:{runs:G,selected:U}})},H=()=>{ce($("results"))},k=pn({inlineEditEnabled:!M.unavailable,onSubmit:()=>{ce($(s.pane))},probe:E,schema:_,setDraft:L}),{closeAutocomplete:D,closeInlineEdit:z}=k,P=()=>{L(kt(N))},oe=U=>{D(),z(),a(U)},Z=()=>{r({pane:"results"})},ne=()=>{ce($("explain"))},q=()=>{r({pane:"chart"})},j=()=>{R(!I)},J=I?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",V=I?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";return B("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[f(Yn,{activeId:m,history:d.history,listRef:d.listRef,onClearHistory:d.clearHistory,onDelete:d.deleteQuery,onLoadHistory:d.loadFromHistory,onLoadTemplate:d.loadTemplate,onNew:d.newQuery,onSearchChange:d.onSearchChange,onSelect:d.selectQuery,onToggleRememberHistory:d.setRememberHistory,queries:d.queries,rememberHistory:d.rememberHistory,search:d.search}),B("div",{className:"flex min-w-0 flex-1 flex-col",children:[f(ts,{model:t,onSelect:oe}),B("div",{className:J,children:[f(zn,{assistant:M,autocomplete:k.autocompleteState,diagnostics:A,draft:N,editorRef:k.editorRef,failed:C,gutterRef:k.gutterRef,handlers:k.handlers,inlineEdit:k.inlineEdit,listboxId:k.listboxId,onAcceptInlineEdit:k.acceptInlineEdit,onCancelInlineEdit:k.closeInlineEdit,onGenerated:L,onPickSuggestion:k.onPickSuggestion,onRevealDiagnostic:k.revealDiagnostic,overlayRef:k.overlayRef}),f(Gn,{assistant:M,chart:x,className:V,durationMs:s.durationMs,error:p,onFormat:P,onInferChart:W,onRun:H,onSelectStatement:F,onShardKeyChange:T,onShowChart:q,onShowExplain:ne,onShowResults:Z,onToggleSplit:j,pane:h,result:v,running:S,script:s.script,shardKey:w,splitView:I})]})]})]})};export{Es as SqlEditorPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as k}from"react/compiler-runtime";import{
|
|
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-BXEjuLPN.mjs";import{l as O,s as I}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as X}from"../packem_shared/DataBrowser-Cc1qZX-4.mjs";import{GlobalDataBrowser as Y}from"../packem_shared/GlobalDataBrowser-Hq6gTlkb.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 ae}from"react";import{E as q}from"../packem_shared/error-alert-
|
|
1
|
+
import{c as te}from"react/compiler-runtime";import{useState as ae}from"react";import{E as q}from"../packem_shared/error-alert-54TiaMvZ.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-BW9IuacC.mjs";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as v}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as se}from"../packem_shared/internal-BXEjuLPN.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 a=r[t];return typeof a=="string"?a:void 0},E=(r,t)=>{const a=r[t];return typeof a=="number"?a:void 0},H=r=>{const{usage:t}=r;if(t===null||typeof t!="object")return;const{totalTokens:a}=t;return typeof a=="number"?a:void 0},de=r=>{const{toolCalls:t}=r;return Array.isArray(t)?t.map(a=>a!==null&&typeof a=="object"?a.name:void 0).filter(a=>typeof a=="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:a}=r,u=G();let i;return t[0]!==a||t[1]!==u?(i=a<=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]=a,t[1]=u,t[2]=i):i=t[2],i},Ee=({initialShardKey:r=""})=>{const t=G(),[a,u]=ae(void 0),{data:i}=x(v.listTables,ne,{live:!0,shardKey:r}),z=i!==void 0,h=Array.isArray(i)&&i.some(s=>s.name===Q),O=Array.isArray(i)&&i.some(s=>s.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:a??""}],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&&a!==void 0,live:!0,shardKey:r}),b=Array.isArray(S?.rows)?S.rows:[],Z=Array.isArray(w?.rows)?w.rows:[],C=s=>Z.filter(n=>c(n,"threadKey")===s).length,B=Array.isArray(k?.rows)?k.rows:[],I=B.slice(0,y).toReversed(),R=b.find(s=>c(s,"key")===a);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(s=>{const n=c(s,"key")??"",m=c(s,"status"),p=H(s);return l(f,{"data-active":n===a?"":void 0,"data-testid":`agents-thread-${n}`,children:[e(d,{className:"font-mono text-xs",children:c(s,"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(s,"messageCount")??"—"}),e(d,{className:"tabular-nums text-muted-foreground",children:p??"—"}),e(d,{className:"text-muted-foreground tabular-nums",children:se(E(s,"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,testId:"agents-messages-error"}),a!==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")," · ",a,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((s,n)=>{const m=c(s,"role")??"—",p=de(s),ee=c(s,"toolName"),N=c(s,"status"),T=E(s,"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(s,"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(s,"messageKey")??`${m}:${String(T)}`)})})]})]})})]}),l("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[V!==null&&e(q,{error:F,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-CNQjdAhi.mjs";import{ShardInput as ue}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{S as K}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-CLStXJ7v.mjs";import{u as fe}from"../packem_shared/use-open-trace-B_0LbTD7.mjs";import{u as he}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as w}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as z}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as Te}from"../packem_shared/internal-BXEjuLPN.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 U;e[44]!==n||e[45]!==t?(U=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]=U):U=e[46],x=s.slice(0,we).map(U),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},Ue=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(K,{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(K,{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(K,{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(K,{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(28),{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(Ke),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?(f=T===null?null:r(de,{error:T,testId:"ai-error"}),e[13]=T,e[14]=f):f=e[14];let h;e[15]!==i||e[16]!==n||e[17]!==b||e[18]!==d.byFunction||e[19]!==d.byModel||e[20]!==d.calls||e[21]!==d.source||e[22]!==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(Ue,{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[15]=i,e[16]=n,e[17]=b,e[18]=d.byFunction,e[19]=d.byModel,e[20]=d.calls,e[21]=d.source,e[22]=d.totals,e[23]=h):h=e[23];let g;return e[24]!==p||e[25]!==f||e[26]!==h?(g=I("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[p,f,h]}),e[24]=p,e[25]=f,e[26]=h,e[27]=g):g=e[27],g};function Ke(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-54TiaMvZ.mjs";import{ShardInput as ue}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{S as K}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-BW9IuacC.mjs";import{u as fe}from"../packem_shared/use-open-trace-B_0LbTD7.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-B8yyk5BX.mjs";import{h as Te}from"../packem_shared/internal-BXEjuLPN.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 U;e[44]!==n||e[45]!==t?(U=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]=U):U=e[46],x=s.slice(0,we).map(U),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},Ue=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(K,{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(K,{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(K,{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(K,{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(28),{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(Ke),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?(f=T===null?null:r(de,{error:T,testId:"ai-error"}),e[13]=T,e[14]=f):f=e[14];let h;e[15]!==i||e[16]!==n||e[17]!==b||e[18]!==d.byFunction||e[19]!==d.byModel||e[20]!==d.calls||e[21]!==d.source||e[22]!==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(Ue,{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[15]=i,e[16]=n,e[17]=b,e[18]=d.byFunction,e[19]=d.byModel,e[20]=d.calls,e[21]=d.source,e[22]=d.totals,e[23]=h):h=e[23];let g;return e[24]!==p||e[25]!==f||e[26]!==h?(g=I("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[p,f,h]}),e[24]=p,e[25]=f,e[26]=h,e[27]=g):g=e[27],g};function Ke(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-
|
|
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-BXEjuLPN.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};
|