@trilogy-data/trilogy-studio-components 0.1.25 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/dist/AssetAutoImporter-OHphsfW9.js +403 -0
  2. package/dist/ChatCreatorModal-CuXha6Dg.js +218 -0
  3. package/dist/ChatModelSelect-Cz7axWjP.js +40 -0
  4. package/dist/{CodeBlock-PT4no49I.js → CodeBlock-BBsaC6hX.js} +4 -4
  5. package/dist/{CommunityModels-D7zWnHgG.js → CommunityModels-CIQQhO-y.js} +106 -75
  6. package/dist/{ConnectionErrorPopup-FSs7U-Yl.js → ConnectionErrorPopup-7vpqgF0s.js} +1 -1
  7. package/dist/{ConnectionView-COnTTuA4.js → ConnectionView-7Jj_Ggdi.js} +49 -49
  8. package/dist/{CreateEditorFromDatasourcePopup-snOh1d5h.js → CreateEditorFromDatasourcePopup-CrVHUWFl.js} +4 -4
  9. package/dist/{Dashboard-D1ZCTw5r.js → Dashboard-DxSi9W6Q.js} +276 -280
  10. package/dist/{DashboardImportSelector-CNxibXlS.js → DashboardImportSelector-kuDRDYi8.js} +2 -2
  11. package/dist/{DashboardMobile-D_m0xv17.js → DashboardMobile-CZEgTb0R.js} +39 -39
  12. package/dist/{DrilldownPane-CBs5ZojS.js → DrilldownPane-BheRHJMs.js} +5 -7
  13. package/dist/{Editor-DhsP18KE.js → Editor-D6tdutTm.js} +106 -104
  14. package/dist/{ErrorMessage-XMn_08gJ.js → ErrorMessage-D5JeF3Iz.js} +4 -4
  15. package/dist/{GlobalChatPanel-DFx9A4yP.js → GlobalChatPanel-BXZh0sdD.js} +169 -134
  16. package/dist/{IDE-BRMLxTfP.js → IDE-T8PmyAQ_.js} +200 -203
  17. package/dist/{JobsView-C9PYS6pZ.js → JobsView-Ca97MiSd.js} +12 -13
  18. package/dist/{LLMChat-Cqg6pTgC.js → LLMChat-Cch33Yd_.js} +3 -3
  19. package/dist/{LLMView-VkJpP-49.js → LLMView-BDb6wD74.js} +26 -26
  20. package/dist/{LoadingView-s1uznGwG.js → LoadingView-B-xFwd2N.js} +2 -2
  21. package/dist/{MarkdownRenderer-BNDuEyG-.js → MarkdownRenderer-BWvdx0k3.js} +531 -430
  22. package/dist/MobileIDE-DpdEQEqc.js +783 -0
  23. package/dist/{ModelCard-D8tKkK9-.js → ModelCard-DkAMP4X9.js} +19 -20
  24. package/dist/{ModelView-rAurf9n8.js → ModelView-DomyhN8g.js} +7 -7
  25. package/dist/PageLoading-BAvKGo9h.js +5937 -0
  26. package/dist/{ResultComponent-_-1qZCfv.js → ResultComponent-zoOSoRLe.js} +8 -8
  27. package/dist/{Results-CQGpFmPQ.js → Results-dq-SlJbU.js} +17 -19
  28. package/dist/{StatusIcon-BylPx2EO.js → StatusIcon-AbxNvJ6p.js} +2 -2
  29. package/dist/{StoreTokenModal-zCSYhfrw.js → StoreTokenModal-CM8WXdu1.js} +2 -2
  30. package/dist/{SymbolsPane-BpmL___H.js → SymbolsPane-DfaxeaPS.js} +6 -3
  31. package/dist/{TrilogyEmbedProvider-WA_dlv9e.js → TrilogyEmbedProvider-D3h0gYnX.js} +9 -9
  32. package/dist/{TutorialPage-CZGBRJdq.js → TutorialPage-BtEJG7cT.js} +27 -28
  33. package/dist/{VegaLiteChart-CmkOw6yD.js → VegaLiteChart-BVyAab-o.js} +12191 -10975
  34. package/dist/{WelcomePage-CLKvAvk-.js → WelcomePage-BoqzYBLr.js} +5 -5
  35. package/dist/{embedTheme-Bub46ILG.js → _plugin-vue_export-helper-f9Rw-Il4.js} +14 -6
  36. package/dist/assets/{css.worker-9aDGcEUy.js → css.worker-niORQtzO.js} +14 -14
  37. package/dist/assets/{html.worker-D2LKDpnG.js → html.worker-CO5LvJpF.js} +17 -17
  38. package/dist/assets/json.worker-BezHzWUV.js +58 -0
  39. package/dist/assets/{ts.worker-Bz0-EaKK.js → ts.worker-CYhxGg0r.js} +107 -107
  40. package/dist/{results-DTgAKr5j.js → base-DuKnVD-A.js} +216 -45
  41. package/dist/components/AssetAutoImporter.vue.d.ts.map +1 -1
  42. package/dist/components/FeedbackBanner.vue.d.ts +4 -0
  43. package/dist/components/FeedbackBanner.vue.d.ts.map +1 -0
  44. package/dist/components/TipsCTA.vue.d.ts +1 -1
  45. package/dist/components/VegaLiteChart.vue.d.ts.map +1 -1
  46. package/dist/components/chartHelpers.d.ts +9 -1
  47. package/dist/components/chartHelpers.d.ts.map +1 -1
  48. package/dist/components/chartRenderManager.d.ts +4 -1
  49. package/dist/components/chartRenderManager.d.ts.map +1 -1
  50. package/dist/components/community/AddStoreModal.vue.d.ts +1 -1
  51. package/dist/components/community/AddStoreModal.vue.d.ts.map +1 -1
  52. package/dist/components/community/CommunityModelCard.vue.d.ts.map +1 -1
  53. package/dist/components/dashboard/DashboardCreatorIcon.vue.d.ts +54 -0
  54. package/dist/components/dashboard/DashboardCreatorIcon.vue.d.ts.map +1 -0
  55. package/dist/components/dashboard/DashboardProvenance.vue.d.ts +30 -0
  56. package/dist/components/dashboard/DashboardProvenance.vue.d.ts.map +1 -0
  57. package/dist/components/dashboard/ReportLayout.vue.d.ts +19 -0
  58. package/dist/components/dashboard/ReportLayout.vue.d.ts.map +1 -0
  59. package/dist/components/editor/Editor.vue.d.ts +3 -3
  60. package/dist/components/editor/Editor.vue.d.ts.map +1 -1
  61. package/dist/components/editor/EditorCreatorIcon.vue.d.ts +62 -0
  62. package/dist/components/editor/EditorCreatorIcon.vue.d.ts.map +1 -0
  63. package/dist/components/editor/ValidationComponent.vue.d.ts +50 -0
  64. package/dist/components/editor/ValidationComponent.vue.d.ts.map +1 -0
  65. package/dist/components/jobs/JobsAddStoreModal.vue.d.ts.map +1 -1
  66. package/dist/components/llm/ChatCreatorModal.vue.d.ts +17 -1
  67. package/dist/components/llm/ChatCreatorModal.vue.d.ts.map +1 -1
  68. package/dist/components/llm/ChatModelSelect.vue.d.ts +13 -0
  69. package/dist/components/llm/ChatModelSelect.vue.d.ts.map +1 -0
  70. package/dist/components/llm/GlobalChatPanel.vue.d.ts.map +1 -1
  71. package/dist/components/model/ModelCard.vue.d.ts +3 -3
  72. package/dist/components/sidebar/CommunityModelList.vue.d.ts +33 -50
  73. package/dist/components/sidebar/CommunityModelList.vue.d.ts.map +1 -1
  74. package/dist/components/sidebar/CommunityModelListItem.vue.d.ts.map +1 -1
  75. package/dist/components/sidebar/EditorList.vue.d.ts +32 -49
  76. package/dist/components/sidebar/EditorList.vue.d.ts.map +1 -1
  77. package/dist/components/sidebar/LLMConnectionList.vue.d.ts.map +1 -1
  78. package/dist/components/sidebar/Sidebar.vue.d.ts +65 -99
  79. package/dist/components/sidebar/Sidebar.vue.d.ts.map +1 -1
  80. package/dist/components/tutorial/TutorialPrompt.vue.d.ts +3 -3
  81. package/dist/components/tutorial/TutorialPrompt.vue.d.ts.map +1 -1
  82. package/dist/{remoteWorker-Dkv3TJ0j.js → connections-CWH3zwH2.js} +4544 -4126
  83. package/dist/connections.js +3 -4
  84. package/dist/{cssMode-D4Rzr1Cu.js → cssMode-zpO2ap2B.js} +5 -6
  85. package/dist/dashboard.js +54 -57
  86. package/dist/dashboards/layerSpec.d.ts +38 -4
  87. package/dist/dashboards/layerSpec.d.ts.map +1 -1
  88. package/dist/dashboards/lineAreaSpec.d.ts +8 -80
  89. package/dist/dashboards/lineAreaSpec.d.ts.map +1 -1
  90. package/dist/dashboards/mapSpec.d.ts +1 -0
  91. package/dist/dashboards/mapSpec.d.ts.map +1 -1
  92. package/dist/dashboards/spec.d.ts.map +1 -1
  93. package/dist/data/tutorial/documentation.d.ts.map +1 -1
  94. package/dist/data/tutorial/startupScripts.d.ts +3 -0
  95. package/dist/data/tutorial/startupScripts.d.ts.map +1 -0
  96. package/dist/{dist-CXoL8kXK.js → dist-1z5KURzS.js} +55 -50
  97. package/dist/{dist-DKkuvbPb.js → dist-Bv3D2p5A.js} +20 -18
  98. package/dist/{editor.main-Cl8i7rHY.js → editor.main-BQh6DxDB.js} +33 -33
  99. package/dist/{editorRefinementRuntime-C_YmXRy4.js → editorStore-CAlMJftt.js} +2084 -946
  100. package/dist/embed.js +2 -2
  101. package/dist/entry.dashboard.d.ts +1 -0
  102. package/dist/entry.dashboard.d.ts.map +1 -1
  103. package/dist/{freemarker2-fW5NBILf.js → freemarker2-DQBqlEXc.js} +1 -1
  104. package/dist/{globalChatRuntime-oMLiPLNC.js → globalChatRuntime-CyS7vH51.js} +18 -18
  105. package/dist/{handlebars-dG4w8UUY.js → handlebars-tgYxaM70.js} +1 -1
  106. package/dist/{helpers-DcWCa6bX.js → helpers-BbVlA3Pf.js} +39 -39
  107. package/dist/{html-1Dq70BdU.js → html-jJahD3Mi.js} +1 -1
  108. package/dist/{htmlMode--IQmLBeh.js → htmlMode-BA1-8l2e.js} +5 -6
  109. package/dist/{javascript-CTzBM4sF.js → javascript-Cypfo7va.js} +1 -1
  110. package/dist/{jsonMode-DzeJjIEH.js → jsonMode-xJye8PWS.js} +25 -25
  111. package/dist/{liquid-DlHThiki.js → liquid-BGDrv5da.js} +1 -1
  112. package/dist/llm/data/constants.d.ts +1 -1
  113. package/dist/llm/data/constants.d.ts.map +1 -1
  114. package/dist/llm/data/trilogySyntax.generated.d.ts +7 -1
  115. package/dist/llm/data/trilogySyntax.generated.d.ts.map +1 -1
  116. package/dist/llm/docsIndex.d.ts.map +1 -1
  117. package/dist/llm/openai.d.ts +2 -1
  118. package/dist/llm/openai.d.ts.map +1 -1
  119. package/dist/llm-ClU-2rgk.js +18493 -0
  120. package/dist/llm.js +2 -3
  121. package/dist/{localStorage-CSuYS7QE.js → localStorage-CGQ1iJXt.js} +39 -42
  122. package/dist/{lspLanguageFeatures-Cdfs3EKq.js → lspLanguageFeatures-V3e_p9oN.js} +32 -32
  123. package/dist/{mdx-fn3g4PH5.js → mdx-BUR1aImW.js} +1 -1
  124. package/dist/models/helpers.d.ts.map +1 -1
  125. package/dist/monaco.js +3 -3
  126. package/dist/{python-CCVj0pFt.js → python-YLkl0pc6.js} +1 -1
  127. package/dist/{razor-Cj3flYnk.js → razor-BP8TRMDY.js} +1 -1
  128. package/dist/{reconcile-Bk7M797_.js → reconcile-DXIvGwBk.js} +1 -1
  129. package/dist/{remoteStoreSync-CLvZJrTK.js → remoteStoreSync-CuQBWpWf.js} +3 -3
  130. package/dist/remotes/displayHelpers.d.ts.map +1 -1
  131. package/dist/remotes/genericStoreMetadata.d.ts +1 -0
  132. package/dist/remotes/genericStoreMetadata.d.ts.map +1 -1
  133. package/dist/remotes/models.d.ts +37 -5
  134. package/dist/remotes/models.d.ts.map +1 -1
  135. package/dist/remotes/staticStorePresets.d.ts +22 -0
  136. package/dist/remotes/staticStorePresets.d.ts.map +1 -0
  137. package/dist/remotes/storeService.d.ts +25 -4
  138. package/dist/remotes/storeService.d.ts.map +1 -1
  139. package/dist/{rolldown-runtime-Dqa2HsxW.js → rolldown-runtime-B0aSnxlc.js} +2 -2
  140. package/dist/static/test_import.vue.d.ts +4 -0
  141. package/dist/static/test_import.vue.d.ts.map +1 -0
  142. package/dist/stores/communityApiStore.d.ts +32 -60
  143. package/dist/stores/communityApiStore.d.ts.map +1 -1
  144. package/dist/stores/connectionStore.d.ts.map +1 -1
  145. package/dist/stores/resolver.d.ts +5 -0
  146. package/dist/stores/resolver.d.ts.map +1 -1
  147. package/dist/stores/urlStore.d.ts +1 -0
  148. package/dist/stores/urlStore.d.ts.map +1 -1
  149. package/dist/stores-LlyiwSbK.js +2604 -0
  150. package/dist/stores.js +4 -7
  151. package/dist/trilogy-studio-components.css +1 -1
  152. package/dist/{tsMode-GI4xMYAl.js → tsMode-BH9HS_sH.js} +64 -66
  153. package/dist/{typescript-CPibXi3J.js → typescript-BM-ynfk9.js} +1 -1
  154. package/dist/{useChatWithTools-GV1ufcqw.js → useChatWithTools-m3Jn_SV-.js} +11 -11
  155. package/dist/{useDashboard-OoBKkkuQ.js → useDashboard-BOAuvVEw.js} +1013 -1021
  156. package/dist/{tabulator_esm-CxLvGDp8.js → useGlobalChatPanel-DuP1q7_f.js} +1729 -711
  157. package/dist/{useResizableDialog-B0ePSts4.js → useResizableDialog-Cs90WJdF.js} +2 -2
  158. package/dist/views/MobileIDE.vue.d.ts.map +1 -1
  159. package/dist/views/ModelView.vue.d.ts +6 -6
  160. package/dist/views/ModelView.vue.d.ts.map +1 -1
  161. package/dist/views/TutorialPage.vue.d.ts +41 -58
  162. package/dist/views/TutorialPage.vue.d.ts.map +1 -1
  163. package/dist/views.js +193 -195
  164. package/dist/{editor.api2-ClD5pp8H.js → workers-B9Eybl-M.js} +16252 -15926
  165. package/dist/{xml-BNyphceI.js → xml-M5WFPSpA.js} +1 -1
  166. package/dist/{yaml-DE5Vz0PH.js → yaml-CEeFwjz9.js} +1 -1
  167. package/package.json +29 -20
  168. package/dist/AssetAutoImporter-DfMd_DSk.js +0 -403
  169. package/dist/ChatCreatorModal-BTqY06B6.js +0 -177
  170. package/dist/DashboardCreatorInline-LWvf--2x.js +0 -129
  171. package/dist/DataTable-DoRDynP1.js +0 -365
  172. package/dist/EditorCreatorInline-D6_y1H_h.js +0 -125
  173. package/dist/LoadingButton-OH3frQuO.js +0 -138
  174. package/dist/MobileIDE-CHGJoh05.js +0 -781
  175. package/dist/ModalDialog-D1EOG4rl.js +0 -42
  176. package/dist/ModelCreator-DrxLxeyH.js +0 -253
  177. package/dist/PageLoading-I6mr-7NB.js +0 -2666
  178. package/dist/Tooltip-Dihir4zs.js +0 -103
  179. package/dist/_plugin-vue_export-helper-B3ysoDQm.js +0 -8
  180. package/dist/assets/json.worker-CJ5MmO5Q.js +0 -58
  181. package/dist/base-C8IuZWqY.js +0 -164
  182. package/dist/connectionHistoryStorage-DKJHiKJY.js +0 -111
  183. package/dist/connectionHistoryStore-DQeBvStZ.js +0 -61
  184. package/dist/connections-CJSb1TZl.js +0 -229
  185. package/dist/constants-DgFEYN2b.js +0 -7
  186. package/dist/dashboardStore-CNkWQ4r7.js +0 -641
  187. package/dist/demoSetup-DiW3ROFQ.js +0 -2941
  188. package/dist/editorRefinementToolExecutor-mX8ClQ63.js +0 -4498
  189. package/dist/editorStore-Ch7k-gse.js +0 -972
  190. package/dist/formatting-BbJ5ICgh.js +0 -6
  191. package/dist/llm-_807I79k.js +0 -11965
  192. package/dist/llmStore-CSzM1IZd.js +0 -153
  193. package/dist/monaco.contribution-ikesdolO.js +0 -128
  194. package/dist/stores-C1wUWiFm.js +0 -1708
  195. package/dist/trilogy-BroD2Qmp.js +0 -4
  196. package/dist/urlStore-Dgmwx1YI.js +0 -54
  197. package/dist/useGlobalChatPanel-CIeUyZba.js +0 -85
  198. package/dist/useIsMobile-CNpUQAvk.js +0 -8
  199. package/dist/usePrismHighlight-DVyDiDAL.js +0 -183
  200. package/dist/workers-Br7ThUKL.js +0 -47
@@ -0,0 +1,2604 @@
1
+ import { c as e, u as t } from "./base-DuKnVD-A.js";
2
+ import { Ct as n, Dt as r, Et as i, Ft as a, Gt as o, It as s, Ot as c, Tt as l, _t as u, bt as d, fn as f, gt as p, kt as m, vt as h, wt as g } from "./llm-ClU-2rgk.js";
3
+ import { C as _, F as v, H as y, I as b, L as x, N as S, P as C, R as ee, S as te, i as ne, it as w, q as re, s as ie, t as ae, z as T } from "./editorStore-CAlMJftt.js";
4
+ import { t as oe } from "./connections-CWH3zwH2.js";
5
+ import { n as se, t as E } from "./chatHelpers-F_woEbYF.js";
6
+ import { computed as D, ref as O } from "vue";
7
+ import { defineStore as k } from "pinia";
8
+ //#region data/tips.ts
9
+ var ce = [
10
+ {
11
+ id: "welcome",
12
+ title: "Welcome!",
13
+ content: "Welcome to Trilogy Studio, an analytics IDE! Let's get you started with the basics. If you know what you're doing, feel free to dismiss these tips.",
14
+ category: "onboarding"
15
+ },
16
+ {
17
+ id: "navigation",
18
+ title: "Navigation",
19
+ content: "Access different sections through the sidebar on the left. The right side contains a tabbed browser with your primary workspaces. Opening new items will open new tabs.",
20
+ category: "onboarding",
21
+ highlightDataTestId: "sidebar-icons"
22
+ },
23
+ {
24
+ id: "settings",
25
+ title: "Settings",
26
+ content: "User settings - such as darkmode - can be accessed through the gear on the bottom of the sidebar.",
27
+ category: "onboarding",
28
+ highlightDataTestId: "sidebar-icon-settings"
29
+ },
30
+ {
31
+ id: "trilogy",
32
+ title: "Trilogy - The Query Language",
33
+ content: "The studio supports standard SQL, but most rich functionality expects you to write Trilogy, a modified SQL syntax that streamlines analytics. The tutorial in the help section is the best way to get up to speed with it!",
34
+ category: "onboarding",
35
+ highlightDataTestId: "sidebar-icon-tutorial"
36
+ }
37
+ ], le = [
38
+ {
39
+ id: "editor-intro",
40
+ title: "Settings",
41
+ content: "Editors let you run SQL or Trilogy commands. Click the run button in top right to run a query.",
42
+ category: "editor",
43
+ highlightDataTestId: "editor-run-button"
44
+ },
45
+ {
46
+ id: "editor-shortcuts",
47
+ title: "Keyboard Shortcuts",
48
+ content: "Standard keyboard shortcuts are available to run, validate, generate AI code, format, and save your work.",
49
+ category: "editor",
50
+ highlightDataTestId: "editor-shortcut-hints"
51
+ },
52
+ {
53
+ id: "editor-validate",
54
+ title: "Validate",
55
+ content: "Click the validate button to parse the current Trilogy script. This will provide syntax feedback and populate the schema explorer on the right.",
56
+ category: "editor",
57
+ highlightDataTestId: "editor-validate-button"
58
+ },
59
+ {
60
+ id: "editor-save",
61
+ title: "Save",
62
+ content: "Click the save button to save your changes to local browser storage. Trilogy will auto-save regularly, but you can trigger on demand.",
63
+ category: "editor",
64
+ highlightDataTestId: "editor-save-button"
65
+ },
66
+ {
67
+ id: "editor-sources",
68
+ title: "Sources",
69
+ content: "An editor can be marked as a \"source\". Sources are special editors that can be imported by other editors using import syntax `import <editor_name> as <alias>. Use this to create reusable abstractions and models.",
70
+ category: "editor",
71
+ highlightDataTestId: "editor-set-source"
72
+ },
73
+ {
74
+ id: "editor-ai",
75
+ title: "AI Assistance",
76
+ content: "If you have configured an LLM connection, you can interact with the AI assistant via a chat window. The assistant can help you generate or update code, but will not have direct access to your db.",
77
+ category: "editor",
78
+ highlightDataTestId: "editor-generate-button"
79
+ }
80
+ ], ue = [
81
+ {
82
+ id: "dashboard-intro",
83
+ title: "Dashboard",
84
+ content: "Welcome to a dashboard - a way of interactively exploring visualized data and markup. It natively support cross-filtering, drilldown, global filtering, and other interactivity. Click or drag on charts to filter. They are designed to be lightweight, customizable, and interactive. You can close these tips in the top right if you know what you're doing!",
85
+ category: "dashboard"
86
+ },
87
+ {
88
+ id: "dashboard-full-screen",
89
+ title: "Full Screen",
90
+ content: "Dashboards can be full-screen for viewing and analysis or in edit mode, which will allow you to modify the layout and content. Use the button in the top right to toggle between modes.",
91
+ category: "dashboard",
92
+ highlightDataTestId: "toggle-edit-mode-button"
93
+ },
94
+ {
95
+ id: "dashboard-add-item",
96
+ title: "Add Dashboard Item",
97
+ content: "Use the add item button in the top left to add new charts, tables, markdown blocks, or filters to your dashboard. You will need to be in edit mode to see it.",
98
+ category: "dashboard",
99
+ highlightDataTestId: "add-item-button"
100
+ },
101
+ {
102
+ id: "dashboard-edit",
103
+ title: "Dashboard Data",
104
+ content: "Dashboarding is Trilogy-SQL centric. To populate an item, you need to give it a data query. Click the edit button on the item header to configure data and appearance. (the header is available when you mouse over a widget in edit mode.) ",
105
+ category: "dashboard",
106
+ highlightDataTestId: "dashboard-item-header-controls"
107
+ },
108
+ {
109
+ id: "dashboard-filter",
110
+ title: "Dashboard Filters",
111
+ content: "The omni-filter bar at the top of dashboards can be used to filter all items. You can also add filter widgets, which are just queries that render as a search box and cross-filter content.",
112
+ category: "dashboard",
113
+ highlightDataTestId: "filter-input"
114
+ },
115
+ {
116
+ id: "dashboard-source",
117
+ title: "Dashboard Source",
118
+ content: "Dashboards run queries against a source editor. Add any new common fields or calculations to the source so they can be used throughout the dashboard. If you define a calculation locally to a widget, it will not be usable for cross-filtering across widgets.",
119
+ category: "dashboard",
120
+ highlightDataTestId: "dashboard-import-wrapper"
121
+ },
122
+ {
123
+ id: "dashboard-connection",
124
+ title: "Dashboard Connection",
125
+ content: "Dashboards run queries against a source editor, which in turn runs against a database connection. You can change the connection for the source editor using the connection selector in the top right.",
126
+ category: "dashboard",
127
+ highlightDataTestId: "connection-selector-wrapper"
128
+ },
129
+ {
130
+ id: "dashboard-features",
131
+ title: "Complex Types",
132
+ content: "A basic dashboard is just charts and tables, but you can use Markdown blocks and filters to make more rich, interactive experiences. Markdown blocks can have source trilogy queries and have a special syntax for embedding results in line.",
133
+ category: "dashboard"
134
+ }
135
+ ], de = [{
136
+ id: "model-intro",
137
+ title: "Community Models",
138
+ content: "Packages of data and metadata can be shared as community models. You can use this page to browse and import models. Models are open-source and community contributed.",
139
+ category: "community",
140
+ highlightDataTestId: "sidebar-icon-community-models"
141
+ }, {
142
+ id: "feature-update",
143
+ title: "Sharing Dashboards!",
144
+ content: "Dashboard share links are a special URL that lets you share dashboards with others. It will automatically import the relevant model to support the dashboard. This will only work with public models though; not any that you have defined locally.",
145
+ category: "community",
146
+ highlightDataTestId: "copy-dashboard-share-button"
147
+ }];
148
+ //#endregion
149
+ //#region projects/project.ts
150
+ function fe() {
151
+ return `proj-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
152
+ }
153
+ var A = class e {
154
+ id;
155
+ name;
156
+ description;
157
+ dataConnectionId;
158
+ llmConnectionName;
159
+ editorIds;
160
+ subchatIds;
161
+ dashboardIds;
162
+ directoryPath;
163
+ promptOverrides;
164
+ createdAt;
165
+ updatedAt;
166
+ storage;
167
+ changed;
168
+ deleted;
169
+ constructor(e = {}) {
170
+ this.id = e.id || fe(), this.name = e.name || "Untitled project", this.description = e.description || "", this.dataConnectionId = e.dataConnectionId || "", this.llmConnectionName = e.llmConnectionName || "", this.editorIds = e.editorIds || [], this.subchatIds = e.subchatIds || [], this.dashboardIds = e.dashboardIds || [], this.directoryPath = e.directoryPath || "", this.promptOverrides = e.promptOverrides ? { ...e.promptOverrides } : {}, this.createdAt = e.createdAt || /* @__PURE__ */ new Date(), this.updatedAt = e.updatedAt || /* @__PURE__ */ new Date(), this.storage = e.storage || "local", this.changed = e.changed ?? !0, this.deleted = e.deleted ?? !1;
171
+ }
172
+ setName(e) {
173
+ this.name !== e && (this.name = e, this.touch());
174
+ }
175
+ setDescription(e) {
176
+ this.description !== e && (this.description = e, this.touch());
177
+ }
178
+ setDirectoryPath(e) {
179
+ this.directoryPath !== e && (this.directoryPath = e, this.touch());
180
+ }
181
+ setPromptOverride(e, t) {
182
+ let n = t?.trim() ?? "", r = this.promptOverrides[e];
183
+ if (n) {
184
+ if (r === n) return;
185
+ this.promptOverrides[e] = n;
186
+ } else {
187
+ if (r === void 0) return;
188
+ delete this.promptOverrides[e];
189
+ }
190
+ this.touch();
191
+ }
192
+ addSubchat(e) {
193
+ return !this.subchatIds.includes(e) && (this.subchatIds.push(e), this.touch(), !0);
194
+ }
195
+ removeSubchat(e) {
196
+ let t = this.subchatIds.indexOf(e);
197
+ return t !== -1 && (this.subchatIds.splice(t, 1), this.touch(), !0);
198
+ }
199
+ addEditor(e) {
200
+ return !this.editorIds.includes(e) && (this.editorIds.push(e), this.touch(), !0);
201
+ }
202
+ removeEditor(e) {
203
+ let t = this.editorIds.indexOf(e);
204
+ return t !== -1 && (this.editorIds.splice(t, 1), this.touch(), !0);
205
+ }
206
+ addDashboard(e) {
207
+ return !this.dashboardIds.includes(e) && (this.dashboardIds.push(e), this.touch(), !0);
208
+ }
209
+ removeDashboard(e) {
210
+ let t = this.dashboardIds.indexOf(e);
211
+ return t !== -1 && (this.dashboardIds.splice(t, 1), this.touch(), !0);
212
+ }
213
+ touch() {
214
+ this.updatedAt = /* @__PURE__ */ new Date(), this.changed = !0;
215
+ }
216
+ serialize() {
217
+ return {
218
+ id: this.id,
219
+ name: this.name,
220
+ description: this.description,
221
+ dataConnectionId: this.dataConnectionId,
222
+ llmConnectionName: this.llmConnectionName,
223
+ editorIds: this.editorIds,
224
+ subchatIds: this.subchatIds,
225
+ dashboardIds: this.dashboardIds,
226
+ directoryPath: this.directoryPath,
227
+ promptOverrides: { ...this.promptOverrides },
228
+ createdAt: this.createdAt.toISOString(),
229
+ updatedAt: this.updatedAt.toISOString(),
230
+ storage: this.storage
231
+ };
232
+ }
233
+ static fromSerialized(t) {
234
+ return new e({
235
+ ...t,
236
+ createdAt: t.createdAt ? new Date(t.createdAt) : /* @__PURE__ */ new Date(),
237
+ updatedAt: t.updatedAt ? new Date(t.updatedAt) : /* @__PURE__ */ new Date(),
238
+ changed: !1
239
+ });
240
+ }
241
+ }, j = (e) => {
242
+ let t = e.replace(/'''/g, "```").replace(/"""/g, "```").replace(/```(trilogy|sql|json)(\s|\n)/g, "```");
243
+ for (let e of ["```\\s*```", "```"]) {
244
+ let n = t.match(RegExp(`${e}([\\s\\S]*)${e}`, "s"));
245
+ if (n) return n[n.length - 1];
246
+ }
247
+ return e;
248
+ }, pe = k("llmConnections", {
249
+ state: () => ({
250
+ connections: {},
251
+ activeConnection: ""
252
+ }),
253
+ actions: {
254
+ addConnection(e, t = !0) {
255
+ let n = e.name;
256
+ return this.activeConnection ||= n, t && Object.values(this.connections).filter((e) => e.isDefault).length === 0 && (e.isDefault = !0), this.connections[n] = e, e;
257
+ },
258
+ async resetConnection(e) {
259
+ if (this.connections[e]) return await this.connections[e].reset();
260
+ throw Error(`LLM connection with name "${e}" not found.`);
261
+ },
262
+ resetConnectionInBackground(e) {
263
+ this.resetConnection(e).catch(() => {});
264
+ },
265
+ connectionStateToStatus(e) {
266
+ if (!e) return "disabled";
267
+ let t = e;
268
+ return t.error ? "failed" : t.running ? "running" : t.connected ? "connected" : "disabled";
269
+ },
270
+ async newConnection(e, t, a) {
271
+ if (this.connections[e]) throw Error(`LLM connection with name "${e}" already exists.`);
272
+ let o;
273
+ if (t === "demo") o = new r(e, a.model);
274
+ else if (t === "anthropic") o = new l(e, a.apiKey, a.model, a.saveCredential);
275
+ else if (t === "openai") o = new i(e, a.apiKey, a.model, a.saveCredential);
276
+ else if (t === "google") o = new g(e, a.apiKey, a.model, a.saveCredential);
277
+ else if (t === "openrouter") o = new c(e, a.apiKey, a.model, a.saveCredential, void 0, {
278
+ httpReferer: a.httpReferer,
279
+ appTitle: a.appTitle
280
+ });
281
+ else if (t === "deepseek") o = new n(e, a.apiKey, a.model, a.saveCredential);
282
+ else throw Error(`LLM provider type "${t}" not found.`);
283
+ return this.addConnection(o), this.resetConnectionInBackground(e), o;
284
+ },
285
+ async fetchModelsForProvider(e, t) {
286
+ let r, a = `__temp_${e}_${Date.now()}`;
287
+ if (e === "anthropic") r = new l(a, t, "", !1);
288
+ else if (e === "openai") r = new i(a, t, "", !1);
289
+ else if (e === "google") r = new g(a, t, "", !1);
290
+ else if (e === "openrouter") r = new c(a, t, "", !1);
291
+ else if (e === "deepseek") r = new n(a, t, "", !1);
292
+ else throw Error(`LLM provider type "${e}" not found.`);
293
+ return await r.reset(), r.models;
294
+ },
295
+ async generateValidatedCompletion(e, t = null, n = 3, r = null, i = null, a = !0) {
296
+ let o = r || this.activeConnection || "", s = i || [];
297
+ if (o === "") throw Error("No active LLM connection");
298
+ let c = 0, l = !1, u = "", d = await this.generateCompletion(o, { prompt: e }, i);
299
+ if (a && s.push({
300
+ role: "user",
301
+ content: e
302
+ }), s.push({
303
+ role: "assistant",
304
+ content: d.text,
305
+ toolCalls: d.toolCalls
306
+ }), console.log("Initial LLM response:", d.text), u = j(d.text), t) for (; c < n && !l;) try {
307
+ if (!u || u.trim() == "") throw Error("Attempt to extract contents of triple backticks returned null or empty string");
308
+ l = await t(u), console.log("LLM response validation passed"), l = !0;
309
+ } catch (e) {
310
+ if (console.log("LLM response validation failed"), console.log(e), c++, c >= n) {
311
+ console.log(`Max attempts (${n}) reached, returning last response`);
312
+ break;
313
+ }
314
+ let t = e.message, r = `\nYou had given a response: """${u}""" that failed validation on this error: ${t}. Generate a new response that solves the original request while fixing the error. Ensure the new answer to validate is still enclosed within triple double quotes with no extra content. Put your reasoning on the fix before the quotes.`;
315
+ d = await this.generateCompletion(o, { prompt: r }, s), s.push({
316
+ role: "user",
317
+ content: r
318
+ }), s.push({
319
+ role: "assistant",
320
+ content: d.text,
321
+ toolCalls: d.toolCalls
322
+ }), u = j(d.text), console.log(`Attempt ${c}. New extract:`, u);
323
+ }
324
+ return console.log("Exiting validation loop with attempts:", c), console.log("Final LLM response:", u), {
325
+ success: l,
326
+ prompt: e,
327
+ message: d.text,
328
+ content: u,
329
+ attempts: c,
330
+ error: l ? null : "Validation failed after maximum attempts"
331
+ };
332
+ },
333
+ async generateDashboardCompletion(e, t = null, n = [], r = 3) {
334
+ let i = p(e, n);
335
+ return this.generateValidatedCompletion(i, t, r).then((e) => e.content);
336
+ },
337
+ async generateQueryCompletion(e, t, n = null, r = 3, i = null) {
338
+ let a = h(e, t);
339
+ return this.generateValidatedCompletion(a, n, r, i);
340
+ },
341
+ async generateSQLQueryCompletion(e) {
342
+ return this.generateCompletion(this.activeConnection, { prompt: e }).then((t) => ({
343
+ success: !0,
344
+ prompt: e,
345
+ message: t.text,
346
+ content: j(t.text),
347
+ attempts: 1
348
+ }));
349
+ },
350
+ async generateFilterQuery(e, t, n = null, r = 3) {
351
+ let i = u(e, t);
352
+ return this.generateValidatedCompletion(i, n, r).then((e) => e.content);
353
+ },
354
+ async generateChatName(e, t) {
355
+ let n = this.connections[e];
356
+ if (!n) throw Error(`LLM connection with name "${e}" not found.`);
357
+ let r = E(t), i = n.model, a = n.getFastModel();
358
+ try {
359
+ a !== i && (n.model = a);
360
+ let e = await n.generateCompletion({
361
+ prompt: r,
362
+ maxTokens: 50,
363
+ temperature: .7
364
+ }, null);
365
+ return se(e.text);
366
+ } finally {
367
+ a !== i && (n.model = i);
368
+ }
369
+ },
370
+ async generateCompletion(e, t, n = null) {
371
+ if (!this.connections[e]) throw Error(`LLM connection with name "${e}" not found.`);
372
+ return await this.connections[e].generateCompletion(t, n);
373
+ }
374
+ },
375
+ getters: {
376
+ connectionList: (e) => Object.keys(e.connections).map((t) => e.connections[t]),
377
+ unsavedConnections: (e) => Object.values(e.connections).filter((e) => e.changed).length,
378
+ getConnection: (e) => (t) => e.connections[t] || null,
379
+ getAllConnections: (e) => Object.values(e.connections),
380
+ getConnectionStatus: (e) => (t) => {
381
+ let n = e.connections[t];
382
+ if (!n) return "disabled";
383
+ let r = n;
384
+ return r.error ? "failed" : r.running ? "running" : r.connected ? "connected" : "disabled";
385
+ },
386
+ hasActiveDefaultConnection: (e) => Object.values(e.connections).some((e) => e.isDefault && e.connected)
387
+ }
388
+ });
389
+ //#endregion
390
+ //#region dashboards/dashboardQueryExecutor.ts
391
+ function me(e) {
392
+ return typeof e == "string" ? e : typeof e?.error == "string" && e.error ? e.error : typeof e?.message == "string" && e.message ? e.message : "Unknown error occurred";
393
+ }
394
+ var M = class {
395
+ queryQueue = /* @__PURE__ */ new Map();
396
+ activeQueries = /* @__PURE__ */ new Set();
397
+ queryWaiters = /* @__PURE__ */ new Map();
398
+ latestQueryByItemId = /* @__PURE__ */ new Map();
399
+ itemIdsByQueryId = /* @__PURE__ */ new Map();
400
+ queryExecutionService;
401
+ connectionName;
402
+ dashboardId;
403
+ getItemData;
404
+ setItemData;
405
+ getDashboardData;
406
+ maxConcurrentQueries;
407
+ retryAttempts;
408
+ batchDelay;
409
+ batchTimeout = null;
410
+ constructor(e, t, n, r, i, a, o = {}) {
411
+ this.queryExecutionService = e, this.connectionName = t, this.maxConcurrentQueries = o.maxConcurrentQueries || 10, this.retryAttempts = o.retryAttempts || 2, this.batchDelay = o.batchDelay || 0, this.dashboardId = n, this.getItemData = i, this.setItemData = a, this.getDashboardData = r;
412
+ }
413
+ cancelPendingQueriesForItem(e) {
414
+ let t = this.latestQueryByItemId.get(e), n = [];
415
+ this.queryQueue.forEach((r, i) => {
416
+ r.itemId === e && i !== t && n.push(i);
417
+ }), this.activeQueries.forEach((r) => {
418
+ let i = this.itemIdsByQueryId.get(r);
419
+ i?.has(e) && r !== t && ([...i].some((t) => t !== e && this.latestQueryByItemId.get(t) === r) || n.push(r));
420
+ }), n.forEach((t) => {
421
+ console.log(`Cancelling outdated query ${t} for itemId ${e}`), this.cancelQuery(t);
422
+ });
423
+ }
424
+ trackQueryForItem(e, t) {
425
+ this.latestQueryByItemId.set(e, t);
426
+ let n = this.itemIdsByQueryId.get(t);
427
+ n ? n.add(e) : this.itemIdsByQueryId.set(t, /* @__PURE__ */ new Set([e]));
428
+ }
429
+ isLatestQueryForItem(e, t) {
430
+ return this.latestQueryByItemId.get(e) === t;
431
+ }
432
+ isQueryInFlight(e) {
433
+ return this.queryQueue.has(e) || this.activeQueries.has(e);
434
+ }
435
+ settleQueryLoading(e) {
436
+ let t = this.itemIdsByQueryId.get(e);
437
+ if (t) for (let e of t) {
438
+ let t = this.latestQueryByItemId.get(e);
439
+ t && this.isQueryInFlight(t) || this.setItemData(e, this.dashboardId, { loading: !1 });
440
+ }
441
+ }
442
+ cleanupQueryTracking(e) {
443
+ let t = this.itemIdsByQueryId.get(e);
444
+ if (t) {
445
+ for (let n of t) this.latestQueryByItemId.get(n) === e && this.latestQueryByItemId.delete(n);
446
+ this.itemIdsByQueryId.delete(e);
447
+ }
448
+ }
449
+ getDefaultPriority(e) {
450
+ return this.getDashboardData(this.dashboardId).layout.find((t) => t.i === e)?.y || 0;
451
+ }
452
+ setConnection(e) {
453
+ this.connectionName = e;
454
+ }
455
+ getDashboardImports() {
456
+ return this.getDashboardData(this.dashboardId).imports.map((e) => ({
457
+ name: e.name,
458
+ alias: e.alias
459
+ }));
460
+ }
461
+ waitForQuery(e) {
462
+ return new Promise((t, n) => {
463
+ if (!this.queryQueue.has(e) && !this.activeQueries.has(e)) {
464
+ n(/* @__PURE__ */ Error(`Query ${e} not found or already completed`));
465
+ return;
466
+ }
467
+ this.queryWaiters.set(e, {
468
+ resolve: t,
469
+ reject: n
470
+ });
471
+ });
472
+ }
473
+ getItemQueryText(e) {
474
+ return (e.structured_content ? e.structured_content.query : e.content) || "";
475
+ }
476
+ enqueueItemQuery(e, t) {
477
+ let n = this.getItemData(e, this.dashboardId), r = this.getItemQueryText(n);
478
+ if (r.trim().length === 0) return this.setItemData(e, this.dashboardId, {
479
+ error: null,
480
+ loading: !1
481
+ }), null;
482
+ let i = n.filters || [], a = Object.assign({}, ...i.map((e) => e.parameters || {}));
483
+ this.setItemData(e, this.dashboardId, {
484
+ loading: !0,
485
+ error: null
486
+ });
487
+ let o, s = () => this.isLatestQueryForItem(e, o), c = {
488
+ dashboardId: this.dashboardId,
489
+ queryInput: {
490
+ text: r,
491
+ extraFilters: i.map((e) => e.value),
492
+ parameters: {
493
+ ...n.parameters || {},
494
+ ...a
495
+ },
496
+ extraContent: n.rootContent || []
497
+ },
498
+ priority: this.getDefaultPriority(e),
499
+ itemId: e,
500
+ onSuccess: (t) => {
501
+ s() ? this.setItemData(e, this.dashboardId, { results: t.results }) : console.log(`Ignoring outdated query result for itemId ${e}`);
502
+ },
503
+ onError: (t) => {
504
+ s() ? this.setItemData(e, this.dashboardId, { error: t }) : console.log(`Ignoring outdated query error for itemId ${e}`);
505
+ },
506
+ onProgress: (e) => {}
507
+ }, l = this.generateQueryId(c);
508
+ this.cancelPendingQueriesForItem(e);
509
+ let u = this.findDuplicateQuery(c);
510
+ if (u) console.log(`Deduplicating query for ${e}`), o = u.id, this.addCallbacksToExistingQuery(u, c);
511
+ else {
512
+ o = l;
513
+ let n = {
514
+ ...c,
515
+ id: o,
516
+ timestamp: Date.now(),
517
+ retryCount: 0
518
+ };
519
+ this.queryQueue.set(o, n), t && this.activeQueries.size < this.maxConcurrentQueries && (console.log(`Executing query immediately for ${e}`), this.executeQuery(o));
520
+ }
521
+ return this.trackQueryForItem(e, o), o;
522
+ }
523
+ runSingle(e) {
524
+ return this.enqueueItemQuery(e, !0);
525
+ }
526
+ runBatch(e) {
527
+ this.batchTimeout && clearTimeout(this.batchTimeout);
528
+ let t = e.map((e) => this.enqueueItemQuery(e, !1)).filter((e) => e !== null);
529
+ return this.batchTimeout = setTimeout(() => {
530
+ this.processBatch();
531
+ }, this.batchDelay), t;
532
+ }
533
+ cancelQuery(e) {
534
+ let t = this.queryWaiters.get(e);
535
+ return t && (t.reject("Query was cancelled"), this.queryWaiters.delete(e)), this.cleanupQueryTracking(e), this.queryQueue.has(e) ? (this.queryQueue.delete(e), !0) : this.activeQueries.has(e) ? (this.activeQueries.delete(e), !0) : !1;
536
+ }
537
+ clearQueue() {
538
+ this.queryWaiters.forEach((e, t) => {
539
+ e.reject("Queue was cleared");
540
+ }), this.queryWaiters.clear(), this.queryQueue.clear(), this.latestQueryByItemId.clear(), this.itemIdsByQueryId.clear(), this.batchTimeout &&= (clearTimeout(this.batchTimeout), null);
541
+ }
542
+ getStatus() {
543
+ return {
544
+ queued: this.queryQueue.size,
545
+ active: this.activeQueries.size,
546
+ queuedQueries: Array.from(this.queryQueue.values()),
547
+ latestQueryByItemId: Object.fromEntries(this.latestQueryByItemId)
548
+ };
549
+ }
550
+ async createDrilldownQuery(e, t, n, r, i = [], a = this.getDashboardImports()) {
551
+ return await this.queryExecutionService.createConnectionDrilldownQuery(this.connectionName, e, "trilogy", a, t, n, r, i);
552
+ }
553
+ generateQueryId(e) {
554
+ return `${e.dashboardId}-${e.itemId}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
555
+ }
556
+ findDuplicateQuery(e) {
557
+ for (let [, t] of this.queryQueue) if (t.dashboardId === e.dashboardId && t.queryInput.text === e.queryInput.text && JSON.stringify(t.queryInput.extraFilters) === JSON.stringify(e.queryInput.extraFilters) && JSON.stringify(t.queryInput.parameters) === JSON.stringify(e.queryInput.parameters)) return t;
558
+ return null;
559
+ }
560
+ addCallbacksToExistingQuery(e, t) {
561
+ let n = e.onSuccess, r = e.onError, i = e.onProgress;
562
+ e.onSuccess = (e) => {
563
+ n(e), t.onSuccess(e);
564
+ }, e.onError = (e) => {
565
+ r(e), t.onError(e);
566
+ }, e.onProgress = (e) => {
567
+ i(e), t.onProgress(e);
568
+ }, e.priority = Math.min(e.priority, t.priority);
569
+ }
570
+ processBatch() {
571
+ if (this.queryQueue.size === 0) return;
572
+ let e = Array.from(this.queryQueue.values()).sort((e, t) => e.priority === t.priority ? e.timestamp - t.timestamp : e.priority - t.priority), t = this.maxConcurrentQueries - this.activeQueries.size, n = e.slice(0, t);
573
+ this.executeBatchQueries(n);
574
+ }
575
+ async executeBatchQueries(e) {
576
+ if (e.length !== 0) try {
577
+ let t = this.getDashboardImports(), n = [], r = [];
578
+ for (let t of e) {
579
+ let e = t.id;
580
+ this.activeQueries.has(e) || this.queryQueue.has(e) && (this.queryQueue.delete(e), this.activeQueries.add(e), n.push({
581
+ query: t.queryInput.text,
582
+ label: e,
583
+ extra_filters: t.queryInput.extraFilters,
584
+ parameters: t.queryInput.parameters
585
+ }), r.push(t));
586
+ }
587
+ if (n.length === 0) return;
588
+ let i = Object.fromEntries(n.map((e) => [e.label, (t) => {
589
+ r.find((t) => t.id === e.label)?.onSuccess(t);
590
+ let n = this.queryWaiters.get(e.label);
591
+ n && (n.resolve(t), this.queryWaiters.delete(e.label)), this.activeQueries.delete(e.label), this.settleQueryLoading(e.label), this.cleanupQueryTracking(e.label);
592
+ }])), a = Object.fromEntries(n.map((e) => [e.label, (t) => {
593
+ let n = me(t), i = r.find((t) => t.id === e.label);
594
+ i && this.handleQueryError(i, n), this.activeQueries.delete(e.label), this.settleQueryLoading(e.label), this.cleanupQueryTracking(e.label);
595
+ }])), { resultPromise: o } = await this.queryExecutionService.executeQueriesBatch(this.connectionName, n, "trilogy", t, [], {}, () => {}, () => {}, a, i, !1, r[0]?.queryInput.extraContent || []), s = await o;
596
+ console.log(`Batch query executed successfully with ${s.results.length} results`);
597
+ } catch (t) {
598
+ let n = t instanceof Error ? t.message : "Unknown error occurred";
599
+ for (let t of e) {
600
+ let e = t.id;
601
+ this.activeQueries.has(e) && (t.retryCount < this.retryAttempts ? (console.log(`Retrying query ${e} (attempt ${t.retryCount + 1})`), t.retryCount++, t.timestamp = Date.now(), this.activeQueries.delete(e), this.queryQueue.set(e, t), setTimeout(() => {
602
+ this.queryQueue.has(e) && this.executeQuery(e);
603
+ }, 1e3 * t.retryCount)) : (this.handleQueryError(t, n), this.activeQueries.delete(e), this.settleQueryLoading(e), this.cleanupQueryTracking(e)));
604
+ }
605
+ } finally {
606
+ this.processBatch();
607
+ }
608
+ }
609
+ handleQueryError(e, t) {
610
+ let n = e.id;
611
+ e.onError(t);
612
+ let r = this.queryWaiters.get(n);
613
+ r && (r.reject(t), this.queryWaiters.delete(n));
614
+ }
615
+ async executeQuery(e) {
616
+ let t = this.queryQueue.get(e);
617
+ if (t) try {
618
+ this.queryQueue.delete(e), this.activeQueries.add(e);
619
+ let n = this.getDashboardImports(), r = {
620
+ ...t.queryInput,
621
+ imports: n,
622
+ editorType: "trilogy"
623
+ }, { resultPromise: i } = await this.queryExecutionService.executeQuery(this.connectionName, r, () => {}, (e) => {
624
+ e.error && t.onProgress(e);
625
+ }), a = await i;
626
+ if (a.success && a.results) {
627
+ t.onSuccess(a);
628
+ let n = this.queryWaiters.get(e);
629
+ n && (n.resolve(a), this.queryWaiters.delete(e));
630
+ } else if (a.error) {
631
+ t.onError(a.error);
632
+ let n = this.queryWaiters.get(e);
633
+ n && (n.reject(a.error), this.queryWaiters.delete(e));
634
+ }
635
+ } catch (n) {
636
+ let r = n instanceof Error ? n.message : "Unknown error occurred";
637
+ if (t.retryCount < this.retryAttempts) console.log(`Retrying query ${e} (attempt ${t.retryCount + 1})`), t.retryCount++, t.timestamp = Date.now(), this.queryQueue.set(e, t), setTimeout(() => {
638
+ this.queryQueue.has(e) && this.executeQuery(e);
639
+ }, 1e3 * t.retryCount);
640
+ else {
641
+ t.onError(r);
642
+ let n = this.queryWaiters.get(e);
643
+ n && (n.reject(r), this.queryWaiters.delete(e));
644
+ }
645
+ } finally {
646
+ this.activeQueries.delete(e), this.settleQueryLoading(e), this.cleanupQueryTracking(e), this.processBatch();
647
+ }
648
+ }
649
+ }, N = (e) => e.replace(/\s+/g, "");
650
+ function P(e) {
651
+ if (!e) return;
652
+ let t = te();
653
+ return t.connections[e] || t.connectionByName(e);
654
+ }
655
+ var F = k("dashboards", {
656
+ state: () => ({
657
+ dashboards: {},
658
+ activeDashboardId: "",
659
+ queryExecutors: {},
660
+ pendingChatPrompts: {}
661
+ }),
662
+ getters: {
663
+ dashboardList: (e) => Object.values(e.dashboards),
664
+ activeDashboard: (e) => e.activeDashboardId ? e.dashboards[e.activeDashboardId] : null,
665
+ getConnectionDashboards: (e) => (t) => Object.values(e.dashboards).filter((e) => e.connectionId === t),
666
+ unsavedDashboards: (e) => Object.values(e.dashboards).filter((e) => e.changed).length,
667
+ activeQueryExecutor: (e) => e.activeDashboardId ? e.queryExecutors[e.activeDashboardId] : null,
668
+ hasQueryExecutor: (e) => (t) => !!e.queryExecutors[t]
669
+ },
670
+ actions: {
671
+ getOrCreateQueryExecutor(e, t) {
672
+ if (!this.dashboards[e]) throw Error(`Dashboard with ID "${e}" not found.`);
673
+ if (this.queryExecutors[e]) {
674
+ let n = this.queryExecutors[e];
675
+ return t.connectionName && n.connectionName !== t.connectionName && n.setConnection(t.connectionName), n;
676
+ }
677
+ let n = new M(t.queryExecutionService, t.connectionName, t.dashboardId, t.getDashboardData, t.getItemData, t.setItemData, t.options || {});
678
+ return this.queryExecutors[e] = n, console.log(`Created new query executor for dashboard: ${e}`), n;
679
+ },
680
+ getQueryExecutor(e) {
681
+ return this.queryExecutors[e] || null;
682
+ },
683
+ removeQueryExecutor(e) {
684
+ return this.queryExecutors[e] ? (this.queryExecutors[e].clearQueue(), delete this.queryExecutors[e], console.log(`Removed query executor for dashboard: ${e}`), !0) : !1;
685
+ },
686
+ clearAllQueryExecutors() {
687
+ Object.keys(this.queryExecutors).forEach((e) => {
688
+ this.queryExecutors[e].clearQueue();
689
+ }), this.queryExecutors = {}, console.log("Cleared all query executors");
690
+ },
691
+ getQueryExecutorStatuses() {
692
+ let e = {};
693
+ return Object.entries(this.queryExecutors).forEach(([t, n]) => {
694
+ e[t] = {
695
+ dashboardName: this.dashboards[t]?.name || "Unknown",
696
+ ...n.getStatus()
697
+ };
698
+ }), e;
699
+ },
700
+ getDashboardByName(e) {
701
+ return Object.values(this.dashboards).find((t) => t.name === e) || null;
702
+ },
703
+ newDashboard(e, t) {
704
+ let n = e;
705
+ if (Object.values(this.dashboards).some((t) => t.name === e)) throw Error(`A dashboard with name ${e} already exists.`);
706
+ let r = P(t), i = new s({
707
+ id: n,
708
+ name: e,
709
+ connection: r?.name || t,
710
+ connectionId: r?.id || t,
711
+ storage: "local",
712
+ state: "editing"
713
+ });
714
+ return this.dashboards[n] = i, i;
715
+ },
716
+ newReport(e, t) {
717
+ let n = this.newDashboard(e, t);
718
+ return n.setLayoutType("report"), n;
719
+ },
720
+ cloneDashboard(e) {
721
+ let t = this.dashboards[e];
722
+ if (!t) throw Error(`Dashboard with ID "${e}" not found.`);
723
+ let n = `${t.name} (copy)`, r = 1;
724
+ for (; Object.values(this.dashboards).some((e) => e.name === n);) n = `${t.name} (copy ${r})`, r++;
725
+ let i = new s({
726
+ id: n,
727
+ name: n,
728
+ connection: t.connection,
729
+ connectionId: t.connectionId,
730
+ storage: t.storage,
731
+ state: "editing"
732
+ });
733
+ return i.gridItems = Object.fromEntries(Object.entries(t.gridItems).map(([e, t]) => [e, {
734
+ ...t,
735
+ chartFilters: [],
736
+ conceptFilters: [],
737
+ filters: []
738
+ }])), i.layout = t.layout.map((e) => ({ ...e })), i.imports = t.imports.map((e) => ({ ...e })), i.filter = t.filter, i.description = t.description, i.updatedAt = /* @__PURE__ */ new Date(), i.nextId = t.nextId, i.changed = !0, this.addDashboard(i), this.activeDashboardId = n, i;
739
+ },
740
+ forkDashboard(e, t) {
741
+ let n = this.dashboards[e];
742
+ if (!n) throw Error(`Dashboard with ID "${e}" not found.`);
743
+ let r = `${n.name} / ${t}`, i = 1;
744
+ for (; this.dashboards[r];) r = `${n.name} / ${t} (${i})`, i++;
745
+ let a = new s({
746
+ id: r,
747
+ name: r,
748
+ connection: n.connection,
749
+ connectionId: n.connectionId,
750
+ storage: n.storage,
751
+ state: "editing",
752
+ parentDashboardId: e,
753
+ investigationName: t,
754
+ investigationCreatedFrom: { timestamp: /* @__PURE__ */ new Date() },
755
+ description: n.description
756
+ });
757
+ return a.gridItems = Object.fromEntries(Object.entries(n.gridItems).map(([e, t]) => [e, {
758
+ ...t,
759
+ chartFilters: [],
760
+ conceptFilters: [],
761
+ filters: []
762
+ }])), a.layout = n.layout.map((e) => ({ ...e })), a.imports = n.imports.map((e) => ({ ...e })), a.filter = n.filter, a.nextId = n.nextId, a.changed = !0, n.children ||= [], n.children.push(r), n.changed = !0, this.addDashboard(a), this.activeDashboardId = r, a;
763
+ },
764
+ promoteDashboard(e) {
765
+ let t = this.dashboards[e];
766
+ if (!t) throw Error(`Dashboard with ID "${e}" not found.`);
767
+ if (t.parentDashboardId) {
768
+ let n = this.dashboards[t.parentDashboardId];
769
+ n?.children && (n.children = n.children.filter((t) => t !== e), n.changed = !0);
770
+ }
771
+ return t.parentDashboardId = null, t.investigationName = void 0, t.investigationCreatedFrom = void 0, t.changed = !0, t;
772
+ },
773
+ getInvestigations(e) {
774
+ return Object.values(this.dashboards).filter((t) => t.parentDashboardId === e && !t.deleted);
775
+ },
776
+ getRootDashboards() {
777
+ return Object.values(this.dashboards).filter((e) => !e.parentDashboardId && !e.deleted);
778
+ },
779
+ addDashboard(e) {
780
+ this.dashboards[e.id] = e;
781
+ },
782
+ loadDashboards(e) {
783
+ Object.entries(e).forEach(([e, t]) => {
784
+ this.dashboards[e] = s.fromSerialized(t);
785
+ });
786
+ },
787
+ removeAllFilters(e) {
788
+ if (this.dashboards[e]) return this.dashboards[e].removeAllFilters();
789
+ throw Error(`Dashboard with ID "${e}" not found.`);
790
+ },
791
+ getConnectionDashboardsSync(e) {
792
+ return Object.values(this.dashboards).filter((t) => t.connectionId === e);
793
+ },
794
+ setPendingChatPrompt(e, t) {
795
+ this.pendingChatPrompts[e] = t;
796
+ },
797
+ consumePendingChatPrompt(e) {
798
+ let t = this.pendingChatPrompts[e];
799
+ return t === void 0 ? null : (delete this.pendingChatPrompts[e], t);
800
+ },
801
+ setActiveDashboard(e) {
802
+ if (this.dashboards[e]) this.activeDashboardId = e;
803
+ else throw Error(`Dashboard with ID "${e}" not found.`);
804
+ },
805
+ setDashboardState(e, t) {
806
+ if (this.dashboards[e]) this.dashboards[e].state = t;
807
+ else throw Error(`Dashboard with ID "${e}" not found.`);
808
+ },
809
+ updateDashboardName(e, t) {
810
+ if (this.dashboards[e]) this.dashboards[e].name = t, this.dashboards[e].updatedAt = /* @__PURE__ */ new Date();
811
+ else throw Error(`Dashboard with ID "${e}" not found.`);
812
+ },
813
+ updateDashboardFilter(e, t) {
814
+ if (this.dashboards[e]) {
815
+ let n = this.dashboards[e].filter;
816
+ return (!t || N(t) === "") && (this.dashboards[e].filter = null, n != null) || (this.dashboards[e].filter = t, n !== t) ? Object.entries(this.dashboards[e].gridItems).map(([e, t]) => e) : [];
817
+ }
818
+ throw Error(`Dashboard with ID "${e}" not found.`);
819
+ },
820
+ updateDashboardImports(e, t) {
821
+ if (this.dashboards[e]) this.dashboards[e].imports = t;
822
+ else throw Error(`Dashboard with ID "${e}" not found.`);
823
+ },
824
+ removeDashboard(e) {
825
+ if (this.dashboards[e]) this.removeQueryExecutor(e), delete this.dashboards[e], this.activeDashboardId === e && (this.activeDashboardId = "");
826
+ else throw Error(`Dashboard with ID "${e}" not found.`);
827
+ },
828
+ purgeDeletedDashboards() {
829
+ for (let e of Object.keys(this.dashboards)) this.dashboards[e].deleted && (this.removeQueryExecutor(e), delete this.dashboards[e], this.activeDashboardId === e && (this.activeDashboardId = ""));
830
+ },
831
+ setState(e, t) {
832
+ this.dashboards[e] && (this.dashboards[e].state = t);
833
+ },
834
+ setDashboardLayoutType(e, t) {
835
+ let n = this.dashboards[e];
836
+ if (!n) throw Error(`Dashboard with ID "${e}" not found.`);
837
+ n.setLayoutType(t);
838
+ },
839
+ setDashboardTheme(e, t) {
840
+ let n = this.dashboards[e];
841
+ if (!n) throw Error(`Dashboard with ID "${e}" not found.`);
842
+ n.setTheme(t);
843
+ },
844
+ addItemToDashboard(e, t, n = 0, r = 0, i = 5, a = null, o = null, s = null) {
845
+ if (this.dashboards[e]) return this.dashboards[e].addItem(t, n, r, i, a, o, s);
846
+ throw Error(`Dashboard with ID "${e}" not found.`);
847
+ },
848
+ updateDashboardTitle(e, t) {
849
+ if (this.dashboards[e]) this.dashboards[e].name = t, this.dashboards[e].updatedAt = /* @__PURE__ */ new Date();
850
+ else throw Error(`Dashboard with ID "${e}" not found.`);
851
+ },
852
+ updateItemContent(e, t, n) {
853
+ if (this.dashboards[e]) this.dashboards[e].updateItemContent(t, n);
854
+ else throw Error(`Dashboard with ID "${e}" not found.`);
855
+ },
856
+ updateItemCrossFilterEligibility(e, t, n) {
857
+ if (this.dashboards[e]) this.dashboards[e].updateItemCrossFilterEligibility(t, n);
858
+ else throw Error(`Dashboard with ID "${e}" not found.`);
859
+ },
860
+ updateItemResults(e, t, n) {
861
+ if (this.dashboards[e]) this.dashboards[e].updateItemResults(t, n);
862
+ else throw Error(`Dashboard with ID "${e}" not found.`);
863
+ },
864
+ updateItemLoading(e, t, n) {
865
+ if (this.dashboards[e]) this.dashboards[e].updateItemLoading(t, n);
866
+ else throw Error(`Dashboard with ID "${e}" not found.`);
867
+ },
868
+ updateItemError(e, t, n) {
869
+ if (this.dashboards[e]) this.dashboards[e].updateItemError(t, n);
870
+ else throw Error(`Dashboard with ID "${e}" not found.`);
871
+ },
872
+ updateItemDrilldown(e, t, n) {
873
+ if (this.dashboards[e]) this.dashboards[e].updateItemDrilldown(t, n);
874
+ else throw Error(`Dashboard with ID "${e}" not found.`);
875
+ },
876
+ updateItemDrilldownChartConfig(e, t, n) {
877
+ if (this.dashboards[e]) this.dashboards[e].updateItemDrilldownChartConfig(t, n);
878
+ else throw Error(`Dashboard with ID "${e}" not found.`);
879
+ },
880
+ updateItemType(e, t, n) {
881
+ if (this.dashboards[e]) this.dashboards[e].updateItemType(t, n);
882
+ else throw Error(`Dashboard with ID "${e} not found`);
883
+ },
884
+ updateItemCrossFilters(e, t, n, r, i) {
885
+ if (this.dashboards[e]) return this.dashboards[e].updateItemCrossFilters(t, n, r, i);
886
+ throw Error(`Dashboard with ID "${e}" not found.`);
887
+ },
888
+ removeItemCrossFilter(e, t, n) {
889
+ if (this.dashboards[e]) return this.dashboards[e].removeItemCrossFilter(t, n), t;
890
+ throw Error(`Dashboard with ID "${e}" not found.`);
891
+ },
892
+ removeItemCrossFilterSource(e, t) {
893
+ if (this.dashboards[e]) return this.dashboards[e].removeItemCrossFilterSource(t);
894
+ throw Error(`Dashboard with ID "${e}" not found.`);
895
+ },
896
+ updateItemName(e, t, n) {
897
+ if (this.dashboards[e]) this.dashboards[e].updateItemName(t, n);
898
+ else throw Error(`Dashboard with ID "${e}" not found.`);
899
+ },
900
+ updateItemChartConfig(e, t, n) {
901
+ if (this.dashboards[e]) this.dashboards[e].updateItemChartConfig(t, n);
902
+ else throw Error(`Dashboard with ID "${e}" not found.`);
903
+ },
904
+ updateMultipleItemProperties(e, t, n) {
905
+ if (!this.dashboards[e]) throw Error(`Dashboard with ID "${e}" not found.`);
906
+ this.dashboards[e].updateItemMultipleProperties(t, n);
907
+ },
908
+ updateDashboardConnection(e, t) {
909
+ if (this.dashboards[e]) {
910
+ let n = P(t);
911
+ this.dashboards[e].connection = n?.name || t, this.dashboards[e].connectionId = n?.id || t, this.dashboards[e].changed = !0;
912
+ } else throw Error(`Dashboard with ID "${e}" not found.`);
913
+ },
914
+ updateDashboardDescription(e, t) {
915
+ if (this.dashboards[e]) this.dashboards[e].description = t;
916
+ else throw Error(`Dashboard with ID "${e}" not found.`);
917
+ },
918
+ updateDashboardLayout(e, t) {
919
+ if (this.dashboards[e]) this.dashboards[e].updateLayout(t);
920
+ else throw Error(`Dashboard with ID "${e}" not found.`);
921
+ },
922
+ updateItemDimensions(e, t, n, r) {
923
+ if (this.dashboards[e]) this.dashboards[e].updateItemDimensions(t, n, r);
924
+ else throw Error(`Dashboard with ID "${e}" not found.`);
925
+ },
926
+ updateItemLayoutDimensions(e, t, n = null, r = null, i = null, a = null) {
927
+ if (this.dashboards[e]) this.dashboards[e].updateItemLayoutDimensions(t, n, r, i, a);
928
+ else throw Error(`Dashboard with ID "${e}" not found.`);
929
+ },
930
+ removeItemFromDashboard(e, t) {
931
+ if (this.dashboards[e]) this.dashboards[e].removeItem(t);
932
+ else throw Error(`Dashboard with ID "${e}" not found.`);
933
+ },
934
+ copyItemInDashboard(e, t) {
935
+ if (this.dashboards[e]) return this.dashboards[e].copyItem(t);
936
+ throw Error(`Dashboard with ID "${e}" not found.`);
937
+ },
938
+ clearDashboardItems(e) {
939
+ if (this.dashboards[e]) this.dashboards[e].clearItems();
940
+ else throw Error(`Dashboard with ID "${e}" not found.`);
941
+ },
942
+ serializeDashboards() {
943
+ let e = {};
944
+ return Object.entries(this.dashboards).forEach(([t, n]) => {
945
+ n.storage === "local" && (e[t] = n.serialize());
946
+ }), e;
947
+ },
948
+ async warmDashboardQueries(e, t, n) {
949
+ let r = this.dashboards[e];
950
+ if (r) {
951
+ for (let e of Object.values(r.gridItems)) if (e.type === a.CHART || e.type === a.TABLE) {
952
+ let i = typeof e.content == "string" ? e.content : e.content?.query || "";
953
+ await t?.generateQuery(r.connectionId || r.connection, {
954
+ text: i,
955
+ editorType: "trilogy",
956
+ imports: r.imports,
957
+ extraContent: r.imports.map((e) => ({
958
+ alias: e.name,
959
+ contents: n.editors[e.id]?.contents || n.editors[e.name]?.contents || ""
960
+ }))
961
+ });
962
+ }
963
+ }
964
+ },
965
+ async populateCompletion(e, t, n) {
966
+ let r = this.dashboards[e];
967
+ if (r) {
968
+ let i = await t?.validateQuery(r.connectionId || r.connection, {
969
+ text: "select 1 as test;",
970
+ editorType: "trilogy",
971
+ imports: r.imports,
972
+ extraContent: r.imports.map((e) => ({
973
+ alias: e.name,
974
+ contents: n.editors[e.id]?.contents || n.editors[e.name]?.contents || ""
975
+ }))
976
+ });
977
+ return i ? i.data.completion_items : (console.log(`No results returned from validateQuery for dashboard ID "${e}".`), []);
978
+ }
979
+ throw Error(`Dashboard with ID "${e}" not found.`);
980
+ },
981
+ async populateAIConcepts(e, t, n) {
982
+ let r = await this.populateCompletion(e, t, n);
983
+ if (!r) throw Error(`No completion items found for dashboard ID "${e}".`);
984
+ return m(r);
985
+ },
986
+ async generatePromptSpec(e, t, n, r) {
987
+ let i = await this.populateAIConcepts(this.activeDashboardId, n, r), a = await t.generateDashboardCompletion(e, d, i, 3);
988
+ if (!a) throw Error("No response from LLM");
989
+ return d(a);
990
+ },
991
+ async populateFromPromptSpec(e, t, n, r, i) {
992
+ let o = this.dashboards[e];
993
+ if (!o) throw Error(`Dashboard with ID "${e}" not found.`);
994
+ o.name = t.name, o.description = t.description;
995
+ let s = await this.populateAIConcepts(e, r, i);
996
+ if (!s) throw Error(`No completion items found for dashboard ID "${e}".`);
997
+ let c = async (e) => {
998
+ let t = {
999
+ text: e,
1000
+ editorType: "trilogy",
1001
+ imports: o.imports,
1002
+ extraContent: o.imports.map((e) => ({
1003
+ alias: e.name,
1004
+ contents: i.editors[e.id]?.contents || i.editors[e.name]?.contents || ""
1005
+ }))
1006
+ };
1007
+ return await (await r.executeQuery(o.connectionId || o.connection, t, () => {}, () => {}, (e) => {
1008
+ throw e;
1009
+ }, () => !0, !0)).resultPromise, !0;
1010
+ }, l = /* @__PURE__ */ new Map();
1011
+ for (let n of t.layout) {
1012
+ let r = t.gridItems[n.id], i = r.content, o = r.type.toLowerCase();
1013
+ [a.CHART, a.TABLE].includes(o) && (i = `Placeholder, prompt: ${i}`);
1014
+ let s = this.addItemToDashboard(e, "markdown", n.x, n.y, n.w, n.h, i, r.name);
1015
+ l.set(s, {
1016
+ type: o,
1017
+ content: i
1018
+ });
1019
+ }
1020
+ for (let t of l) {
1021
+ let r = t[0], i = t[1], o = i.content;
1022
+ [a.CHART, a.TABLE].includes(i.type) && (o = (await n.generateQueryCompletion(i.content, s, c)).content || "No query could be generated"), await this.updateItemContent(e, r, o), await this.updateItemType(e, r, i.type);
1023
+ }
1024
+ }
1025
+ }
1026
+ }), I = /* @__PURE__ */ new Map(), L = "trilogy-jobs-api-state", R = (e, t, n) => `${e}::${n}::${t}`, z = (e, t) => `${e}::${t}`, he = (e) => {
1027
+ let t = e.pollingState, n = t === "unable-to-fetch" ? "stopped" : e.pollingState ?? "ok";
1028
+ return {
1029
+ ...e,
1030
+ pollingState: n,
1031
+ pollingError: n === "stopped" && !e.pollingError && t === "unable-to-fetch" ? "Polling stopped locally." : e.pollingError ?? null
1032
+ };
1033
+ }, ge = (e) => {
1034
+ let t = e instanceof Error ? e.message : "Failed to fetch state";
1035
+ return e instanceof S ? e.status === 401 ? "Authentication required. Set this store’s token to read state." : e.status === 400 && /directory/i.test(t) ? `${t} Directory state requires a Trilogy server on 0.3.306 or newer.` : t : t;
1036
+ }, B = (e) => [...e].sort((e, t) => t.submittedAt - e.submittedAt), _e = k("jobsApi", {
1037
+ state: () => ({
1038
+ filesByStore: {},
1039
+ jobsByStore: {},
1040
+ errors: {},
1041
+ storeStatus: {},
1042
+ loadingByStore: {},
1043
+ submittingByTarget: {},
1044
+ pollingByJob: {},
1045
+ stoppingByJob: {},
1046
+ stateByTarget: {},
1047
+ stateLoadingByTarget: {},
1048
+ stateErrorsByTarget: {}
1049
+ }),
1050
+ actions: {
1051
+ getGenericStore(e) {
1052
+ let t = _().stores.find((t) => t.id === e);
1053
+ return !t || t.type !== "generic" ? null : t;
1054
+ },
1055
+ getGenericStores() {
1056
+ return _().stores.filter((e) => e.type === "generic");
1057
+ },
1058
+ getStoreJobs(e) {
1059
+ return B(this.jobsByStore[e] || []);
1060
+ },
1061
+ getJobsForTarget(e, t) {
1062
+ return this.getStoreJobs(e).filter((e) => e.target === t);
1063
+ },
1064
+ getStoreStatus(e) {
1065
+ return (this.jobsByStore[e] || []).some((e) => e.status === "running" && (e.pollingState ?? "ok") === "ok") ? "running" : this.storeStatus[e] || "idle";
1066
+ },
1067
+ isSubmitting(e, t, n) {
1068
+ return !!this.submittingByTarget[R(e, t, n)];
1069
+ },
1070
+ getState(e, t) {
1071
+ return this.stateByTarget[T(e, t)]?.snapshot || null;
1072
+ },
1073
+ getStateMeta(e, t) {
1074
+ let n = this.stateByTarget[T(e, t)];
1075
+ return n ? {
1076
+ cached: n.cached,
1077
+ computedAt: n.computedAt
1078
+ } : null;
1079
+ },
1080
+ isStateLoading(e, t) {
1081
+ return !!this.stateLoadingByTarget[T(e, t)];
1082
+ },
1083
+ getStateError(e, t) {
1084
+ return this.stateErrorsByTarget[T(e, t)] || "";
1085
+ },
1086
+ isPollingJob(e, t) {
1087
+ return !!this.pollingByJob[z(e, t)];
1088
+ },
1089
+ isStoppingJob(e, t) {
1090
+ return !!this.stoppingByJob[z(e, t)];
1091
+ },
1092
+ clearStoreError(e) {
1093
+ delete this.errors[e], this.storeStatus[e] = "idle";
1094
+ },
1095
+ clearStoreData(e) {
1096
+ Array.from(I.keys()).filter((t) => t.startsWith(`${e}:`)).forEach((e) => {
1097
+ let t = I.get(e);
1098
+ t && clearInterval(t), I.delete(e);
1099
+ }), delete this.filesByStore[e], delete this.jobsByStore[e], delete this.errors[e], delete this.storeStatus[e], delete this.loadingByStore[e], this.clearStateForStore(e), this.saveJobsToStorage();
1100
+ },
1101
+ clearStateForStore(e) {
1102
+ let t = (t) => y(t)?.storeId === e, n = (e) => {
1103
+ Object.keys(e).filter(t).forEach((t) => delete e[t]);
1104
+ };
1105
+ n(this.stateByTarget), n(this.stateLoadingByTarget), n(this.stateErrorsByTarget);
1106
+ },
1107
+ clearStateError(e, t) {
1108
+ delete this.stateErrorsByTarget[T(e, t)];
1109
+ },
1110
+ refreshLoadedStateForTarget(e, t) {
1111
+ Object.keys(this.stateByTarget).forEach((n) => {
1112
+ let r = y(n);
1113
+ r && r.storeId === e && re(r.target, t) && this.fetchStateForTarget(e, r.target);
1114
+ });
1115
+ },
1116
+ async fetchStateForTarget(e, t, n = !1) {
1117
+ let r = this.getGenericStore(e);
1118
+ if (!r) return;
1119
+ let i = T(e, t);
1120
+ if (!this.stateLoadingByTarget[i]) {
1121
+ this.stateLoadingByTarget[i] = !0, delete this.stateErrorsByTarget[i];
1122
+ try {
1123
+ let e = await x(r, t, n);
1124
+ this.stateByTarget[i] = {
1125
+ snapshot: e.snapshot,
1126
+ cached: e.cached,
1127
+ computedAt: e.computedAt
1128
+ };
1129
+ } catch (e) {
1130
+ this.stateErrorsByTarget[i] = ge(e);
1131
+ } finally {
1132
+ delete this.stateLoadingByTarget[i];
1133
+ }
1134
+ }
1135
+ },
1136
+ async initialize() {
1137
+ _().loadStoresFromStorage(), this.loadJobsFromStorage(), this.resumePolling(), await this.refreshAllStores();
1138
+ },
1139
+ saveJobsToStorage() {
1140
+ try {
1141
+ localStorage.setItem(L, JSON.stringify(this.jobsByStore));
1142
+ } catch (e) {
1143
+ console.error("Error saving jobs to localStorage:", e);
1144
+ }
1145
+ },
1146
+ loadJobsFromStorage() {
1147
+ try {
1148
+ let e = localStorage.getItem(L);
1149
+ if (!e) return;
1150
+ let t = JSON.parse(e);
1151
+ this.jobsByStore = Object.fromEntries(Object.entries(t).map(([e, t]) => [e, (t || []).map((e) => he(e))]));
1152
+ } catch (e) {
1153
+ console.error("Error loading jobs from localStorage:", e);
1154
+ }
1155
+ },
1156
+ resumePolling() {
1157
+ Object.entries(this.jobsByStore).forEach(([e, t]) => {
1158
+ t.forEach((t) => {
1159
+ t.status === "running" && (t.pollingState ?? "ok") === "ok" && this.startPolling(e, t.job_id);
1160
+ });
1161
+ });
1162
+ },
1163
+ async resumeAuthPausedJobs(e) {
1164
+ let t = (this.jobsByStore[e] || []).filter((e) => e.status === "running" && e.pollingState === "auth-paused");
1165
+ await Promise.all(t.map(async (t) => {
1166
+ let n = {
1167
+ ...t,
1168
+ updatedAt: Date.now(),
1169
+ pollingState: "ok",
1170
+ pollingError: null
1171
+ };
1172
+ this.upsertJob(e, n), this.startPolling(e, t.job_id), await this.pollJob(e, t.job_id);
1173
+ }));
1174
+ },
1175
+ async refreshAllStores() {
1176
+ let e = this.getGenericStores();
1177
+ await Promise.all(e.map((e) => this.fetchFilesForStore(e.id)));
1178
+ },
1179
+ async fetchFilesForStore(e) {
1180
+ let t = this.getGenericStore(e);
1181
+ if (t) {
1182
+ this.loadingByStore[e] = !0, this.storeStatus[e] = "idle";
1183
+ try {
1184
+ this.filesByStore[e] = await v(t), delete this.errors[e], this.storeStatus[e] = "connected";
1185
+ } catch (t) {
1186
+ let n = t instanceof Error ? t.message : "Failed to fetch files";
1187
+ this.errors[e] = n, this.storeStatus[e] = "failed";
1188
+ } finally {
1189
+ this.loadingByStore[e] = !1;
1190
+ }
1191
+ }
1192
+ },
1193
+ upsertJob(e, t) {
1194
+ let n = this.jobsByStore[e] || [], r = n.findIndex((e) => e.job_id === t.job_id);
1195
+ if (r === -1) {
1196
+ this.jobsByStore[e] = B([t, ...n]), this.saveJobsToStorage();
1197
+ return;
1198
+ }
1199
+ let i = [...n];
1200
+ i[r] = {
1201
+ ...i[r],
1202
+ ...t
1203
+ }, this.jobsByStore[e] = B(i), this.saveJobsToStorage();
1204
+ },
1205
+ replaceJobs(e, t) {
1206
+ this.jobsByStore[e] = B(t), this.saveJobsToStorage();
1207
+ },
1208
+ removeJob(e, t) {
1209
+ this.stopPolling(e, t), delete this.pollingByJob[z(e, t)], delete this.stoppingByJob[z(e, t)], this.jobsByStore[e] = (this.jobsByStore[e] || []).filter((e) => e.job_id !== t), this.saveJobsToStorage();
1210
+ },
1211
+ stopPolling(e, t) {
1212
+ let n = `${e}:${t}`, r = I.get(n);
1213
+ r && (clearInterval(r), I.delete(n));
1214
+ },
1215
+ pauseJobPolling(e, t, n, r) {
1216
+ let i = (this.jobsByStore[e] || []).find((e) => e.job_id === t);
1217
+ if (!i) {
1218
+ this.stopPolling(e, t);
1219
+ return;
1220
+ }
1221
+ this.stopPolling(e, t);
1222
+ let a = {
1223
+ ...i,
1224
+ updatedAt: Date.now(),
1225
+ pollingState: n,
1226
+ pollingError: r
1227
+ };
1228
+ this.upsertJob(e, a);
1229
+ },
1230
+ startPolling(e, t) {
1231
+ this.stopPolling(e, t);
1232
+ let n = `${e}:${t}`, r = setInterval(() => {
1233
+ this.pollJob(e, t);
1234
+ }, 1e3);
1235
+ I.set(n, r);
1236
+ },
1237
+ buildLocalJob(e, t, n, r, i) {
1238
+ let a = Date.now();
1239
+ return {
1240
+ ...r,
1241
+ storeId: e,
1242
+ target: t,
1243
+ operation: n,
1244
+ submittedAt: i || a,
1245
+ updatedAt: a,
1246
+ pollingState: "ok",
1247
+ pollingError: null
1248
+ };
1249
+ },
1250
+ async submitJob(e, t, n) {
1251
+ let r = this.getGenericStore(e);
1252
+ if (!r) throw Error("Store not found or does not support jobs");
1253
+ let i = R(e, t, n);
1254
+ this.submittingByTarget[i] = !0;
1255
+ try {
1256
+ let i = await ee(r, n, t), a = this.buildLocalJob(e, t, n, i);
1257
+ return this.upsertJob(e, a), delete this.errors[e], this.storeStatus[e] = "connected", a.status === "running" && this.startPolling(e, a.job_id), a;
1258
+ } catch (r) {
1259
+ let i = r instanceof Error ? r.message : `Failed to ${n} ${t}`;
1260
+ throw this.errors[e] = i, this.storeStatus[e] = "failed", r;
1261
+ } finally {
1262
+ delete this.submittingByTarget[i];
1263
+ }
1264
+ },
1265
+ async pollJob(e, t) {
1266
+ let n = z(e, t);
1267
+ if (this.pollingByJob[n]) return;
1268
+ this.pollingByJob[n] = !0;
1269
+ let r = this.getGenericStore(e), i = (this.jobsByStore[e] || []).find((e) => e.job_id === t);
1270
+ if (!r || !i) {
1271
+ this.stopPolling(e, t), delete this.pollingByJob[n];
1272
+ return;
1273
+ }
1274
+ try {
1275
+ let n = await b(r, t), a = this.buildLocalJob(e, i.target, i.operation, n, i.submittedAt);
1276
+ this.upsertJob(e, a), a.status !== "running" && (this.stopPolling(e, t), this.fetchFilesForStore(e), this.refreshLoadedStateForTarget(e, a.target));
1277
+ } catch (n) {
1278
+ let r = n instanceof Error ? n.message : `Failed to poll job ${t}`;
1279
+ n instanceof S && n.status === 401 ? this.pauseJobPolling(e, t, "auth-paused", "Polling paused: authentication required. Update the store token to resume tracking.") : n instanceof S && n.status === 404 ? this.pauseJobPolling(e, t, "not-found", "Polling stopped: job was not found on the server.") : this.pauseJobPolling(e, t, "stopped", `Polling stopped locally. ${r}`);
1280
+ } finally {
1281
+ delete this.pollingByJob[n];
1282
+ }
1283
+ },
1284
+ async stopJob(e, t) {
1285
+ let n = z(e, t);
1286
+ if (this.stoppingByJob[n]) return;
1287
+ let r = this.getGenericStore(e), i = (this.jobsByStore[e] || []).find((e) => e.job_id === t);
1288
+ if (!r || !i) {
1289
+ this.stopPolling(e, t);
1290
+ return;
1291
+ }
1292
+ this.stoppingByJob[n] = !0, this.stopPolling(e, t), delete this.pollingByJob[n];
1293
+ try {
1294
+ let n = await C(r, t), a = this.buildLocalJob(e, i.target, i.operation, n, i.submittedAt);
1295
+ a.status === "running" && (a.pollingState = "stopped", a.pollingError = "Cancel requested. Polling stopped locally."), this.upsertJob(e, a);
1296
+ } catch (n) {
1297
+ let r = n instanceof Error ? n.message : `Failed to cancel job ${t}`, a = {
1298
+ ...i,
1299
+ updatedAt: Date.now(),
1300
+ pollingState: "stopped",
1301
+ pollingError: `Stopped polling locally. ${r}`
1302
+ };
1303
+ this.upsertJob(e, a);
1304
+ } finally {
1305
+ delete this.stoppingByJob[n];
1306
+ }
1307
+ }
1308
+ }
1309
+ }), ve = k("projects", {
1310
+ state: () => ({
1311
+ projects: {},
1312
+ activeProjectId: ""
1313
+ }),
1314
+ getters: {
1315
+ projectList: (e) => Object.values(e.projects).filter((e) => !e.deleted),
1316
+ unsavedProjects: (e) => Object.values(e.projects).filter((e) => e.changed && !e.deleted).length,
1317
+ activeProject: (e) => e.activeProjectId && e.projects[e.activeProjectId] || null,
1318
+ getProjectById: (e) => (t) => e.projects[t] || null
1319
+ },
1320
+ actions: {
1321
+ newProject(e, t = "") {
1322
+ let n = new A({
1323
+ name: e || `Project ${(/* @__PURE__ */ new Date()).toLocaleDateString()}`,
1324
+ description: t
1325
+ });
1326
+ return this.projects[n.id] = n, this.activeProjectId = n.id, n;
1327
+ },
1328
+ addProject(e) {
1329
+ this.projects[e.id] = e;
1330
+ },
1331
+ removeProject(e) {
1332
+ let t = this.projects[e];
1333
+ t && (t.deleted = !0, t.changed = !0, this.activeProjectId === e && (this.activeProjectId = ""));
1334
+ },
1335
+ setActiveProject(e) {
1336
+ this.projects[e] && !this.projects[e].deleted && (this.activeProjectId = e);
1337
+ },
1338
+ clearActiveProject() {
1339
+ this.activeProjectId = "";
1340
+ },
1341
+ renameProject(e, t) {
1342
+ this.projects[e]?.setName(t);
1343
+ },
1344
+ setProjectDescription(e, t) {
1345
+ this.projects[e]?.setDescription(t);
1346
+ },
1347
+ setProjectDataConnection(e, t) {
1348
+ let n = this.projects[e];
1349
+ n && n.dataConnectionId !== t && (n.dataConnectionId = t, n.updatedAt = /* @__PURE__ */ new Date(), n.changed = !0);
1350
+ },
1351
+ setProjectLLMConnection(e, t) {
1352
+ let n = this.projects[e];
1353
+ n && n.llmConnectionName !== t && (n.llmConnectionName = t, n.updatedAt = /* @__PURE__ */ new Date(), n.changed = !0);
1354
+ },
1355
+ setProjectDirectory(e, t) {
1356
+ this.projects[e]?.setDirectoryPath(t);
1357
+ },
1358
+ addSubchatToProject(e, t) {
1359
+ return this.projects[e]?.addSubchat(t) ?? !1;
1360
+ },
1361
+ removeSubchatFromProject(e, t) {
1362
+ return this.projects[e]?.removeSubchat(t) ?? !1;
1363
+ },
1364
+ addEditorToProject(e, t) {
1365
+ return this.projects[e]?.addEditor(t) ?? !1;
1366
+ },
1367
+ removeEditorFromProject(e, t) {
1368
+ return this.projects[e]?.removeEditor(t) ?? !1;
1369
+ },
1370
+ addDashboardToProject(e, t) {
1371
+ return this.projects[e]?.addDashboard(t) ?? !1;
1372
+ },
1373
+ removeDashboardFromProject(e, t) {
1374
+ return this.projects[e]?.removeDashboard(t) ?? !1;
1375
+ },
1376
+ setProjectPromptOverride(e, t, n) {
1377
+ this.projects[e]?.setPromptOverride(t, n);
1378
+ },
1379
+ setProjects(e) {
1380
+ if (this.projects = e, !this.activeProjectId) {
1381
+ let t = Object.values(e).find((e) => !e.deleted);
1382
+ t && (this.activeProjectId = t.id);
1383
+ }
1384
+ }
1385
+ }
1386
+ }), V = {
1387
+ SCREEN: "screen",
1388
+ SIDEBAR_SCREEN: "sidebarScreen",
1389
+ EDITORS: "editors",
1390
+ DASHBOARD: "dashboard",
1391
+ CONNECTIONS: "connections",
1392
+ LLMS: "llms",
1393
+ TUTORIAL: "tutorial",
1394
+ MODELS: "models",
1395
+ JOBS: "jobs",
1396
+ COMMUNITY_MODELS: "community-models",
1397
+ DASHBOARD_IMPORT: "dashboard-import",
1398
+ ASSET_IMPORT: "asset-import",
1399
+ WELCOME: "welcome",
1400
+ SETTINGS: "settings",
1401
+ PROFILE: "profile",
1402
+ ACTIVE_EDITOR_TAB: "activeEditorTab",
1403
+ CHAT_PANEL: "chatPanel",
1404
+ DEMO: "demo",
1405
+ SKIP_TIPS: "skipTips",
1406
+ INITIAL_SEARCH: "initialSearch",
1407
+ IMPORT: "import",
1408
+ STORE: "store",
1409
+ STORE_ID: "storeId",
1410
+ STORE_KIND: "kind",
1411
+ TOKEN: "token",
1412
+ REMOTE: "remote",
1413
+ ASSET_TYPE: "assetType",
1414
+ ASSET_NAME: "assetName",
1415
+ MODEL_NAME: "modelName",
1416
+ CONNECTION: "connection"
1417
+ };
1418
+ function H(e, t = null) {
1419
+ let n = window.location.hash;
1420
+ if (!n || !n.startsWith("#")) return t;
1421
+ let r = new URLSearchParams(n.slice(1)).get(e);
1422
+ return r === null ? t : r;
1423
+ }
1424
+ function U(e, t) {
1425
+ let n = window.location.hash, r = new URLSearchParams(n.slice(1));
1426
+ r.set(e, t), window.location.hash = `#${r.toString()}`;
1427
+ }
1428
+ function W(e) {
1429
+ let t = window.location.hash, n = new URLSearchParams(t.slice(1));
1430
+ n.delete(e), window.location.hash = `#${n.toString()}`;
1431
+ }
1432
+ function ye(e) {
1433
+ let t = window.location.hash, n = new URLSearchParams(t.slice(1));
1434
+ e.forEach((e) => {
1435
+ n.delete(e);
1436
+ }), window.location.hash = `#${n.toString()}`;
1437
+ }
1438
+ //#endregion
1439
+ //#region stores/useScreenNavigation.ts
1440
+ var be = () => {
1441
+ let e = F(), t = ae(), n = f(), r = _(), i = ne(), a = null, o = {
1442
+ activeScreen: O(H(V.SCREEN, "")),
1443
+ activeSidebarScreen: O(H(V.SIDEBAR_SCREEN, "editors")),
1444
+ activeEditor: O(H(V.EDITORS, "")),
1445
+ activeDashboard: O(H(V.DASHBOARD, "")),
1446
+ activeConnectionKey: O(H(V.CONNECTIONS, "")),
1447
+ activeModelKey: O(H(V.MODELS, "")),
1448
+ activeCommunityModelKey: O(H(V.COMMUNITY_MODELS, "")),
1449
+ activeJobsKey: O(H(V.JOBS, "")),
1450
+ activeLLMConnectionKey: O(H(V.LLMS, "")),
1451
+ activeDocumentationKey: O(H(V.TUTORIAL, "")),
1452
+ modelImport: O(H(V.IMPORT, H(V.MODELS, ""))),
1453
+ connectionImport: O(H(V.CONNECTION, "")),
1454
+ mobileMenuOpen: O(!1),
1455
+ initialSearch: O(H(V.INITIAL_SEARCH, "")),
1456
+ tabs: O([]),
1457
+ activeTab: O(null),
1458
+ showTipModal: O(!0),
1459
+ displayedTips: O([]),
1460
+ fullScreen: O(!1)
1461
+ }, s = /* @__PURE__ */ new Set([
1462
+ "editors",
1463
+ "tutorial",
1464
+ "llms",
1465
+ "jobs",
1466
+ "dashboard",
1467
+ "models",
1468
+ "community-models",
1469
+ "profile",
1470
+ "settings",
1471
+ "connections"
1472
+ ]), c = (e, t = !1) => {
1473
+ if (o.activeSidebarScreen.value !== e && (o.activeSidebarScreen.value = e, !t)) {
1474
+ if (e) {
1475
+ U(V.SIDEBAR_SCREEN, e);
1476
+ return;
1477
+ }
1478
+ W(V.SIDEBAR_SCREEN);
1479
+ }
1480
+ }, l = (e, t = !1) => {
1481
+ s.has(e) && c(e, t);
1482
+ }, u = (n, a, o) => {
1483
+ if (a) return a;
1484
+ if (n === "dashboard") {
1485
+ let t = e.dashboards[o];
1486
+ if (t) return t.name || "Untitled Dashboard";
1487
+ } else if (n === "editors") {
1488
+ let e = t.editors[o];
1489
+ if (e) return e.name || "Untitled Editor";
1490
+ } else if (n === "llms") {
1491
+ let e = o.split("+"), t = e[0], n = e.length > 1 ? e[1] : null;
1492
+ if (n) {
1493
+ let e = i.getChatById(n);
1494
+ if (e) return e.name;
1495
+ }
1496
+ return t || "LLM Chat";
1497
+ } else if (n === "community-models") {
1498
+ let e = o.split("+"), t = e[0], n = r.stores.find((e) => e.id === t);
1499
+ if (n) return e.length === 2 ? `${n.name} - ${e[1]}` : e.length === 3 ? e[2] : n.name;
1500
+ } else if (n === "jobs") {
1501
+ let e = o.split("+"), t = e[0], n = r.stores.find((e) => e.id === t)?.name || t;
1502
+ if (e.length === 1) return n;
1503
+ let i = decodeURIComponent(e[2] || "");
1504
+ if (e[1] === "directory") return i === "__root__" ? `${n} - Root` : i;
1505
+ if (e[1] === "file") {
1506
+ let e = i.split("/");
1507
+ return e[e.length - 1] || n;
1508
+ }
1509
+ }
1510
+ return oe(o, null);
1511
+ }, d = (e, t, n) => {
1512
+ let r = o.tabs.value.find((t) => t.screen === e && t.address === n);
1513
+ r && (r.title = u(e, t, n));
1514
+ }, p = (e, t, n, r = !1) => {
1515
+ let i = o.tabs.value.find((t) => t.screen === e && t.address === n);
1516
+ if (i) {
1517
+ y(i.id, r);
1518
+ return;
1519
+ }
1520
+ let a = o.tabs.value.reduce((e, t) => {
1521
+ let n = parseInt(t.id.replace("tab-", ""));
1522
+ return isNaN(n) ? e : Math.max(e, n);
1523
+ }, 0);
1524
+ r || b(e);
1525
+ let s = u(e, t, n), c = {
1526
+ id: `tab-${++a}`,
1527
+ title: s,
1528
+ screen: e,
1529
+ address: n
1530
+ };
1531
+ o.tabs.value.push(c), y(c.id, r);
1532
+ }, m = (e, t = null) => {
1533
+ if (!e && !t) return;
1534
+ if (!e && t) {
1535
+ let n = o.tabs.value.find((e) => e.address === t);
1536
+ if (n) e = n.id;
1537
+ else return;
1538
+ }
1539
+ let n = o.tabs.value.findIndex((t) => t.id === e);
1540
+ if (n !== -1) {
1541
+ let t = o.activeTab.value === e;
1542
+ if (o.tabs.value.splice(n, 1), t) {
1543
+ if (o.tabs.value.length > 0) {
1544
+ let e = n > 0 ? n - 1 : 0;
1545
+ y(o.tabs.value[e].id);
1546
+ } else p("welcome", "Welcome", "welcome");
1547
+ }
1548
+ }
1549
+ g();
1550
+ }, h = (e) => {
1551
+ let t = o.activeTab.value === e;
1552
+ o.tabs.value = o.tabs.value.filter((t) => t.id === e), t || (o.tabs.value.length > 0 ? y(o.tabs.value[0].id) : p("welcome", "Welcome", "welcome")), g();
1553
+ }, g = () => {
1554
+ let e = o.tabs.value.map((e) => e.screen), t = [];
1555
+ e.includes("editors") || (o.activeEditor.value = "", t.push(V.EDITORS), t.push(V.ACTIVE_EDITOR_TAB)), e.includes("dashboard") || (o.activeDashboard.value = "", t.push(V.DASHBOARD)), e.includes("connections") || (o.activeConnectionKey.value = "", t.push(V.CONNECTIONS)), e.includes("models") || (o.activeModelKey.value = "", t.push(V.MODELS)), e.includes("community-models") || (o.activeCommunityModelKey.value = "", t.push(V.COMMUNITY_MODELS)), e.includes("jobs") || (o.activeJobsKey.value = "", t.push(V.JOBS)), e.includes("tutorial") || (o.activeDocumentationKey.value = "", t.push(V.TUTORIAL)), e.includes("llms") || (o.activeLLMConnectionKey.value = "", t.push(V.LLMS)), e.includes("settings") || t.push(V.SETTINGS), e.includes("profile") || t.push(V.PROFILE), e.includes("welcome") || t.push(V.WELCOME), ye(t);
1556
+ }, v = (e) => {
1557
+ let t = o.tabs.value.findIndex((t) => t.id === e);
1558
+ if (t !== -1) {
1559
+ let e = o.tabs.value.findIndex((e) => e.id === o.activeTab.value) > t;
1560
+ o.tabs.value.splice(t + 1), e && (o.tabs.value.length > 0 ? y(o.tabs.value[o.tabs.value.length - 1].id) : p("welcome", "Welcome", "welcome"));
1561
+ }
1562
+ g();
1563
+ }, y = (r, a = !1) => {
1564
+ let s = o.tabs.value.find((e) => e.id === r);
1565
+ if (s) {
1566
+ o.activeTab.value = r, b(s.screen), l(s.screen, a);
1567
+ let c = n.getUnreadTips(ce);
1568
+ if (s.screen === "editors") o.activeEditor.value = s.address, t.activeEditorId = s.address, c = c.concat(n.getUnreadTips(le));
1569
+ else if (s.screen === "dashboard") o.activeDashboard.value = s.address, e.activeDashboardId = s.address, c = o.fullScreen.value ? [] : c.concat(n.getUnreadTips(ue));
1570
+ else if (s.screen === "connections") o.activeConnectionKey.value = s.address;
1571
+ else if (s.screen === "llms") {
1572
+ o.activeLLMConnectionKey.value = s.address;
1573
+ let e = s.address.split("+");
1574
+ if (e.length > 1) {
1575
+ let t = e[1];
1576
+ i.setActiveChat(t);
1577
+ }
1578
+ } else s.screen === "tutorial" ? o.activeDocumentationKey.value = s.address : s.screen === "models" ? o.activeModelKey.value = s.address : s.screen === "dashboard-import" || s.screen === "asset-import" ? c = [] : s.screen === "community-models" ? (o.activeCommunityModelKey.value = s.address, c = c.concat(n.getUnreadTips(de))) : s.screen === "jobs" && (o.activeJobsKey.value = s.address);
1579
+ o.mobileMenuOpen.value = !1, o.displayedTips.value = c, o.showTipModal.value = c.length > 0, s.address && !a && U(s.screen, s.address);
1580
+ }
1581
+ }, b = (e) => {
1582
+ o.activeScreen.value !== e && (o.activeScreen.value = e, U(V.SCREEN, e));
1583
+ }, x = (e) => {
1584
+ c(e), e == "settings" ? p("settings", "Settings", "settings") : e == "profile" && p("profile", "Profile", "profile");
1585
+ };
1586
+ return {
1587
+ get activeScreen() {
1588
+ return o.activeScreen;
1589
+ },
1590
+ get activeSidebarScreen() {
1591
+ return o.activeSidebarScreen;
1592
+ },
1593
+ get activeEditor() {
1594
+ return o.activeEditor;
1595
+ },
1596
+ get activeDashboard() {
1597
+ return o.activeDashboard;
1598
+ },
1599
+ get activeConnectionKey() {
1600
+ return o.activeConnectionKey;
1601
+ },
1602
+ get activeModelKey() {
1603
+ return o.activeModelKey;
1604
+ },
1605
+ get activeCommunityModelKey() {
1606
+ return o.activeCommunityModelKey;
1607
+ },
1608
+ get activeJobsKey() {
1609
+ return o.activeJobsKey;
1610
+ },
1611
+ get activeDocumentationKey() {
1612
+ return o.activeDocumentationKey;
1613
+ },
1614
+ get activeLLMConnectionKey() {
1615
+ return o.activeLLMConnectionKey;
1616
+ },
1617
+ get modelImport() {
1618
+ return o.modelImport;
1619
+ },
1620
+ get connectionImport() {
1621
+ return o.connectionImport;
1622
+ },
1623
+ get mobileMenuOpen() {
1624
+ return o.mobileMenuOpen;
1625
+ },
1626
+ get initialSearch() {
1627
+ return o.initialSearch;
1628
+ },
1629
+ get tabs() {
1630
+ return o.tabs;
1631
+ },
1632
+ get activeTab() {
1633
+ return o.activeTab;
1634
+ },
1635
+ get showTipModal() {
1636
+ return o.showTipModal;
1637
+ },
1638
+ get displayedTips() {
1639
+ return o.displayedTips;
1640
+ },
1641
+ get fullScreen() {
1642
+ return o.fullScreen;
1643
+ },
1644
+ setActiveScreen: b,
1645
+ setActiveSidebarScreen: x,
1646
+ setActiveEditor: (e) => {
1647
+ if (e === null) {
1648
+ W(V.EDITORS), o.activeEditor.value = "";
1649
+ return;
1650
+ }
1651
+ p("editors", null, e);
1652
+ },
1653
+ setActiveDashboard: (e) => {
1654
+ if (e === null) {
1655
+ W(V.DASHBOARD), o.activeDashboard.value = "";
1656
+ return;
1657
+ }
1658
+ p("dashboard", null, e);
1659
+ },
1660
+ setActiveConnectionKey: (e) => {
1661
+ if (e === null) {
1662
+ W(V.CONNECTIONS), o.activeConnectionKey.value = "";
1663
+ return;
1664
+ }
1665
+ p("connections", null, e);
1666
+ },
1667
+ setActiveDocumentationKey: (e) => {
1668
+ if (e === null) {
1669
+ W(V.TUTORIAL), o.activeDocumentationKey.value = "";
1670
+ return;
1671
+ }
1672
+ let t = e.split("+");
1673
+ p("tutorial", t[t.length - 1], e);
1674
+ },
1675
+ setActiveLLMConnectionKey: (e) => {
1676
+ if (e === null) {
1677
+ W(V.LLMS), o.activeLLMConnectionKey.value = "";
1678
+ return;
1679
+ }
1680
+ p("llms", null, e);
1681
+ },
1682
+ setActiveCommunityModelKey: (e) => {
1683
+ if (e === null) {
1684
+ W(V.COMMUNITY_MODELS), o.activeCommunityModelKey.value = "";
1685
+ return;
1686
+ }
1687
+ o.activeCommunityModelKey.value = e, p("community-models", null, e);
1688
+ },
1689
+ setActiveJobsKey: (e) => {
1690
+ if (e === null) {
1691
+ W(V.JOBS), o.activeJobsKey.value = "";
1692
+ return;
1693
+ }
1694
+ o.activeJobsKey.value = e, p("jobs", null, e);
1695
+ },
1696
+ toggleMobileMenu: () => {
1697
+ o.mobileMenuOpen.value = !o.mobileMenuOpen.value;
1698
+ },
1699
+ setActiveModelKey: (e) => {
1700
+ if (e === null) {
1701
+ W(V.MODELS);
1702
+ return;
1703
+ }
1704
+ U(V.MODELS, e), o.activeModelKey.value = e;
1705
+ },
1706
+ setActiveTab: y,
1707
+ openTab: p,
1708
+ updateTabName: d,
1709
+ closeTab: m,
1710
+ closeOtherTabsExcept: h,
1711
+ closeTabsToRightOf: v,
1712
+ onInitialLoad: () => {
1713
+ let e = o.modelImport.value, t = o.connectionImport.value, r = "editors", i = !1;
1714
+ H(V.SKIP_TIPS, "") === "true" && n.updateSetting("skipAllTips", !0);
1715
+ let a = H(V.ASSET_TYPE, ""), s = H(V.ASSET_NAME, ""), c = H(V.DASHBOARD, ""), l = [
1716
+ "true",
1717
+ "1",
1718
+ "yes"
1719
+ ].includes(H(V.REMOTE, "").toLowerCase()) && !!H(V.STORE, "") && !!(s || c);
1720
+ (e && t || l) && (a && s ? p("asset-import", null, "asset-import") : p("dashboard-import", null, "dashboard-import"), i = !0);
1721
+ let u = o.activeScreen.value, d = o.activeSidebarScreen.value, f = [];
1722
+ o.activeEditor.value && !i && f.push({
1723
+ screen: "editors",
1724
+ title: null,
1725
+ key: o.activeEditor.value,
1726
+ isActive: u === "editors"
1727
+ }), o.activeDashboard.value && !i && f.push({
1728
+ screen: "dashboard",
1729
+ title: null,
1730
+ key: o.activeDashboard.value,
1731
+ isActive: u === "dashboard"
1732
+ }), o.activeConnectionKey.value && !i && f.push({
1733
+ screen: "connections",
1734
+ title: null,
1735
+ key: o.activeConnectionKey.value,
1736
+ isActive: u === "connections"
1737
+ }), o.activeModelKey.value && !i && f.push({
1738
+ screen: "models",
1739
+ title: null,
1740
+ key: o.activeModelKey.value,
1741
+ isActive: u === "models"
1742
+ }), o.activeCommunityModelKey.value && !i && f.push({
1743
+ screen: "community-models",
1744
+ title: null,
1745
+ key: o.activeCommunityModelKey.value,
1746
+ isActive: u === "community-models"
1747
+ }), o.activeJobsKey.value && !i && f.push({
1748
+ screen: "jobs",
1749
+ title: null,
1750
+ key: o.activeJobsKey.value,
1751
+ isActive: u === "jobs"
1752
+ }), o.activeDocumentationKey.value && !i && f.push({
1753
+ screen: "tutorial",
1754
+ title: null,
1755
+ key: o.activeDocumentationKey.value,
1756
+ isActive: u === "tutorial"
1757
+ }), o.activeLLMConnectionKey.value && !i && f.push({
1758
+ screen: "llms",
1759
+ title: null,
1760
+ key: o.activeLLMConnectionKey.value,
1761
+ isActive: u === "llms"
1762
+ }), o.activeSidebarScreen.value === "settings" && f.push({
1763
+ screen: "settings",
1764
+ title: "Settings",
1765
+ key: "settings",
1766
+ isActive: u === "settings"
1767
+ }), o.activeSidebarScreen.value === "profile" && f.push({
1768
+ screen: "profile",
1769
+ title: "Profile",
1770
+ key: "profile",
1771
+ isActive: u === "profile"
1772
+ }), f.sort((e, t) => e.isActive ? 1 : t.isActive ? -1 : 0), f.forEach((e) => {
1773
+ p(e.screen, e.title, e.key, !0);
1774
+ }), b(u), !d && f.length > 0 ? r = f[f.length - 1].screen : d && (r = d), x(r);
1775
+ },
1776
+ toggleFullScreen: (e) => {
1777
+ o.fullScreen.value = e;
1778
+ },
1779
+ addBackListeners: () => {
1780
+ a ||= window.addEventListener("hashchange", () => {
1781
+ let e = H(V.EDITORS, ""), t = H(V.DASHBOARD, ""), n = H(V.CONNECTIONS, ""), r = H(V.MODELS, ""), i = H(V.COMMUNITY_MODELS, ""), a = H(V.JOBS, ""), s = H(V.TUTORIAL, ""), c = H(V.LLMS, ""), l = H(V.SCREEN, ""), u = H(V.SIDEBAR_SCREEN, ""), d = !1;
1782
+ u !== o.activeSidebarScreen.value && x(u), l !== o.activeScreen.value && (o.activeScreen.value = l, d = !0);
1783
+ let f = [
1784
+ {
1785
+ hash: e,
1786
+ screen: "editors",
1787
+ current: o.activeEditor.value
1788
+ },
1789
+ {
1790
+ hash: t,
1791
+ screen: "dashboard",
1792
+ current: o.activeDashboard.value
1793
+ },
1794
+ {
1795
+ hash: n,
1796
+ screen: "connections",
1797
+ current: o.activeConnectionKey.value
1798
+ },
1799
+ {
1800
+ hash: r,
1801
+ screen: "models",
1802
+ current: o.activeModelKey.value
1803
+ },
1804
+ {
1805
+ hash: i,
1806
+ screen: "community-models",
1807
+ current: o.activeCommunityModelKey.value
1808
+ },
1809
+ {
1810
+ hash: a,
1811
+ screen: "jobs",
1812
+ current: o.activeJobsKey.value
1813
+ },
1814
+ {
1815
+ hash: s,
1816
+ screen: "tutorial",
1817
+ current: o.activeDocumentationKey.value
1818
+ },
1819
+ {
1820
+ hash: c,
1821
+ screen: "llms",
1822
+ current: o.activeLLMConnectionKey.value
1823
+ }
1824
+ ];
1825
+ for (let { hash: e, screen: t, current: n } of f) if (e && e !== n || t === l && d) {
1826
+ let n = o.tabs.value.find((n) => n.screen === t && n.screen === l && n.address === e);
1827
+ if (n && n.id !== o.activeTab.value) {
1828
+ y(n.id, !0);
1829
+ break;
1830
+ }
1831
+ if (!n && e) {
1832
+ p(t, null, e);
1833
+ break;
1834
+ }
1835
+ }
1836
+ });
1837
+ },
1838
+ removeBacklisteners: () => {
1839
+ a &&= (window.removeEventListener("hashchange", a), null);
1840
+ }
1841
+ };
1842
+ }, G = null;
1843
+ function xe() {
1844
+ return G ||= be(), G;
1845
+ }
1846
+ //#endregion
1847
+ //#region stores/useMobileSidebarNavigation.ts
1848
+ var Se = () => {
1849
+ let e = O(!1), t = O(""), n = O([]), r = O(!1), i = () => {
1850
+ for (; n.value.length;) n.value.pop()?.onBack();
1851
+ };
1852
+ return {
1853
+ level: D(() => e.value ? "detail" : "root"),
1854
+ title: D(() => e.value ? r.value ? t.value : n.value[n.value.length - 1]?.title || t.value : ""),
1855
+ depth: D(() => n.value.length),
1856
+ canGoBack: D(() => e.value),
1857
+ searchActive: r,
1858
+ enterDestination(n) {
1859
+ i(), t.value = n, e.value = !0;
1860
+ },
1861
+ push(e) {
1862
+ n.value.push(e);
1863
+ },
1864
+ back() {
1865
+ let t = n.value.pop();
1866
+ if (t) {
1867
+ t.onBack();
1868
+ return;
1869
+ }
1870
+ e.value = !1;
1871
+ },
1872
+ home() {
1873
+ i(), e.value = !1;
1874
+ }
1875
+ };
1876
+ }, K = null;
1877
+ function Ce() {
1878
+ return K ||= Se(), K;
1879
+ }
1880
+ //#endregion
1881
+ //#region editors/chartStatement.ts
1882
+ var we = [
1883
+ "line",
1884
+ "bar",
1885
+ "barh",
1886
+ "point",
1887
+ "area",
1888
+ "headline",
1889
+ "donut",
1890
+ "heatmap",
1891
+ "boxplot",
1892
+ "treemap"
1893
+ ], Te = [
1894
+ "linear",
1895
+ "log",
1896
+ "sqrt"
1897
+ ];
1898
+ function q(e) {
1899
+ return Te.includes(e) ? e : void 0;
1900
+ }
1901
+ function J(e) {
1902
+ for (let t of Object.keys(e)) e[t] === void 0 && delete e[t];
1903
+ return e;
1904
+ }
1905
+ function Ee(e, t) {
1906
+ let n = e.x_fields ?? [], r = e.y_fields ?? [], i;
1907
+ e.geo_field ? i = "geo-map" : we.includes(e.chart_type) ? i = e.chart_type : (i = "bar", t.push(`Unknown chart type '${e.chart_type}'; rendering as a bar chart.`));
1908
+ let a = r[0] || n[0], o = a ? e.field_labels?.[a] : void 0;
1909
+ return J({
1910
+ chartType: i,
1911
+ xField: n[0] || void 0,
1912
+ yField: r[0] || void 0,
1913
+ yField2: r[1] || void 0,
1914
+ colorField: e.color_field || void 0,
1915
+ sizeField: e.size_field || void 0,
1916
+ groupField: e.group_field || void 0,
1917
+ trellisField: e.x_trellis_field || void 0,
1918
+ trellisRowField: e.y_trellis_field || void 0,
1919
+ geoField: e.geo_field || void 0,
1920
+ annotationField: e.annotation_field || void 0,
1921
+ layerLabel: o || void 0
1922
+ });
1923
+ }
1924
+ function Y(e) {
1925
+ let t = e?.layers?.[0];
1926
+ if (!e || !t) return null;
1927
+ let n = [], r = J({
1928
+ chartType: "bar",
1929
+ hideLegend: e.hide_legend || void 0,
1930
+ showTitle: e.show_title || void 0,
1931
+ scaleX: q(e.scale_x),
1932
+ scaleY: q(e.scale_y),
1933
+ placements: e.placements?.length ? e.placements.filter((e) => e.kind === "hline" || e.kind === "vline").map((e) => ({
1934
+ kind: e.kind,
1935
+ value: e.value ?? 0,
1936
+ label: e.label || void 0
1937
+ })) : void 0
1938
+ }), i = e.layers.map((e) => Ee(e, n));
1939
+ if (i.length === 1) {
1940
+ let { layerLabel: e, ...t } = i[0];
1941
+ return {
1942
+ config: J({
1943
+ ...r,
1944
+ ...t
1945
+ }),
1946
+ warnings: n
1947
+ };
1948
+ }
1949
+ return {
1950
+ config: J({
1951
+ ...r,
1952
+ chartType: i[0].chartType,
1953
+ layers: i
1954
+ }),
1955
+ warnings: n
1956
+ };
1957
+ }
1958
+ //#endregion
1959
+ //#region stores/connectionHistoryStore.ts
1960
+ var X = null, Z = () => (X ||= new ie(), X);
1961
+ function Q(e) {
1962
+ let t = O([]), n = O(!0), r = O(null), i = async () => {
1963
+ n.value = !0;
1964
+ try {
1965
+ let n = await Z().getQueriesForConnection(e);
1966
+ t.value = n, r.value = null;
1967
+ } catch (e) {
1968
+ console.error("Failed to load query history:", e), r.value = "Failed to load query history";
1969
+ } finally {
1970
+ n.value = !1;
1971
+ }
1972
+ }, a = async (t) => {
1973
+ try {
1974
+ await Z().addQuery(e, t), await i();
1975
+ } catch (e) {
1976
+ console.error("Failed to record query:", e), r.value = "Failed to record query";
1977
+ }
1978
+ };
1979
+ return i(), {
1980
+ history: t,
1981
+ isLoading: n,
1982
+ error: r,
1983
+ recordQuery: a,
1984
+ clearHistory: async () => {
1985
+ n.value = !0;
1986
+ try {
1987
+ await Z().clearConnectionHistory(e), t.value = [], r.value = null;
1988
+ } catch (e) {
1989
+ console.error("Failed to clear query history:", e), r.value = "Failed to clear query history";
1990
+ } finally {
1991
+ n.value = !1;
1992
+ }
1993
+ },
1994
+ executeWithHistory: async (e, t) => {
1995
+ let n = performance.now(), r = "success", i = null, o = 0, s = 0, c = null;
1996
+ try {
1997
+ c = await e(t), c && Array.isArray(c) && (o = c.length, o > 0 && typeof c[0] == "object" && (s = Object.keys(c[0]).length));
1998
+ } catch (e) {
1999
+ throw r = "error", i = e instanceof Error ? e.message : String(e), e;
2000
+ } finally {
2001
+ let e = performance.now() - n;
2002
+ await a({
2003
+ query: t,
2004
+ executionTime: e,
2005
+ status: r,
2006
+ errorMessage: i,
2007
+ resultSize: o,
2008
+ resultColumns: s
2009
+ });
2010
+ }
2011
+ return c;
2012
+ },
2013
+ refreshHistory: i
2014
+ };
2015
+ }
2016
+ //#endregion
2017
+ //#region stores/queryExecutionService.ts
2018
+ var De = class {
2019
+ connection;
2020
+ constructor(e) {
2021
+ this.connection = e;
2022
+ }
2023
+ get name() {
2024
+ return this.connection.name;
2025
+ }
2026
+ get queryType() {
2027
+ return this.connection.query_type;
2028
+ }
2029
+ isConnected() {
2030
+ return this.connection.connected;
2031
+ }
2032
+ executeSql(e, t) {
2033
+ return this.connection.query(e, t ?? null);
2034
+ }
2035
+ runScript(e) {
2036
+ return this.connection.runScript(e);
2037
+ }
2038
+ listRegisteredFiles() {
2039
+ return this.connection.listRegisteredFiles ? this.connection.listRegisteredFiles() : [];
2040
+ }
2041
+ }, $ = class {
2042
+ connectionStore;
2043
+ workingPathResolver;
2044
+ sourcesResolver;
2045
+ filesResolver;
2046
+ constructor(e, t, n, r) {
2047
+ this.connectionStore = e, this.workingPathResolver = t, this.sourcesResolver = n, this.filesResolver = r;
2048
+ }
2049
+ getConnection(e) {
2050
+ let t = this.connectionStore.connections[e];
2051
+ return t ? new De(t) : null;
2052
+ }
2053
+ async ensureConnected(e) {
2054
+ let t = this.connectionStore.connections[e];
2055
+ if (!t) throw Error(`Connection ${e} not found.`);
2056
+ t.connected || await this.connectionStore.resetConnection(e);
2057
+ }
2058
+ getConnectionSources(e) {
2059
+ return this.sourcesResolver ? this.sourcesResolver(e) : this.connectionStore.getConnectionSources(e);
2060
+ }
2061
+ getConnectionWorkingPath(e) {
2062
+ return this.workingPathResolver ? this.workingPathResolver(e) : null;
2063
+ }
2064
+ getConnectionRegisteredFiles(e) {
2065
+ return this.filesResolver ? this.filesResolver(e) : null;
2066
+ }
2067
+ };
2068
+ function Oe(e) {
2069
+ return e.split(";").map((e) => e.trim()).filter((e) => e.length > 0);
2070
+ }
2071
+ function ke(e) {
2072
+ let t = e.trim();
2073
+ for (; t.length > 0;) if (t.startsWith("--")) {
2074
+ let e = t.indexOf("\n");
2075
+ t = e === -1 ? "" : t.slice(e + 1).trimStart();
2076
+ } else if (t.startsWith("/*")) {
2077
+ let e = t.indexOf("*/");
2078
+ t = e === -1 ? "" : t.slice(e + 2).trimStart();
2079
+ } else break;
2080
+ let n = t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase();
2081
+ return n ? [
2082
+ "CREATE",
2083
+ "DROP",
2084
+ "ALTER",
2085
+ "TRUNCATE",
2086
+ "COPY",
2087
+ "SET",
2088
+ "ATTACH",
2089
+ "DETACH",
2090
+ "USE",
2091
+ "BEGIN",
2092
+ "COMMIT",
2093
+ "ROLLBACK",
2094
+ "VACUUM",
2095
+ "ANALYZE",
2096
+ "REINDEX",
2097
+ "CHECKPOINT",
2098
+ "PRAGMA"
2099
+ ].includes(n) : !1;
2100
+ }
2101
+ function Ae(e) {
2102
+ return typeof e.getConnection == "function" && typeof e.ensureConnected == "function";
2103
+ }
2104
+ var je = class {
2105
+ trilogyResolver;
2106
+ connectionProvider;
2107
+ storeHistory;
2108
+ eligibleCrossFilterFieldsCache = /* @__PURE__ */ new Map();
2109
+ constructor(e, t, n = !0) {
2110
+ this.trilogyResolver = e, this.connectionProvider = Ae(t) ? t : new $(t), this.storeHistory = n;
2111
+ }
2112
+ resolveRegisteredFiles(e, t) {
2113
+ return this.connectionProvider.getConnectionRegisteredFiles?.(e) ?? t.listRegisteredFiles();
2114
+ }
2115
+ async executeQueriesBatch(e, t, n, r = [], i, a = {}, o, s, c, l, u = !1, d) {
2116
+ if (n === "python") return {
2117
+ cancellation: {
2118
+ cancel: () => {},
2119
+ isActive: () => !1
2120
+ },
2121
+ resultPromise: Promise.resolve({
2122
+ success: !1,
2123
+ results: [],
2124
+ executionTime: 0
2125
+ })
2126
+ };
2127
+ let f = (/* @__PURE__ */ new Date()).getTime(), p = new AbortController();
2128
+ return {
2129
+ cancellation: {
2130
+ cancel: () => p.abort(),
2131
+ isActive: () => !p.signal.aborted
2132
+ },
2133
+ resultPromise: this.executeQueriesBatchInternal(e, t, n, r, i || [], a, f, p, o, s, c, l, u, d)
2134
+ };
2135
+ }
2136
+ async executeQueriesBatchInternal(e, n, r, i = [], a, o = {}, s, c, l, u, d, f, p = !1, m) {
2137
+ l && l();
2138
+ let h = this.connectionProvider.getConnection(e);
2139
+ if (!h) return {
2140
+ success: !1,
2141
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2142
+ results: n.map((n) => ({
2143
+ success: !1,
2144
+ generated_sql: "",
2145
+ columns: [],
2146
+ error: `Connection ${e} not found.`,
2147
+ executionTime: 0,
2148
+ results: new t(/* @__PURE__ */ new Map(), []),
2149
+ resultSize: 0,
2150
+ columnCount: 0
2151
+ }))
2152
+ };
2153
+ if (p) return {
2154
+ success: !0,
2155
+ results: n.map((e) => ({
2156
+ success: !0,
2157
+ generated_sql: e.query,
2158
+ columns: [],
2159
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2160
+ results: new t(/* @__PURE__ */ new Map(), []),
2161
+ resultSize: 0,
2162
+ columnCount: 0
2163
+ })),
2164
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s
2165
+ };
2166
+ if (!h.isConnected()) try {
2167
+ u && u({
2168
+ message: "Connection is not active... Attempting to automatically reconnect.",
2169
+ error: !0
2170
+ }), await this.connectionProvider.ensureConnected(e), u && u({
2171
+ message: "Reconnect Successful",
2172
+ running: !0
2173
+ });
2174
+ } catch {
2175
+ return d && Object.values(d).forEach((e) => e({
2176
+ message: "Connection failed to reconnect.",
2177
+ error: !0,
2178
+ running: !1
2179
+ })), {
2180
+ success: !1,
2181
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2182
+ results: n.map((n) => ({
2183
+ success: !1,
2184
+ generated_sql: "",
2185
+ columns: [],
2186
+ error: `Connection ${e} not active, failed to reconnect.`,
2187
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2188
+ results: new t(/* @__PURE__ */ new Map(), []),
2189
+ columnCount: 0,
2190
+ resultSize: 0
2191
+ }))
2192
+ };
2193
+ }
2194
+ let g = this.connectionProvider.getConnectionSources(e);
2195
+ m && (g = g.concat(m));
2196
+ let _ = this.resolveRegisteredFiles(e, h), v = this.connectionProvider.getConnectionWorkingPath?.(e) ?? null;
2197
+ try {
2198
+ let o = await Promise.race([this.trilogyResolver.resolve_queries_batch(n, h.queryType, g, i, a, null, _.length > 0 ? _ : null, v), new Promise((e, t) => {
2199
+ c.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query batch cancelled by user")));
2200
+ })]), l = [];
2201
+ if (o && Array.isArray(o.data.queries)) for (let i = 0; i < o.data.queries.length; i++) {
2202
+ let u = o.data.queries[i];
2203
+ if (u.generated_sql) {
2204
+ let o = {
2205
+ ...n[i]?.parameters || {},
2206
+ ...u.parameters || {}
2207
+ }, p = Object.keys(o).length ? o : null;
2208
+ try {
2209
+ let t = await Promise.race([h.executeSql(u.generated_sql, p), new Promise((e, t) => {
2210
+ c.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query execution cancelled by user")));
2211
+ })]);
2212
+ w(r) && this.enrichTrilogyColumns(u.columns || [], t);
2213
+ let d = Y(u.chart), m = await this.executeChartLayers(h, u.chart, t, o, c, r), g = {
2214
+ success: !0,
2215
+ generatedSql: u.generated_sql,
2216
+ results: t,
2217
+ resultSize: t.data.length,
2218
+ columnCount: t.headers.size,
2219
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2220
+ chartConfig: d?.config,
2221
+ chartWarnings: d?.warnings.length ? d.warnings : void 0,
2222
+ layers: m
2223
+ };
2224
+ f && u.label && f[u.label] && f[u.label](g), l.push(g), this.storeHistory && Q(e).recordQuery({
2225
+ query: n[i].query,
2226
+ generatedQuery: u.generated_sql,
2227
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2228
+ status: "success",
2229
+ resultSize: t.data.length,
2230
+ resultColumns: t.headers.size,
2231
+ errorMessage: null,
2232
+ extraFilters: a
2233
+ });
2234
+ } catch (r) {
2235
+ let o = c.signal.aborted ? "Query execution cancelled by user" : r instanceof Error ? r.message : "Unknown error occurred during execution", f = {
2236
+ success: !1,
2237
+ error: o,
2238
+ generatedSql: u.generated_sql,
2239
+ results: new t(/* @__PURE__ */ new Map(), []),
2240
+ resultSize: 0,
2241
+ columnCount: 0,
2242
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s
2243
+ };
2244
+ l.push(f), console.error("Error callback for ", u.label, d), console.error("Error details:", r), d && u.label && d[u.label] && d[u.label](f), this.storeHistory && Q(e).recordQuery({
2245
+ query: n[i].query,
2246
+ generatedQuery: u.generated_sql,
2247
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2248
+ status: "error",
2249
+ resultSize: 0,
2250
+ resultColumns: 0,
2251
+ errorMessage: o,
2252
+ extraFilters: a
2253
+ });
2254
+ }
2255
+ } else if (u.error) {
2256
+ let e = {
2257
+ success: !1,
2258
+ error: u.error,
2259
+ generatedSql: "",
2260
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2261
+ results: new t(/* @__PURE__ */ new Map(), []),
2262
+ resultSize: 0,
2263
+ columnCount: 0
2264
+ };
2265
+ d && u.label && d[u.label] && d[u.label](e), l.push(e);
2266
+ } else {
2267
+ let e = {
2268
+ success: !1,
2269
+ error: "No SQL was generated for this query",
2270
+ generatedSql: "",
2271
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2272
+ results: new t(/* @__PURE__ */ new Map(), []),
2273
+ resultSize: 0,
2274
+ columnCount: 0
2275
+ };
2276
+ l.push(e), d && u.label && d[u.label] && d[u.label](e);
2277
+ }
2278
+ }
2279
+ return {
2280
+ success: !0,
2281
+ results: l,
2282
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s
2283
+ };
2284
+ } catch (e) {
2285
+ let t = c.signal.aborted ? "Query batch cancelled by user" : e instanceof Error ? e.message : "Unknown error occurred";
2286
+ return d && Object.values(d).forEach((e) => e({
2287
+ message: t,
2288
+ error: !0,
2289
+ running: !1
2290
+ })), {
2291
+ success: !1,
2292
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - s,
2293
+ results: []
2294
+ };
2295
+ }
2296
+ }
2297
+ async formatQuery(e, t, n, r = [], i, a, o, s) {
2298
+ if (n === "python") return e;
2299
+ try {
2300
+ let c = await this.trilogyResolver.format_query(e, t, n, i, r, null, null, a || null, o && o.length > 0 ? o : null, s ?? null);
2301
+ return c.data && c.data.text ? c.data.text : null;
2302
+ } catch (e) {
2303
+ throw console.error("Error formatting query:", e), e;
2304
+ }
2305
+ }
2306
+ async createDrilldownQuery(e, t, n, r = [], i, a, o, s, c, l, u) {
2307
+ if (n === "python") return null;
2308
+ try {
2309
+ let d = await this.trilogyResolver.drilldown_query(e, t, n, a, i, o, s, r, null, null, c || null, l && l.length > 0 ? l : null, u ?? null);
2310
+ return d.data && d.data.text ? d.data.text : null;
2311
+ } catch (e) {
2312
+ throw console.error("Error creating drilldown query:", e), e;
2313
+ }
2314
+ }
2315
+ async createConnectionDrilldownQuery(e, t, n, r = [], i, a, o, s, c) {
2316
+ let l = this.connectionProvider.getConnection(e);
2317
+ if (!l) throw Error(`Connection ${e} not found.`);
2318
+ return this.createDrilldownQuery(t, l.queryType, n, r, i, a, o, s, c, this.resolveRegisteredFiles(e, l), this.connectionProvider.getConnectionWorkingPath?.(e) ?? null);
2319
+ }
2320
+ async generateQuery(e, t) {
2321
+ let n = this.connectionProvider.getConnection(e);
2322
+ if (!n) throw Error(`Connection ${e} not found.`);
2323
+ let r = this.connectionProvider.getConnectionSources(e);
2324
+ t.extraContent && (r = r.concat(t.extraContent));
2325
+ let i = this.resolveRegisteredFiles(e, n), a = this.connectionProvider.getConnectionWorkingPath?.(e) ?? null;
2326
+ return this.trilogyResolver.resolve_query(t.text, n.queryType, t.editorType, r, t.imports, t.extraFilters, t.parameters, t.currentFilename || null, i.length > 0 ? i : null, a);
2327
+ }
2328
+ async validateQuery(e, t, n = !0, r = null) {
2329
+ if (t.editorType === "sql" || t.editorType === "python") return null;
2330
+ try {
2331
+ n && console.log(`Validating ${t.editorType} query`);
2332
+ } catch (e) {
2333
+ console.log(e);
2334
+ }
2335
+ let i = this.connectionProvider.getConnection(e);
2336
+ if (!i) return null;
2337
+ r ||= this.connectionProvider.getConnectionSources(e), t.extraContent && (r = r.concat(t.extraContent));
2338
+ let a = this.resolveRegisteredFiles(e, i), o = this.connectionProvider.getConnectionWorkingPath?.(e) ?? null;
2339
+ return await this.trilogyResolver.validate_query(t.text, r, t.imports, t.extraFilters, null, t.currentFilename || null, t.parameters || null, a.length > 0 ? a : null, o);
2340
+ }
2341
+ async getEligibleCrossFilterFields(e, t = {}) {
2342
+ let n = this.connectionProvider.getConnection(e);
2343
+ if (!n) throw Error(`Connection ${e} not found.`);
2344
+ let r = t.imports ?? [], i = t.extraFilters ?? [], a = t.extraContent ?? [], s = this.connectionProvider.getConnectionSources(e).concat(a), c = JSON.stringify({
2345
+ connectionId: e,
2346
+ queryType: n.queryType,
2347
+ imports: r,
2348
+ extraFilters: i,
2349
+ sources: s,
2350
+ currentFilename: t.currentFilename ?? null
2351
+ }), l = this.eligibleCrossFilterFieldsCache.get(c);
2352
+ if (l) return [...l];
2353
+ let u = await this.validateQuery(e, {
2354
+ text: "select 1 as cross_filter_probe;",
2355
+ editorType: "trilogy",
2356
+ imports: r,
2357
+ extraFilters: i,
2358
+ extraContent: a,
2359
+ currentFilename: t.currentFilename
2360
+ }, !1), d = o(u?.data.completion_items ?? []);
2361
+ return this.eligibleCrossFilterFieldsCache.set(c, d), [...d];
2362
+ }
2363
+ clearEligibleCrossFilterFieldsCache() {
2364
+ this.eligibleCrossFilterFieldsCache.clear();
2365
+ }
2366
+ async executeQuery(e, t, n, r, i, a, o = !1) {
2367
+ let s = (/* @__PURE__ */ new Date()).getTime(), c = new AbortController();
2368
+ return {
2369
+ cancellation: {
2370
+ cancel: () => c.abort(),
2371
+ isActive: () => !c.signal.aborted
2372
+ },
2373
+ resultPromise: this.executeQueryInternal(e, t, s, c, n, r, i, a, o)
2374
+ };
2375
+ }
2376
+ async executeQueryInternal(n, r, i, a, o, s, c, l, u = !1) {
2377
+ let d = 0, f = 0, p = "";
2378
+ if (r.editorType === "python") {
2379
+ let e = "Python files are editable but cannot be run locally.";
2380
+ return c && c({
2381
+ message: e,
2382
+ error: !0,
2383
+ running: !1
2384
+ }), {
2385
+ success: !1,
2386
+ error: e,
2387
+ executionTime: 0,
2388
+ resultSize: 0,
2389
+ columnCount: 0
2390
+ };
2391
+ }
2392
+ o && o();
2393
+ let m = this.connectionProvider.getConnection(n);
2394
+ if (!m) return c && c({
2395
+ message: `Connection ${n} not found.`,
2396
+ error: !0,
2397
+ running: !1
2398
+ }), {
2399
+ success: !1,
2400
+ error: `Connection ${n} not found.`,
2401
+ executionTime: 0,
2402
+ resultSize: 0,
2403
+ columnCount: 0
2404
+ };
2405
+ if (!m.isConnected() && !u) try {
2406
+ s && s({
2407
+ message: "Connection is not active... Attempting to automatically reconnect.",
2408
+ error: !0
2409
+ }), await this.connectionProvider.ensureConnected(n), s && s({
2410
+ message: "Reconnect Successful",
2411
+ running: !0
2412
+ });
2413
+ } catch {
2414
+ return c && c({
2415
+ message: "Connection failed to reconnect.",
2416
+ error: !0,
2417
+ running: !1
2418
+ }), {
2419
+ success: !1,
2420
+ error: "Connection is not active.",
2421
+ executionTime: 0,
2422
+ resultSize: 0,
2423
+ columnCount: 0
2424
+ };
2425
+ }
2426
+ if (r.editorType === "sql") try {
2427
+ let e = Oe(r.text);
2428
+ if (e.length === 0) {
2429
+ let e = {
2430
+ success: !0,
2431
+ generatedSql: r.text,
2432
+ results: new t(/* @__PURE__ */ new Map(), []),
2433
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2434
+ resultSize: 0,
2435
+ columnCount: 0
2436
+ };
2437
+ return l && l(e), e;
2438
+ }
2439
+ if (e.length > 1) {
2440
+ let t = e.slice(0, -1).join(";\n") + ";";
2441
+ await Promise.race([m.runScript(t), new Promise((e, t) => {
2442
+ a.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
2443
+ })]);
2444
+ }
2445
+ let o = e[e.length - 1], s;
2446
+ ke(o) ? (await Promise.race([m.runScript(o), new Promise((e, t) => {
2447
+ a.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
2448
+ })]), s = new t(/* @__PURE__ */ new Map(), [])) : s = await Promise.race([m.executeSql(o, r.parameters ?? null), new Promise((e, t) => {
2449
+ a.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
2450
+ })]);
2451
+ let c = {
2452
+ success: !0,
2453
+ generatedSql: r.text,
2454
+ results: s,
2455
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2456
+ resultSize: s.data.length,
2457
+ columnCount: s.headers.size
2458
+ };
2459
+ return this.storeHistory && Q(n).recordQuery({
2460
+ query: r.text,
2461
+ generatedQuery: r.text,
2462
+ executionTime: c.executionTime,
2463
+ status: "success",
2464
+ resultSize: c.resultSize,
2465
+ resultColumns: c.columnCount,
2466
+ errorMessage: null,
2467
+ extraFilters: r.extraFilters
2468
+ }), l && l(c), c;
2469
+ } catch (e) {
2470
+ let t = e instanceof Error ? e.message : String(e);
2471
+ return c && c({
2472
+ message: t,
2473
+ error: !0,
2474
+ running: !1
2475
+ }), {
2476
+ success: !1,
2477
+ error: t,
2478
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2479
+ resultSize: 0,
2480
+ columnCount: 0
2481
+ };
2482
+ }
2483
+ let h = this.connectionProvider.getConnectionSources(n);
2484
+ r.extraContent && (h = h.concat(r.extraContent));
2485
+ let g = this.resolveRegisteredFiles(n, m), _ = this.connectionProvider.getConnectionWorkingPath?.(n) ?? null, v = null;
2486
+ try {
2487
+ if (v = await Promise.race([this.trilogyResolver.resolve_query(r.text, m.queryType, r.editorType, h, r.imports, r.extraFilters, r.parameters, r.currentFilename || null, g.length > 0 ? g : null, _), new Promise((e, t) => {
2488
+ a.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
2489
+ })]), v && v.data.generated_output) {
2490
+ let n = v.data.columns || [], r = {
2491
+ success: !0,
2492
+ generatedSql: v.data.generated_sql,
2493
+ results: new t(new Map(n.map((t) => [t.name, {
2494
+ name: t.name,
2495
+ type: e.STRING,
2496
+ purpose: t.purpose
2497
+ }])), v.data.generated_output),
2498
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2499
+ resultSize: v.data.generated_output.length,
2500
+ columnCount: n.length,
2501
+ selectCount: v.data.select_count
2502
+ };
2503
+ return console.log(r), l && l(r), r;
2504
+ }
2505
+ if (!v || !v.data.generated_sql || u) {
2506
+ let e = {
2507
+ success: !0,
2508
+ results: new t(/* @__PURE__ */ new Map(), []),
2509
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2510
+ resultSize: 0,
2511
+ columnCount: 0
2512
+ };
2513
+ return l && l(e), e;
2514
+ }
2515
+ p = v.data.generated_sql;
2516
+ let o = Y(v.data.chart), s = v.data.columns, c = {
2517
+ ...r.parameters || {},
2518
+ ...v.data.parameters || {}
2519
+ }, y = Object.keys(c).length ? c : null, b = await Promise.race([m.executeSql(p, y), new Promise((e, t) => {
2520
+ a.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
2521
+ })]);
2522
+ w(r.editorType) && this.enrichTrilogyColumns(s, b), d = b.data.length, f = b.headers.size, this.storeHistory && Q(n).recordQuery({
2523
+ query: r.text,
2524
+ generatedQuery: p,
2525
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2526
+ status: "success",
2527
+ resultSize: d,
2528
+ resultColumns: f,
2529
+ errorMessage: null,
2530
+ extraFilters: r.extraFilters
2531
+ });
2532
+ let x = await this.executeChartLayers(m, v.data.chart, b, c, a, r.editorType), S = v?.data.select_count, C = {
2533
+ success: !0,
2534
+ generatedSql: p,
2535
+ results: b,
2536
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2537
+ resultSize: d,
2538
+ columnCount: f,
2539
+ selectCount: S,
2540
+ chartConfig: o?.config,
2541
+ chartWarnings: o?.warnings.length ? o.warnings : void 0,
2542
+ layers: x
2543
+ };
2544
+ return l && l(C), C;
2545
+ } catch (e) {
2546
+ console.error("[query catch] raw error:", e, "type:", typeof e, "ctor:", e?.constructor?.name);
2547
+ let t = a.signal.aborted ? "Query cancelled by user" : e instanceof Error ? e.message : typeof e == "string" ? e : (() => {
2548
+ try {
2549
+ return `Unknown error: ${JSON.stringify(e)}`;
2550
+ } catch {
2551
+ return `Unknown error: ${String(e)}`;
2552
+ }
2553
+ })();
2554
+ return this.storeHistory && Q(n).recordQuery({
2555
+ query: r.text,
2556
+ generatedQuery: p,
2557
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2558
+ status: "error",
2559
+ resultSize: d,
2560
+ resultColumns: f,
2561
+ errorMessage: t
2562
+ }), c && c({
2563
+ message: t,
2564
+ error: !0,
2565
+ running: !1,
2566
+ generatedSql: p
2567
+ }), {
2568
+ success: !1,
2569
+ error: t,
2570
+ executionTime: (/* @__PURE__ */ new Date()).getTime() - i,
2571
+ resultSize: d,
2572
+ columnCount: f
2573
+ };
2574
+ }
2575
+ }
2576
+ async executeChartLayers(e, n, r, i, a, o) {
2577
+ let s = n?.layers;
2578
+ if (!s || s.length < 2) return;
2579
+ let c = [r];
2580
+ for (let n = 1; n < s.length; n++) {
2581
+ let r = s[n];
2582
+ if (!r.generated_sql) {
2583
+ c.push(new t(/* @__PURE__ */ new Map(), []));
2584
+ continue;
2585
+ }
2586
+ let l = {
2587
+ ...i,
2588
+ ...r.parameters || {}
2589
+ }, u = await Promise.race([e.executeSql(r.generated_sql, Object.keys(l).length ? l : null), new Promise((e, t) => {
2590
+ a.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
2591
+ })]);
2592
+ w(o) && this.enrichTrilogyColumns(r.columns || [], u), c.push(u);
2593
+ }
2594
+ return c;
2595
+ }
2596
+ enrichTrilogyColumns(e, t) {
2597
+ for (let n = 0; n < e.length; n++) {
2598
+ let r = e[n], i = t.headers.get(r.name.replace("local.", "").replaceAll(".", "_"));
2599
+ i && (i.traits = r.traits || [], i.address = r.name, i.purpose = r.purpose, i.keys = r.keys || [], t.headers.set(i.name, i));
2600
+ }
2601
+ }
2602
+ };
2603
+ //#endregion
2604
+ export { A as _, xe as a, U as c, _e as d, N as f, pe as g, j as h, Ce as i, W as l, M as m, je as n, V as o, F as p, Q as r, H as s, $ as t, ve as u };