@trilogy-data/trilogy-studio-components 0.1.26 → 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 (138) hide show
  1. package/dist/AssetAutoImporter-OHphsfW9.js +403 -0
  2. package/dist/{ChatCreatorModal-CL-jBnc3.js → ChatCreatorModal-CuXha6Dg.js} +3 -3
  3. package/dist/{ChatModelSelect-Do-VRUFc.js → ChatModelSelect-Cz7axWjP.js} +1 -1
  4. package/dist/{CodeBlock-PT4no49I.js → CodeBlock-BBsaC6hX.js} +4 -4
  5. package/dist/{CommunityModels-Cmro0hV3.js → CommunityModels-CIQQhO-y.js} +7 -7
  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-BH9ZwMVJ.js → Dashboard-DxSi9W6Q.js} +276 -280
  10. package/dist/{DashboardImportSelector-DQSvu9T-.js → DashboardImportSelector-kuDRDYi8.js} +2 -2
  11. package/dist/{DashboardMobile-BUPtdN2V.js → DashboardMobile-CZEgTb0R.js} +39 -39
  12. package/dist/{DrilldownPane-CBs5ZojS.js → DrilldownPane-BheRHJMs.js} +5 -7
  13. package/dist/{Editor-DQsYpkwl.js → Editor-D6tdutTm.js} +105 -103
  14. package/dist/{ErrorMessage-XMn_08gJ.js → ErrorMessage-D5JeF3Iz.js} +4 -4
  15. package/dist/{GlobalChatPanel-DhnOaige.js → GlobalChatPanel-BXZh0sdD.js} +20 -21
  16. package/dist/{IDE-HLa8vybk.js → IDE-T8PmyAQ_.js} +200 -203
  17. package/dist/{JobsView-B97HBoIE.js → JobsView-Ca97MiSd.js} +13 -14
  18. package/dist/{LLMChat-CxJcPLEG.js → LLMChat-Cch33Yd_.js} +3 -3
  19. package/dist/{LLMView-C1MUf0c2.js → LLMView-BDb6wD74.js} +23 -23
  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-BpqXoaMR.js → MobileIDE-DpdEQEqc.js} +179 -182
  23. package/dist/{ModelCard-BhN25jaV.js → ModelCard-DkAMP4X9.js} +12 -13
  24. package/dist/{ModelView-DUDA_PtZ.js → ModelView-DomyhN8g.js} +7 -7
  25. package/dist/PageLoading-BAvKGo9h.js +5937 -0
  26. package/dist/{ResultComponent-CAn_r3BL.js → ResultComponent-zoOSoRLe.js} +8 -8
  27. package/dist/{Results-BJtlwebY.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-KYSwN9Sv.js → SymbolsPane-DfaxeaPS.js} +6 -3
  31. package/dist/{TrilogyEmbedProvider-WA_dlv9e.js → TrilogyEmbedProvider-D3h0gYnX.js} +9 -9
  32. package/dist/{TutorialPage-NRcee6Dx.js → TutorialPage-BtEJG7cT.js} +27 -28
  33. package/dist/{VegaLiteChart-D1slfOUY.js → VegaLiteChart-BVyAab-o.js} +12131 -10947
  34. package/dist/{WelcomePage-D5mU2x1L.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/FeedbackBanner.vue.d.ts +4 -0
  42. package/dist/components/FeedbackBanner.vue.d.ts.map +1 -0
  43. package/dist/components/dashboard/DashboardCreatorIcon.vue.d.ts +54 -0
  44. package/dist/components/dashboard/DashboardCreatorIcon.vue.d.ts.map +1 -0
  45. package/dist/components/dashboard/DashboardProvenance.vue.d.ts +30 -0
  46. package/dist/components/dashboard/DashboardProvenance.vue.d.ts.map +1 -0
  47. package/dist/components/dashboard/ReportLayout.vue.d.ts +19 -0
  48. package/dist/components/dashboard/ReportLayout.vue.d.ts.map +1 -0
  49. package/dist/components/editor/Editor.vue.d.ts +3 -3
  50. package/dist/components/editor/EditorCreatorIcon.vue.d.ts +62 -0
  51. package/dist/components/editor/EditorCreatorIcon.vue.d.ts.map +1 -0
  52. package/dist/components/editor/ValidationComponent.vue.d.ts +50 -0
  53. package/dist/components/editor/ValidationComponent.vue.d.ts.map +1 -0
  54. package/dist/components/model/ModelCard.vue.d.ts +3 -3
  55. package/dist/components/sidebar/LLMConnectionList.vue.d.ts.map +1 -1
  56. package/dist/components/sidebar/Sidebar.vue.d.ts.map +1 -1
  57. package/dist/components/tutorial/TutorialPrompt.vue.d.ts +3 -3
  58. package/dist/components/tutorial/TutorialPrompt.vue.d.ts.map +1 -1
  59. package/dist/{remoteWorker-Dkv3TJ0j.js → connections-CWH3zwH2.js} +4544 -4126
  60. package/dist/connections.js +3 -4
  61. package/dist/{cssMode-D4Rzr1Cu.js → cssMode-zpO2ap2B.js} +5 -6
  62. package/dist/dashboard.js +28 -31
  63. package/dist/{dist-CXoL8kXK.js → dist-1z5KURzS.js} +55 -50
  64. package/dist/{dist-DKkuvbPb.js → dist-Bv3D2p5A.js} +20 -18
  65. package/dist/{editor.main-Cl8i7rHY.js → editor.main-BQh6DxDB.js} +33 -33
  66. package/dist/{editorRefinementRuntime-DoP9P5J2.js → editorStore-CAlMJftt.js} +1692 -575
  67. package/dist/embed.js +2 -2
  68. package/dist/{freemarker2-fW5NBILf.js → freemarker2-DQBqlEXc.js} +1 -1
  69. package/dist/{globalChatRuntime-DWZxeS57.js → globalChatRuntime-CyS7vH51.js} +16 -16
  70. package/dist/{handlebars-dG4w8UUY.js → handlebars-tgYxaM70.js} +1 -1
  71. package/dist/{helpers-BLQAgX3C.js → helpers-BbVlA3Pf.js} +34 -35
  72. package/dist/{html-1Dq70BdU.js → html-jJahD3Mi.js} +1 -1
  73. package/dist/{htmlMode--IQmLBeh.js → htmlMode-BA1-8l2e.js} +5 -6
  74. package/dist/{javascript-CTzBM4sF.js → javascript-Cypfo7va.js} +1 -1
  75. package/dist/{jsonMode-DzeJjIEH.js → jsonMode-xJye8PWS.js} +25 -25
  76. package/dist/{liquid-DlHThiki.js → liquid-BGDrv5da.js} +1 -1
  77. package/dist/llm-ClU-2rgk.js +18493 -0
  78. package/dist/llm.js +2 -3
  79. package/dist/{localStorage-D9uyOFEO.js → localStorage-CGQ1iJXt.js} +40 -43
  80. package/dist/{lspLanguageFeatures-Cdfs3EKq.js → lspLanguageFeatures-V3e_p9oN.js} +32 -32
  81. package/dist/{mdx-fn3g4PH5.js → mdx-BUR1aImW.js} +1 -1
  82. package/dist/monaco.js +3 -3
  83. package/dist/{python-CCVj0pFt.js → python-YLkl0pc6.js} +1 -1
  84. package/dist/{razor-Cj3flYnk.js → razor-BP8TRMDY.js} +1 -1
  85. package/dist/{reconcile-Dyf4UZmj.js → reconcile-DXIvGwBk.js} +1 -1
  86. package/dist/{remoteStoreSync-Z-yjlYtI.js → remoteStoreSync-CuQBWpWf.js} +3 -3
  87. package/dist/{rolldown-runtime-Dqa2HsxW.js → rolldown-runtime-B0aSnxlc.js} +2 -2
  88. package/dist/static/test_import.vue.d.ts +4 -0
  89. package/dist/static/test_import.vue.d.ts.map +1 -0
  90. package/dist/stores-LlyiwSbK.js +2604 -0
  91. package/dist/stores.js +4 -7
  92. package/dist/trilogy-studio-components.css +1 -1
  93. package/dist/{tsMode-GI4xMYAl.js → tsMode-BH9HS_sH.js} +64 -66
  94. package/dist/{typescript-CPibXi3J.js → typescript-BM-ynfk9.js} +1 -1
  95. package/dist/{useChatWithTools-B0HZ_DVh.js → useChatWithTools-m3Jn_SV-.js} +11 -11
  96. package/dist/{useDashboard-CdSnPe_6.js → useDashboard-BOAuvVEw.js} +1014 -1022
  97. package/dist/{tabulator_esm-CxLvGDp8.js → useGlobalChatPanel-DuP1q7_f.js} +1729 -711
  98. package/dist/{useResizableDialog-B0ePSts4.js → useResizableDialog-Cs90WJdF.js} +2 -2
  99. package/dist/views/ModelView.vue.d.ts +6 -6
  100. package/dist/views/ModelView.vue.d.ts.map +1 -1
  101. package/dist/views/TutorialPage.vue.d.ts +9 -9
  102. package/dist/views/TutorialPage.vue.d.ts.map +1 -1
  103. package/dist/views.js +192 -194
  104. package/dist/{editor.api2-ClD5pp8H.js → workers-B9Eybl-M.js} +16252 -15926
  105. package/dist/{xml-BNyphceI.js → xml-M5WFPSpA.js} +1 -1
  106. package/dist/{yaml-DE5Vz0PH.js → yaml-CEeFwjz9.js} +1 -1
  107. package/package.json +29 -20
  108. package/dist/AssetAutoImporter-CBzvBaOt.js +0 -405
  109. package/dist/DashboardCreatorInline-CDU7kLy3.js +0 -129
  110. package/dist/DataTable-DoRDynP1.js +0 -365
  111. package/dist/EditorCreatorInline-D6_y1H_h.js +0 -125
  112. package/dist/LoadingButton-OH3frQuO.js +0 -138
  113. package/dist/ModalDialog-D1EOG4rl.js +0 -42
  114. package/dist/ModelCreator-CCdC7EXt.js +0 -253
  115. package/dist/PageLoading-BzniJM0C.js +0 -2669
  116. package/dist/Tooltip-Dihir4zs.js +0 -103
  117. package/dist/_plugin-vue_export-helper-B3ysoDQm.js +0 -8
  118. package/dist/assets/json.worker-CJ5MmO5Q.js +0 -58
  119. package/dist/base-C8IuZWqY.js +0 -164
  120. package/dist/connectionHistoryStorage-DKJHiKJY.js +0 -111
  121. package/dist/connectionHistoryStore-DQeBvStZ.js +0 -61
  122. package/dist/connections-CJSb1TZl.js +0 -229
  123. package/dist/constants-DgFEYN2b.js +0 -7
  124. package/dist/dashboardStore-ppM6nGks.js +0 -641
  125. package/dist/demoSetup-mwa-RDC6.js +0 -2942
  126. package/dist/editorRefinementToolExecutor-CVY3FA7k.js +0 -4624
  127. package/dist/editorStore-BhhmXbi-.js +0 -1019
  128. package/dist/formatting-BbJ5ICgh.js +0 -6
  129. package/dist/llm-BBOVWb-F.js +0 -11967
  130. package/dist/llmStore-DJM2JhzY.js +0 -153
  131. package/dist/monaco.contribution-ikesdolO.js +0 -128
  132. package/dist/stores-BT9hTLny.js +0 -1708
  133. package/dist/trilogy-BroD2Qmp.js +0 -4
  134. package/dist/urlStore-52HG6lsX.js +0 -55
  135. package/dist/useGlobalChatPanel-D_0luajQ.js +0 -85
  136. package/dist/useIsMobile-CNpUQAvk.js +0 -8
  137. package/dist/usePrismHighlight-DVyDiDAL.js +0 -183
  138. package/dist/workers-Br7ThUKL.js +0 -47
@@ -1,1708 +0,0 @@
1
- import { r as e, t } from "./results-DTgAKr5j.js";
2
- import { Rt as n, an as r } from "./editorRefinementToolExecutor-CVY3FA7k.js";
3
- import { E as i, i as a } from "./editorRefinementRuntime-DoP9P5J2.js";
4
- import { t as o } from "./constants-DgFEYN2b.js";
5
- import { C as s, O as c, _ as l, b as u, g as d, h as f, i as p, m, t as h, v as g, y as _ } from "./editorStore-BhhmXbi-.js";
6
- import "./llmStore-DJM2JhzY.js";
7
- import { n as v } from "./dashboardStore-ppM6nGks.js";
8
- import { a as y, i as b, n as x, r as S, t as C } from "./urlStore-52HG6lsX.js";
9
- import { t as w } from "./connectionHistoryStore-DQeBvStZ.js";
10
- import { computed as T, ref as E } from "vue";
11
- import { defineStore as D } from "pinia";
12
- //#region data/tips.ts
13
- var O = [
14
- {
15
- id: "welcome",
16
- title: "Welcome!",
17
- 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.",
18
- category: "onboarding"
19
- },
20
- {
21
- id: "navigation",
22
- title: "Navigation",
23
- 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.",
24
- category: "onboarding",
25
- highlightDataTestId: "sidebar-icons"
26
- },
27
- {
28
- id: "settings",
29
- title: "Settings",
30
- content: "User settings - such as darkmode - can be accessed through the gear on the bottom of the sidebar.",
31
- category: "onboarding",
32
- highlightDataTestId: "sidebar-icon-settings"
33
- },
34
- {
35
- id: "trilogy",
36
- title: "Trilogy - The Query Language",
37
- 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!",
38
- category: "onboarding",
39
- highlightDataTestId: "sidebar-icon-tutorial"
40
- }
41
- ], k = [
42
- {
43
- id: "editor-intro",
44
- title: "Settings",
45
- content: "Editors let you run SQL or Trilogy commands. Click the run button in top right to run a query.",
46
- category: "editor",
47
- highlightDataTestId: "editor-run-button"
48
- },
49
- {
50
- id: "editor-shortcuts",
51
- title: "Keyboard Shortcuts",
52
- content: "Standard keyboard shortcuts are available to run, validate, generate AI code, format, and save your work.",
53
- category: "editor",
54
- highlightDataTestId: "editor-shortcut-hints"
55
- },
56
- {
57
- id: "editor-validate",
58
- title: "Validate",
59
- content: "Click the validate button to parse the current Trilogy script. This will provide syntax feedback and populate the schema explorer on the right.",
60
- category: "editor",
61
- highlightDataTestId: "editor-validate-button"
62
- },
63
- {
64
- id: "editor-save",
65
- title: "Save",
66
- content: "Click the save button to save your changes to local browser storage. Trilogy will auto-save regularly, but you can trigger on demand.",
67
- category: "editor",
68
- highlightDataTestId: "editor-save-button"
69
- },
70
- {
71
- id: "editor-sources",
72
- title: "Sources",
73
- 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.",
74
- category: "editor",
75
- highlightDataTestId: "editor-set-source"
76
- },
77
- {
78
- id: "editor-ai",
79
- title: "AI Assistance",
80
- 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.",
81
- category: "editor",
82
- highlightDataTestId: "editor-generate-button"
83
- }
84
- ], ee = [
85
- {
86
- id: "dashboard-intro",
87
- title: "Dashboard",
88
- 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!",
89
- category: "dashboard"
90
- },
91
- {
92
- id: "dashboard-full-screen",
93
- title: "Full Screen",
94
- 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.",
95
- category: "dashboard",
96
- highlightDataTestId: "toggle-edit-mode-button"
97
- },
98
- {
99
- id: "dashboard-add-item",
100
- title: "Add Dashboard Item",
101
- 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.",
102
- category: "dashboard",
103
- highlightDataTestId: "add-item-button"
104
- },
105
- {
106
- id: "dashboard-edit",
107
- title: "Dashboard Data",
108
- 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.) ",
109
- category: "dashboard",
110
- highlightDataTestId: "dashboard-item-header-controls"
111
- },
112
- {
113
- id: "dashboard-filter",
114
- title: "Dashboard Filters",
115
- 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.",
116
- category: "dashboard",
117
- highlightDataTestId: "filter-input"
118
- },
119
- {
120
- id: "dashboard-source",
121
- title: "Dashboard Source",
122
- 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.",
123
- category: "dashboard",
124
- highlightDataTestId: "dashboard-import-wrapper"
125
- },
126
- {
127
- id: "dashboard-connection",
128
- title: "Dashboard Connection",
129
- 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.",
130
- category: "dashboard",
131
- highlightDataTestId: "connection-selector-wrapper"
132
- },
133
- {
134
- id: "dashboard-features",
135
- title: "Complex Types",
136
- 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.",
137
- category: "dashboard"
138
- }
139
- ], A = [{
140
- id: "model-intro",
141
- title: "Community Models",
142
- 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.",
143
- category: "community",
144
- highlightDataTestId: "sidebar-icon-community-models"
145
- }, {
146
- id: "feature-update",
147
- title: "Sharing Dashboards!",
148
- 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.",
149
- category: "community",
150
- highlightDataTestId: "copy-dashboard-share-button"
151
- }];
152
- //#endregion
153
- //#region projects/project.ts
154
- function j() {
155
- return `proj-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
156
- }
157
- var M = class e {
158
- id;
159
- name;
160
- description;
161
- dataConnectionId;
162
- llmConnectionName;
163
- editorIds;
164
- subchatIds;
165
- dashboardIds;
166
- directoryPath;
167
- promptOverrides;
168
- createdAt;
169
- updatedAt;
170
- storage;
171
- changed;
172
- deleted;
173
- constructor(e = {}) {
174
- this.id = e.id || j(), 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;
175
- }
176
- setName(e) {
177
- this.name !== e && (this.name = e, this.touch());
178
- }
179
- setDescription(e) {
180
- this.description !== e && (this.description = e, this.touch());
181
- }
182
- setDirectoryPath(e) {
183
- this.directoryPath !== e && (this.directoryPath = e, this.touch());
184
- }
185
- setPromptOverride(e, t) {
186
- let n = t?.trim() ?? "", r = this.promptOverrides[e];
187
- if (n) {
188
- if (r === n) return;
189
- this.promptOverrides[e] = n;
190
- } else {
191
- if (r === void 0) return;
192
- delete this.promptOverrides[e];
193
- }
194
- this.touch();
195
- }
196
- addSubchat(e) {
197
- return this.subchatIds.includes(e) ? !1 : (this.subchatIds.push(e), this.touch(), !0);
198
- }
199
- removeSubchat(e) {
200
- let t = this.subchatIds.indexOf(e);
201
- return t === -1 ? !1 : (this.subchatIds.splice(t, 1), this.touch(), !0);
202
- }
203
- addEditor(e) {
204
- return this.editorIds.includes(e) ? !1 : (this.editorIds.push(e), this.touch(), !0);
205
- }
206
- removeEditor(e) {
207
- let t = this.editorIds.indexOf(e);
208
- return t === -1 ? !1 : (this.editorIds.splice(t, 1), this.touch(), !0);
209
- }
210
- addDashboard(e) {
211
- return this.dashboardIds.includes(e) ? !1 : (this.dashboardIds.push(e), this.touch(), !0);
212
- }
213
- removeDashboard(e) {
214
- let t = this.dashboardIds.indexOf(e);
215
- return t === -1 ? !1 : (this.dashboardIds.splice(t, 1), this.touch(), !0);
216
- }
217
- touch() {
218
- this.updatedAt = /* @__PURE__ */ new Date(), this.changed = !0;
219
- }
220
- serialize() {
221
- return {
222
- id: this.id,
223
- name: this.name,
224
- description: this.description,
225
- dataConnectionId: this.dataConnectionId,
226
- llmConnectionName: this.llmConnectionName,
227
- editorIds: this.editorIds,
228
- subchatIds: this.subchatIds,
229
- dashboardIds: this.dashboardIds,
230
- directoryPath: this.directoryPath,
231
- promptOverrides: { ...this.promptOverrides },
232
- createdAt: this.createdAt.toISOString(),
233
- updatedAt: this.updatedAt.toISOString(),
234
- storage: this.storage
235
- };
236
- }
237
- static fromSerialized(t) {
238
- return new e({
239
- ...t,
240
- createdAt: t.createdAt ? new Date(t.createdAt) : /* @__PURE__ */ new Date(),
241
- updatedAt: t.updatedAt ? new Date(t.updatedAt) : /* @__PURE__ */ new Date(),
242
- changed: !1
243
- });
244
- }
245
- }, N = /* @__PURE__ */ new Map(), P = "trilogy-jobs-api-state", F = (e, t, n) => `${e}::${n}::${t}`, I = (e, t) => `${e}::${t}`, L = (e) => {
246
- let t = e.pollingState, n = t === "unable-to-fetch" ? "stopped" : e.pollingState ?? "ok";
247
- return {
248
- ...e,
249
- pollingState: n,
250
- pollingError: n === "stopped" && !e.pollingError && t === "unable-to-fetch" ? "Polling stopped locally." : e.pollingError ?? null
251
- };
252
- }, R = (e) => {
253
- let t = e instanceof Error ? e.message : "Failed to fetch state";
254
- return e instanceof m ? 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;
255
- }, z = (e) => [...e].sort((e, t) => t.submittedAt - e.submittedAt), te = D("jobsApi", {
256
- state: () => ({
257
- filesByStore: {},
258
- jobsByStore: {},
259
- errors: {},
260
- storeStatus: {},
261
- loadingByStore: {},
262
- submittingByTarget: {},
263
- pollingByJob: {},
264
- stoppingByJob: {},
265
- stateByTarget: {},
266
- stateLoadingByTarget: {},
267
- stateErrorsByTarget: {}
268
- }),
269
- actions: {
270
- getGenericStore(e) {
271
- let t = p().stores.find((t) => t.id === e);
272
- return !t || t.type !== "generic" ? null : t;
273
- },
274
- getGenericStores() {
275
- return p().stores.filter((e) => e.type === "generic");
276
- },
277
- getStoreJobs(e) {
278
- return z(this.jobsByStore[e] || []);
279
- },
280
- getJobsForTarget(e, t) {
281
- return this.getStoreJobs(e).filter((e) => e.target === t);
282
- },
283
- getStoreStatus(e) {
284
- return (this.jobsByStore[e] || []).some((e) => e.status === "running" && (e.pollingState ?? "ok") === "ok") ? "running" : this.storeStatus[e] || "idle";
285
- },
286
- isSubmitting(e, t, n) {
287
- return !!this.submittingByTarget[F(e, t, n)];
288
- },
289
- getState(e, t) {
290
- return this.stateByTarget[u(e, t)]?.snapshot || null;
291
- },
292
- getStateMeta(e, t) {
293
- let n = this.stateByTarget[u(e, t)];
294
- return n ? {
295
- cached: n.cached,
296
- computedAt: n.computedAt
297
- } : null;
298
- },
299
- isStateLoading(e, t) {
300
- return !!this.stateLoadingByTarget[u(e, t)];
301
- },
302
- getStateError(e, t) {
303
- return this.stateErrorsByTarget[u(e, t)] || "";
304
- },
305
- isPollingJob(e, t) {
306
- return !!this.pollingByJob[I(e, t)];
307
- },
308
- isStoppingJob(e, t) {
309
- return !!this.stoppingByJob[I(e, t)];
310
- },
311
- clearStoreError(e) {
312
- delete this.errors[e], this.storeStatus[e] = "idle";
313
- },
314
- clearStoreData(e) {
315
- Array.from(N.keys()).filter((t) => t.startsWith(`${e}:`)).forEach((e) => {
316
- let t = N.get(e);
317
- t && clearInterval(t), N.delete(e);
318
- }), 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();
319
- },
320
- clearStateForStore(e) {
321
- let t = (t) => s(t)?.storeId === e, n = (e) => {
322
- Object.keys(e).filter(t).forEach((t) => delete e[t]);
323
- };
324
- n(this.stateByTarget), n(this.stateLoadingByTarget), n(this.stateErrorsByTarget);
325
- },
326
- clearStateError(e, t) {
327
- delete this.stateErrorsByTarget[u(e, t)];
328
- },
329
- refreshLoadedStateForTarget(e, t) {
330
- Object.keys(this.stateByTarget).forEach((n) => {
331
- let r = s(n);
332
- !r || r.storeId !== e || c(r.target, t) && this.fetchStateForTarget(e, r.target);
333
- });
334
- },
335
- async fetchStateForTarget(e, t, n = !1) {
336
- let r = this.getGenericStore(e);
337
- if (!r) return;
338
- let i = u(e, t);
339
- if (!this.stateLoadingByTarget[i]) {
340
- this.stateLoadingByTarget[i] = !0, delete this.stateErrorsByTarget[i];
341
- try {
342
- let e = await g(r, t, n);
343
- this.stateByTarget[i] = {
344
- snapshot: e.snapshot,
345
- cached: e.cached,
346
- computedAt: e.computedAt
347
- };
348
- } catch (e) {
349
- this.stateErrorsByTarget[i] = R(e);
350
- } finally {
351
- delete this.stateLoadingByTarget[i];
352
- }
353
- }
354
- },
355
- async initialize() {
356
- p().loadStoresFromStorage(), this.loadJobsFromStorage(), this.resumePolling(), await this.refreshAllStores();
357
- },
358
- saveJobsToStorage() {
359
- try {
360
- localStorage.setItem(P, JSON.stringify(this.jobsByStore));
361
- } catch (e) {
362
- console.error("Error saving jobs to localStorage:", e);
363
- }
364
- },
365
- loadJobsFromStorage() {
366
- try {
367
- let e = localStorage.getItem(P);
368
- if (!e) return;
369
- let t = JSON.parse(e);
370
- this.jobsByStore = Object.fromEntries(Object.entries(t).map(([e, t]) => [e, (t || []).map((e) => L(e))]));
371
- } catch (e) {
372
- console.error("Error loading jobs from localStorage:", e);
373
- }
374
- },
375
- resumePolling() {
376
- Object.entries(this.jobsByStore).forEach(([e, t]) => {
377
- t.forEach((t) => {
378
- t.status === "running" && (t.pollingState ?? "ok") === "ok" && this.startPolling(e, t.job_id);
379
- });
380
- });
381
- },
382
- async resumeAuthPausedJobs(e) {
383
- let t = (this.jobsByStore[e] || []).filter((e) => e.status === "running" && e.pollingState === "auth-paused");
384
- await Promise.all(t.map(async (t) => {
385
- let n = {
386
- ...t,
387
- updatedAt: Date.now(),
388
- pollingState: "ok",
389
- pollingError: null
390
- };
391
- this.upsertJob(e, n), this.startPolling(e, t.job_id), await this.pollJob(e, t.job_id);
392
- }));
393
- },
394
- async refreshAllStores() {
395
- let e = this.getGenericStores();
396
- await Promise.all(e.map((e) => this.fetchFilesForStore(e.id)));
397
- },
398
- async fetchFilesForStore(e) {
399
- let t = this.getGenericStore(e);
400
- if (t) {
401
- this.loadingByStore[e] = !0, this.storeStatus[e] = "idle";
402
- try {
403
- this.filesByStore[e] = await d(t), delete this.errors[e], this.storeStatus[e] = "connected";
404
- } catch (t) {
405
- let n = t instanceof Error ? t.message : "Failed to fetch files";
406
- this.errors[e] = n, this.storeStatus[e] = "failed";
407
- } finally {
408
- this.loadingByStore[e] = !1;
409
- }
410
- }
411
- },
412
- upsertJob(e, t) {
413
- let n = this.jobsByStore[e] || [], r = n.findIndex((e) => e.job_id === t.job_id);
414
- if (r === -1) {
415
- this.jobsByStore[e] = z([t, ...n]), this.saveJobsToStorage();
416
- return;
417
- }
418
- let i = [...n];
419
- i[r] = {
420
- ...i[r],
421
- ...t
422
- }, this.jobsByStore[e] = z(i), this.saveJobsToStorage();
423
- },
424
- replaceJobs(e, t) {
425
- this.jobsByStore[e] = z(t), this.saveJobsToStorage();
426
- },
427
- removeJob(e, t) {
428
- this.stopPolling(e, t), delete this.pollingByJob[I(e, t)], delete this.stoppingByJob[I(e, t)], this.jobsByStore[e] = (this.jobsByStore[e] || []).filter((e) => e.job_id !== t), this.saveJobsToStorage();
429
- },
430
- stopPolling(e, t) {
431
- let n = `${e}:${t}`, r = N.get(n);
432
- r && (clearInterval(r), N.delete(n));
433
- },
434
- pauseJobPolling(e, t, n, r) {
435
- let i = (this.jobsByStore[e] || []).find((e) => e.job_id === t);
436
- if (!i) {
437
- this.stopPolling(e, t);
438
- return;
439
- }
440
- this.stopPolling(e, t);
441
- let a = {
442
- ...i,
443
- updatedAt: Date.now(),
444
- pollingState: n,
445
- pollingError: r
446
- };
447
- this.upsertJob(e, a);
448
- },
449
- startPolling(e, t) {
450
- this.stopPolling(e, t);
451
- let n = `${e}:${t}`, r = setInterval(() => {
452
- this.pollJob(e, t);
453
- }, 1e3);
454
- N.set(n, r);
455
- },
456
- buildLocalJob(e, t, n, r, i) {
457
- let a = Date.now();
458
- return {
459
- ...r,
460
- storeId: e,
461
- target: t,
462
- operation: n,
463
- submittedAt: i || a,
464
- updatedAt: a,
465
- pollingState: "ok",
466
- pollingError: null
467
- };
468
- },
469
- async submitJob(e, t, n) {
470
- let r = this.getGenericStore(e);
471
- if (!r) throw Error("Store not found or does not support jobs");
472
- let i = F(e, t, n);
473
- this.submittingByTarget[i] = !0;
474
- try {
475
- let i = await _(r, n, t), a = this.buildLocalJob(e, t, n, i);
476
- return this.upsertJob(e, a), delete this.errors[e], this.storeStatus[e] = "connected", a.status === "running" && this.startPolling(e, a.job_id), a;
477
- } catch (r) {
478
- let i = r instanceof Error ? r.message : `Failed to ${n} ${t}`;
479
- throw this.errors[e] = i, this.storeStatus[e] = "failed", r;
480
- } finally {
481
- delete this.submittingByTarget[i];
482
- }
483
- },
484
- async pollJob(e, t) {
485
- let n = I(e, t);
486
- if (this.pollingByJob[n]) return;
487
- this.pollingByJob[n] = !0;
488
- let r = this.getGenericStore(e), i = (this.jobsByStore[e] || []).find((e) => e.job_id === t);
489
- if (!r || !i) {
490
- this.stopPolling(e, t), delete this.pollingByJob[n];
491
- return;
492
- }
493
- try {
494
- let n = await l(r, t), a = this.buildLocalJob(e, i.target, i.operation, n, i.submittedAt);
495
- this.upsertJob(e, a), a.status !== "running" && (this.stopPolling(e, t), this.fetchFilesForStore(e), this.refreshLoadedStateForTarget(e, a.target));
496
- } catch (n) {
497
- let r = n instanceof Error ? n.message : `Failed to poll job ${t}`;
498
- n instanceof m && n.status === 401 ? this.pauseJobPolling(e, t, "auth-paused", "Polling paused: authentication required. Update the store token to resume tracking.") : n instanceof m && 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}`);
499
- } finally {
500
- delete this.pollingByJob[n];
501
- }
502
- },
503
- async stopJob(e, t) {
504
- let n = I(e, t);
505
- if (this.stoppingByJob[n]) return;
506
- let r = this.getGenericStore(e), i = (this.jobsByStore[e] || []).find((e) => e.job_id === t);
507
- if (!r || !i) {
508
- this.stopPolling(e, t);
509
- return;
510
- }
511
- this.stoppingByJob[n] = !0, this.stopPolling(e, t), delete this.pollingByJob[n];
512
- try {
513
- let n = await f(r, t), a = this.buildLocalJob(e, i.target, i.operation, n, i.submittedAt);
514
- a.status === "running" && (a.pollingState = "stopped", a.pollingError = "Cancel requested. Polling stopped locally."), this.upsertJob(e, a);
515
- } catch (n) {
516
- let r = n instanceof Error ? n.message : `Failed to cancel job ${t}`, a = {
517
- ...i,
518
- updatedAt: Date.now(),
519
- pollingState: "stopped",
520
- pollingError: `Stopped polling locally. ${r}`
521
- };
522
- this.upsertJob(e, a);
523
- } finally {
524
- delete this.stoppingByJob[n];
525
- }
526
- }
527
- }
528
- }), B = D("projects", {
529
- state: () => ({
530
- projects: {},
531
- activeProjectId: ""
532
- }),
533
- getters: {
534
- projectList: (e) => Object.values(e.projects).filter((e) => !e.deleted),
535
- unsavedProjects: (e) => Object.values(e.projects).filter((e) => e.changed && !e.deleted).length,
536
- activeProject: (e) => e.activeProjectId && e.projects[e.activeProjectId] || null,
537
- getProjectById: (e) => (t) => e.projects[t] || null
538
- },
539
- actions: {
540
- newProject(e, t = "") {
541
- let n = new M({
542
- name: e || `Project ${(/* @__PURE__ */ new Date()).toLocaleDateString()}`,
543
- description: t
544
- });
545
- return this.projects[n.id] = n, this.activeProjectId = n.id, n;
546
- },
547
- addProject(e) {
548
- this.projects[e.id] = e;
549
- },
550
- removeProject(e) {
551
- let t = this.projects[e];
552
- t && (t.deleted = !0, t.changed = !0, this.activeProjectId === e && (this.activeProjectId = ""));
553
- },
554
- setActiveProject(e) {
555
- this.projects[e] && !this.projects[e].deleted && (this.activeProjectId = e);
556
- },
557
- clearActiveProject() {
558
- this.activeProjectId = "";
559
- },
560
- renameProject(e, t) {
561
- this.projects[e]?.setName(t);
562
- },
563
- setProjectDescription(e, t) {
564
- this.projects[e]?.setDescription(t);
565
- },
566
- setProjectDataConnection(e, t) {
567
- let n = this.projects[e];
568
- n && n.dataConnectionId !== t && (n.dataConnectionId = t, n.updatedAt = /* @__PURE__ */ new Date(), n.changed = !0);
569
- },
570
- setProjectLLMConnection(e, t) {
571
- let n = this.projects[e];
572
- n && n.llmConnectionName !== t && (n.llmConnectionName = t, n.updatedAt = /* @__PURE__ */ new Date(), n.changed = !0);
573
- },
574
- setProjectDirectory(e, t) {
575
- this.projects[e]?.setDirectoryPath(t);
576
- },
577
- addSubchatToProject(e, t) {
578
- return this.projects[e]?.addSubchat(t) ?? !1;
579
- },
580
- removeSubchatFromProject(e, t) {
581
- return this.projects[e]?.removeSubchat(t) ?? !1;
582
- },
583
- addEditorToProject(e, t) {
584
- return this.projects[e]?.addEditor(t) ?? !1;
585
- },
586
- removeEditorFromProject(e, t) {
587
- return this.projects[e]?.removeEditor(t) ?? !1;
588
- },
589
- addDashboardToProject(e, t) {
590
- return this.projects[e]?.addDashboard(t) ?? !1;
591
- },
592
- removeDashboardFromProject(e, t) {
593
- return this.projects[e]?.removeDashboard(t) ?? !1;
594
- },
595
- setProjectPromptOverride(e, t, n) {
596
- this.projects[e]?.setPromptOverride(t, n);
597
- },
598
- setProjects(e) {
599
- if (this.projects = e, !this.activeProjectId) {
600
- let t = Object.values(e).find((e) => !e.deleted);
601
- t && (this.activeProjectId = t.id);
602
- }
603
- }
604
- }
605
- }), V = () => {
606
- let e = v(), t = h(), n = r(), i = p(), s = a(), c = null, l = {
607
- activeScreen: E(x(C.SCREEN, "")),
608
- activeSidebarScreen: E(x(C.SIDEBAR_SCREEN, "editors")),
609
- activeEditor: E(x(C.EDITORS, "")),
610
- activeDashboard: E(x(C.DASHBOARD, "")),
611
- activeConnectionKey: E(x(C.CONNECTIONS, "")),
612
- activeModelKey: E(x(C.MODELS, "")),
613
- activeCommunityModelKey: E(x(C.COMMUNITY_MODELS, "")),
614
- activeJobsKey: E(x(C.JOBS, "")),
615
- activeLLMConnectionKey: E(x(C.LLMS, "")),
616
- activeDocumentationKey: E(x(C.TUTORIAL, "")),
617
- modelImport: E(x(C.IMPORT, x(C.MODELS, ""))),
618
- connectionImport: E(x(C.CONNECTION, "")),
619
- mobileMenuOpen: E(!1),
620
- initialSearch: E(x(C.INITIAL_SEARCH, "")),
621
- tabs: E([]),
622
- activeTab: E(null),
623
- showTipModal: E(!0),
624
- displayedTips: E([]),
625
- fullScreen: E(!1)
626
- }, u = /* @__PURE__ */ new Set([
627
- "editors",
628
- "tutorial",
629
- "llms",
630
- "jobs",
631
- "dashboard",
632
- "models",
633
- "community-models",
634
- "profile",
635
- "settings",
636
- "connections"
637
- ]), d = (e, t = !1) => {
638
- if (l.activeSidebarScreen.value !== e && (l.activeSidebarScreen.value = e, !t)) {
639
- if (e) {
640
- S(C.SIDEBAR_SCREEN, e);
641
- return;
642
- }
643
- b(C.SIDEBAR_SCREEN);
644
- }
645
- }, f = (e, t = !1) => {
646
- u.has(e) && d(e, t);
647
- }, m = (n, r, a) => {
648
- if (r) return r;
649
- if (n === "dashboard") {
650
- let t = e.dashboards[a];
651
- if (t) return t.name || "Untitled Dashboard";
652
- } else if (n === "editors") {
653
- let e = t.editors[a];
654
- if (e) return e.name || "Untitled Editor";
655
- } else if (n === "llms") {
656
- let e = a.split("+"), t = e[0], n = e.length > 1 ? e[1] : null;
657
- if (n) {
658
- let e = s.getChatById(n);
659
- if (e) return e.name;
660
- }
661
- return t || "LLM Chat";
662
- } else if (n === "community-models") {
663
- let e = a.split("+"), t = e[0], n = i.stores.find((e) => e.id === t);
664
- if (n) return e.length === 2 ? `${n.name} - ${e[1]}` : e.length === 3 ? e[2] : n.name;
665
- } else if (n === "jobs") {
666
- let e = a.split("+"), t = e[0], n = i.stores.find((e) => e.id === t)?.name || t;
667
- if (e.length === 1) return n;
668
- let r = decodeURIComponent(e[2] || "");
669
- if (e[1] === "directory") return r === "__root__" ? `${n} - Root` : r;
670
- if (e[1] === "file") {
671
- let e = r.split("/");
672
- return e[e.length - 1] || n;
673
- }
674
- }
675
- return o(a, null);
676
- }, g = (e, t, n) => {
677
- let r = l.tabs.value.find((t) => t.screen === e && t.address === n);
678
- r && (r.title = m(e, t, n));
679
- }, _ = (e, t, n, r = !1) => {
680
- let i = l.tabs.value.find((t) => t.screen === e && t.address === n);
681
- if (i) {
682
- M(i.id, r);
683
- return;
684
- }
685
- let a = l.tabs.value.reduce((e, t) => {
686
- let n = parseInt(t.id.replace("tab-", ""));
687
- return isNaN(n) ? e : Math.max(e, n);
688
- }, 0);
689
- r || N(e);
690
- let o = m(e, t, n), s = {
691
- id: `tab-${++a}`,
692
- title: o,
693
- screen: e,
694
- address: n
695
- };
696
- l.tabs.value.push(s), M(s.id, r);
697
- }, w = (e, t = null) => {
698
- if (!e && !t) return;
699
- if (!e && t) {
700
- let n = l.tabs.value.find((e) => e.address === t);
701
- if (n) e = n.id;
702
- else return;
703
- }
704
- let n = l.tabs.value.findIndex((t) => t.id === e);
705
- if (n !== -1) {
706
- let t = l.activeTab.value === e;
707
- if (l.tabs.value.splice(n, 1), t) if (l.tabs.value.length > 0) {
708
- let e = n > 0 ? n - 1 : 0;
709
- M(l.tabs.value[e].id);
710
- } else _("welcome", "Welcome", "welcome");
711
- }
712
- D();
713
- }, T = (e) => {
714
- let t = l.activeTab.value === e;
715
- l.tabs.value = l.tabs.value.filter((t) => t.id === e), t || (l.tabs.value.length > 0 ? M(l.tabs.value[0].id) : _("welcome", "Welcome", "welcome")), D();
716
- }, D = () => {
717
- let e = l.tabs.value.map((e) => e.screen), t = [];
718
- e.includes("editors") || (l.activeEditor.value = "", t.push(C.EDITORS), t.push(C.ACTIVE_EDITOR_TAB)), e.includes("dashboard") || (l.activeDashboard.value = "", t.push(C.DASHBOARD)), e.includes("connections") || (l.activeConnectionKey.value = "", t.push(C.CONNECTIONS)), e.includes("models") || (l.activeModelKey.value = "", t.push(C.MODELS)), e.includes("community-models") || (l.activeCommunityModelKey.value = "", t.push(C.COMMUNITY_MODELS)), e.includes("jobs") || (l.activeJobsKey.value = "", t.push(C.JOBS)), e.includes("tutorial") || (l.activeDocumentationKey.value = "", t.push(C.TUTORIAL)), e.includes("llms") || (l.activeLLMConnectionKey.value = "", t.push(C.LLMS)), e.includes("settings") || t.push(C.SETTINGS), e.includes("profile") || t.push(C.PROFILE), e.includes("welcome") || t.push(C.WELCOME), y(t);
719
- }, j = (e) => {
720
- let t = l.tabs.value.findIndex((t) => t.id === e);
721
- if (t !== -1) {
722
- let e = l.tabs.value.findIndex((e) => e.id === l.activeTab.value) > t;
723
- l.tabs.value.splice(t + 1), e && (l.tabs.value.length > 0 ? M(l.tabs.value[l.tabs.value.length - 1].id) : _("welcome", "Welcome", "welcome"));
724
- }
725
- D();
726
- }, M = (r, i = !1) => {
727
- let a = l.tabs.value.find((e) => e.id === r);
728
- if (a) {
729
- l.activeTab.value = r, N(a.screen), f(a.screen, i);
730
- let o = n.getUnreadTips(O);
731
- if (a.screen === "editors") l.activeEditor.value = a.address, t.activeEditorId = a.address, o = o.concat(n.getUnreadTips(k));
732
- else if (a.screen === "dashboard") l.activeDashboard.value = a.address, e.activeDashboardId = a.address, o = l.fullScreen.value ? [] : o.concat(n.getUnreadTips(ee));
733
- else if (a.screen === "connections") l.activeConnectionKey.value = a.address;
734
- else if (a.screen === "llms") {
735
- l.activeLLMConnectionKey.value = a.address;
736
- let e = a.address.split("+");
737
- if (e.length > 1) {
738
- let t = e[1];
739
- s.setActiveChat(t);
740
- }
741
- } else a.screen === "tutorial" ? l.activeDocumentationKey.value = a.address : a.screen === "models" ? l.activeModelKey.value = a.address : a.screen === "dashboard-import" || a.screen === "asset-import" ? o = [] : a.screen === "community-models" ? (l.activeCommunityModelKey.value = a.address, o = o.concat(n.getUnreadTips(A))) : a.screen === "jobs" && (l.activeJobsKey.value = a.address);
742
- l.mobileMenuOpen.value = !1, l.displayedTips.value = o, l.showTipModal.value = o.length > 0, a.address && !i && S(a.screen, a.address);
743
- }
744
- }, N = (e) => {
745
- l.activeScreen.value !== e && (l.activeScreen.value = e, S(C.SCREEN, e));
746
- }, P = (e) => {
747
- d(e), e == "settings" ? _("settings", "Settings", "settings") : e == "profile" && _("profile", "Profile", "profile");
748
- };
749
- return {
750
- get activeScreen() {
751
- return l.activeScreen;
752
- },
753
- get activeSidebarScreen() {
754
- return l.activeSidebarScreen;
755
- },
756
- get activeEditor() {
757
- return l.activeEditor;
758
- },
759
- get activeDashboard() {
760
- return l.activeDashboard;
761
- },
762
- get activeConnectionKey() {
763
- return l.activeConnectionKey;
764
- },
765
- get activeModelKey() {
766
- return l.activeModelKey;
767
- },
768
- get activeCommunityModelKey() {
769
- return l.activeCommunityModelKey;
770
- },
771
- get activeJobsKey() {
772
- return l.activeJobsKey;
773
- },
774
- get activeDocumentationKey() {
775
- return l.activeDocumentationKey;
776
- },
777
- get activeLLMConnectionKey() {
778
- return l.activeLLMConnectionKey;
779
- },
780
- get modelImport() {
781
- return l.modelImport;
782
- },
783
- get connectionImport() {
784
- return l.connectionImport;
785
- },
786
- get mobileMenuOpen() {
787
- return l.mobileMenuOpen;
788
- },
789
- get initialSearch() {
790
- return l.initialSearch;
791
- },
792
- get tabs() {
793
- return l.tabs;
794
- },
795
- get activeTab() {
796
- return l.activeTab;
797
- },
798
- get showTipModal() {
799
- return l.showTipModal;
800
- },
801
- get displayedTips() {
802
- return l.displayedTips;
803
- },
804
- get fullScreen() {
805
- return l.fullScreen;
806
- },
807
- setActiveScreen: N,
808
- setActiveSidebarScreen: P,
809
- setActiveEditor: (e) => {
810
- if (e === null) {
811
- b(C.EDITORS), l.activeEditor.value = "";
812
- return;
813
- }
814
- _("editors", null, e);
815
- },
816
- setActiveDashboard: (e) => {
817
- if (e === null) {
818
- b(C.DASHBOARD), l.activeDashboard.value = "";
819
- return;
820
- }
821
- _("dashboard", null, e);
822
- },
823
- setActiveConnectionKey: (e) => {
824
- if (e === null) {
825
- b(C.CONNECTIONS), l.activeConnectionKey.value = "";
826
- return;
827
- }
828
- _("connections", null, e);
829
- },
830
- setActiveDocumentationKey: (e) => {
831
- if (e === null) {
832
- b(C.TUTORIAL), l.activeDocumentationKey.value = "";
833
- return;
834
- }
835
- let t = e.split("+");
836
- _("tutorial", t[t.length - 1], e);
837
- },
838
- setActiveLLMConnectionKey: (e) => {
839
- if (e === null) {
840
- b(C.LLMS), l.activeLLMConnectionKey.value = "";
841
- return;
842
- }
843
- _("llms", null, e);
844
- },
845
- setActiveCommunityModelKey: (e) => {
846
- if (e === null) {
847
- b(C.COMMUNITY_MODELS), l.activeCommunityModelKey.value = "";
848
- return;
849
- }
850
- l.activeCommunityModelKey.value = e, _("community-models", null, e);
851
- },
852
- setActiveJobsKey: (e) => {
853
- if (e === null) {
854
- b(C.JOBS), l.activeJobsKey.value = "";
855
- return;
856
- }
857
- l.activeJobsKey.value = e, _("jobs", null, e);
858
- },
859
- toggleMobileMenu: () => {
860
- l.mobileMenuOpen.value = !l.mobileMenuOpen.value;
861
- },
862
- setActiveModelKey: (e) => {
863
- if (e === null) {
864
- b(C.MODELS);
865
- return;
866
- }
867
- S(C.MODELS, e), l.activeModelKey.value = e;
868
- },
869
- setActiveTab: M,
870
- openTab: _,
871
- updateTabName: g,
872
- closeTab: w,
873
- closeOtherTabsExcept: T,
874
- closeTabsToRightOf: j,
875
- onInitialLoad: () => {
876
- let e = l.modelImport.value, t = l.connectionImport.value, r = "editors", i = !1;
877
- x(C.SKIP_TIPS, "") === "true" && n.updateSetting("skipAllTips", !0);
878
- let a = x(C.ASSET_TYPE, ""), o = x(C.ASSET_NAME, ""), s = x(C.DASHBOARD, ""), c = [
879
- "true",
880
- "1",
881
- "yes"
882
- ].includes(x(C.REMOTE, "").toLowerCase()) && !!x(C.STORE, "") && !!(o || s);
883
- (e && t || c) && (a && o ? _("asset-import", null, "asset-import") : _("dashboard-import", null, "dashboard-import"), i = !0);
884
- let u = l.activeScreen.value, d = l.activeSidebarScreen.value, f = [];
885
- l.activeEditor.value && !i && f.push({
886
- screen: "editors",
887
- title: null,
888
- key: l.activeEditor.value,
889
- isActive: u === "editors"
890
- }), l.activeDashboard.value && !i && f.push({
891
- screen: "dashboard",
892
- title: null,
893
- key: l.activeDashboard.value,
894
- isActive: u === "dashboard"
895
- }), l.activeConnectionKey.value && !i && f.push({
896
- screen: "connections",
897
- title: null,
898
- key: l.activeConnectionKey.value,
899
- isActive: u === "connections"
900
- }), l.activeModelKey.value && !i && f.push({
901
- screen: "models",
902
- title: null,
903
- key: l.activeModelKey.value,
904
- isActive: u === "models"
905
- }), l.activeCommunityModelKey.value && !i && f.push({
906
- screen: "community-models",
907
- title: null,
908
- key: l.activeCommunityModelKey.value,
909
- isActive: u === "community-models"
910
- }), l.activeJobsKey.value && !i && f.push({
911
- screen: "jobs",
912
- title: null,
913
- key: l.activeJobsKey.value,
914
- isActive: u === "jobs"
915
- }), l.activeDocumentationKey.value && !i && f.push({
916
- screen: "tutorial",
917
- title: null,
918
- key: l.activeDocumentationKey.value,
919
- isActive: u === "tutorial"
920
- }), l.activeLLMConnectionKey.value && !i && f.push({
921
- screen: "llms",
922
- title: null,
923
- key: l.activeLLMConnectionKey.value,
924
- isActive: u === "llms"
925
- }), l.activeSidebarScreen.value === "settings" && f.push({
926
- screen: "settings",
927
- title: "Settings",
928
- key: "settings",
929
- isActive: u === "settings"
930
- }), l.activeSidebarScreen.value === "profile" && f.push({
931
- screen: "profile",
932
- title: "Profile",
933
- key: "profile",
934
- isActive: u === "profile"
935
- }), f.sort((e, t) => e.isActive ? 1 : t.isActive ? -1 : 0), f.forEach((e) => {
936
- _(e.screen, e.title, e.key, !0);
937
- }), N(u), !d && f.length > 0 ? r = f[f.length - 1].screen : d && (r = d), P(r);
938
- },
939
- toggleFullScreen: (e) => {
940
- l.fullScreen.value = e;
941
- },
942
- addBackListeners: () => {
943
- c ||= window.addEventListener("hashchange", () => {
944
- let e = x(C.EDITORS, ""), t = x(C.DASHBOARD, ""), n = x(C.CONNECTIONS, ""), r = x(C.MODELS, ""), i = x(C.COMMUNITY_MODELS, ""), a = x(C.JOBS, ""), o = x(C.TUTORIAL, ""), s = x(C.LLMS, ""), c = x(C.SCREEN, ""), u = x(C.SIDEBAR_SCREEN, ""), d = !1;
945
- u !== l.activeSidebarScreen.value && P(u), c !== l.activeScreen.value && (l.activeScreen.value = c, d = !0);
946
- let f = [
947
- {
948
- hash: e,
949
- screen: "editors",
950
- current: l.activeEditor.value
951
- },
952
- {
953
- hash: t,
954
- screen: "dashboard",
955
- current: l.activeDashboard.value
956
- },
957
- {
958
- hash: n,
959
- screen: "connections",
960
- current: l.activeConnectionKey.value
961
- },
962
- {
963
- hash: r,
964
- screen: "models",
965
- current: l.activeModelKey.value
966
- },
967
- {
968
- hash: i,
969
- screen: "community-models",
970
- current: l.activeCommunityModelKey.value
971
- },
972
- {
973
- hash: a,
974
- screen: "jobs",
975
- current: l.activeJobsKey.value
976
- },
977
- {
978
- hash: o,
979
- screen: "tutorial",
980
- current: l.activeDocumentationKey.value
981
- },
982
- {
983
- hash: s,
984
- screen: "llms",
985
- current: l.activeLLMConnectionKey.value
986
- }
987
- ];
988
- for (let { hash: e, screen: t, current: n } of f) if (e && e !== n || t === c && d) {
989
- let n = l.tabs.value.find((n) => n.screen === t && n.screen === c && n.address === e);
990
- if (n && n.id !== l.activeTab.value) {
991
- M(n.id, !0);
992
- break;
993
- }
994
- if (!n && e) {
995
- _(t, null, e);
996
- break;
997
- }
998
- }
999
- });
1000
- },
1001
- removeBacklisteners: () => {
1002
- c &&= (window.removeEventListener("hashchange", c), null);
1003
- }
1004
- };
1005
- }, H = null;
1006
- function U() {
1007
- return H ||= V(), H;
1008
- }
1009
- //#endregion
1010
- //#region stores/useMobileSidebarNavigation.ts
1011
- var W = () => {
1012
- let e = E(!1), t = E(""), n = E([]), r = E(!1), i = () => {
1013
- for (; n.value.length;) n.value.pop()?.onBack();
1014
- };
1015
- return {
1016
- level: T(() => e.value ? "detail" : "root"),
1017
- title: T(() => e.value ? r.value ? t.value : n.value[n.value.length - 1]?.title || t.value : ""),
1018
- depth: T(() => n.value.length),
1019
- canGoBack: T(() => e.value),
1020
- searchActive: r,
1021
- enterDestination(n) {
1022
- i(), t.value = n, e.value = !0;
1023
- },
1024
- push(e) {
1025
- n.value.push(e);
1026
- },
1027
- back() {
1028
- let t = n.value.pop();
1029
- if (t) {
1030
- t.onBack();
1031
- return;
1032
- }
1033
- e.value = !1;
1034
- },
1035
- home() {
1036
- i(), e.value = !1;
1037
- }
1038
- };
1039
- }, G = null;
1040
- function K() {
1041
- return G ||= W(), G;
1042
- }
1043
- //#endregion
1044
- //#region editors/chartStatement.ts
1045
- var q = [
1046
- "line",
1047
- "bar",
1048
- "barh",
1049
- "point",
1050
- "area",
1051
- "headline",
1052
- "donut",
1053
- "heatmap",
1054
- "boxplot",
1055
- "treemap"
1056
- ], J = [
1057
- "linear",
1058
- "log",
1059
- "sqrt"
1060
- ];
1061
- function Y(e) {
1062
- return J.includes(e) ? e : void 0;
1063
- }
1064
- function X(e) {
1065
- for (let t of Object.keys(e)) e[t] === void 0 && delete e[t];
1066
- return e;
1067
- }
1068
- function Z(e, t) {
1069
- let n = e.x_fields ?? [], r = e.y_fields ?? [], i;
1070
- e.geo_field ? i = "geo-map" : q.includes(e.chart_type) ? i = e.chart_type : (i = "bar", t.push(`Unknown chart type '${e.chart_type}'; rendering as a bar chart.`));
1071
- let a = r[0] || n[0], o = a ? e.field_labels?.[a] : void 0;
1072
- return X({
1073
- chartType: i,
1074
- xField: n[0] || void 0,
1075
- yField: r[0] || void 0,
1076
- yField2: r[1] || void 0,
1077
- colorField: e.color_field || void 0,
1078
- sizeField: e.size_field || void 0,
1079
- groupField: e.group_field || void 0,
1080
- trellisField: e.x_trellis_field || void 0,
1081
- trellisRowField: e.y_trellis_field || void 0,
1082
- geoField: e.geo_field || void 0,
1083
- annotationField: e.annotation_field || void 0,
1084
- layerLabel: o || void 0
1085
- });
1086
- }
1087
- function Q(e) {
1088
- let t = e?.layers?.[0];
1089
- if (!e || !t) return null;
1090
- let n = [], r = X({
1091
- chartType: "bar",
1092
- hideLegend: e.hide_legend || void 0,
1093
- showTitle: e.show_title || void 0,
1094
- scaleX: Y(e.scale_x),
1095
- scaleY: Y(e.scale_y),
1096
- placements: e.placements?.length ? e.placements.filter((e) => e.kind === "hline" || e.kind === "vline").map((e) => ({
1097
- kind: e.kind,
1098
- value: e.value ?? 0,
1099
- label: e.label || void 0
1100
- })) : void 0
1101
- }), i = e.layers.map((e) => Z(e, n));
1102
- if (i.length === 1) {
1103
- let { layerLabel: e, ...t } = i[0];
1104
- return {
1105
- config: X({
1106
- ...r,
1107
- ...t
1108
- }),
1109
- warnings: n
1110
- };
1111
- }
1112
- return {
1113
- config: X({
1114
- ...r,
1115
- chartType: i[0].chartType,
1116
- layers: i
1117
- }),
1118
- warnings: n
1119
- };
1120
- }
1121
- //#endregion
1122
- //#region stores/queryExecutionService.ts
1123
- var ne = class {
1124
- connection;
1125
- constructor(e) {
1126
- this.connection = e;
1127
- }
1128
- get name() {
1129
- return this.connection.name;
1130
- }
1131
- get queryType() {
1132
- return this.connection.query_type;
1133
- }
1134
- isConnected() {
1135
- return this.connection.connected;
1136
- }
1137
- executeSql(e, t) {
1138
- return this.connection.query(e, t ?? null);
1139
- }
1140
- runScript(e) {
1141
- return this.connection.runScript(e);
1142
- }
1143
- listRegisteredFiles() {
1144
- return this.connection.listRegisteredFiles ? this.connection.listRegisteredFiles() : [];
1145
- }
1146
- }, $ = class {
1147
- connectionStore;
1148
- workingPathResolver;
1149
- sourcesResolver;
1150
- filesResolver;
1151
- constructor(e, t, n, r) {
1152
- this.connectionStore = e, this.workingPathResolver = t, this.sourcesResolver = n, this.filesResolver = r;
1153
- }
1154
- getConnection(e) {
1155
- let t = this.connectionStore.connections[e];
1156
- return t ? new ne(t) : null;
1157
- }
1158
- async ensureConnected(e) {
1159
- let t = this.connectionStore.connections[e];
1160
- if (!t) throw Error(`Connection ${e} not found.`);
1161
- t.connected || await this.connectionStore.resetConnection(e);
1162
- }
1163
- getConnectionSources(e) {
1164
- return this.sourcesResolver ? this.sourcesResolver(e) : this.connectionStore.getConnectionSources(e);
1165
- }
1166
- getConnectionWorkingPath(e) {
1167
- return this.workingPathResolver ? this.workingPathResolver(e) : null;
1168
- }
1169
- getConnectionRegisteredFiles(e) {
1170
- return this.filesResolver ? this.filesResolver(e) : null;
1171
- }
1172
- };
1173
- function re(e) {
1174
- return e.split(";").map((e) => e.trim()).filter((e) => e.length > 0);
1175
- }
1176
- function ie(e) {
1177
- let t = e.trim();
1178
- for (; t.length > 0;) if (t.startsWith("--")) {
1179
- let e = t.indexOf("\n");
1180
- t = e === -1 ? "" : t.slice(e + 1).trimStart();
1181
- } else if (t.startsWith("/*")) {
1182
- let e = t.indexOf("*/");
1183
- t = e === -1 ? "" : t.slice(e + 2).trimStart();
1184
- } else break;
1185
- let n = t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase();
1186
- return n ? [
1187
- "CREATE",
1188
- "DROP",
1189
- "ALTER",
1190
- "TRUNCATE",
1191
- "COPY",
1192
- "SET",
1193
- "ATTACH",
1194
- "DETACH",
1195
- "USE",
1196
- "BEGIN",
1197
- "COMMIT",
1198
- "ROLLBACK",
1199
- "VACUUM",
1200
- "ANALYZE",
1201
- "REINDEX",
1202
- "CHECKPOINT",
1203
- "PRAGMA"
1204
- ].includes(n) : !1;
1205
- }
1206
- function ae(e) {
1207
- return typeof e.getConnection == "function" && typeof e.ensureConnected == "function";
1208
- }
1209
- var oe = class {
1210
- trilogyResolver;
1211
- connectionProvider;
1212
- storeHistory;
1213
- eligibleCrossFilterFieldsCache = /* @__PURE__ */ new Map();
1214
- constructor(e, t, n = !0) {
1215
- this.trilogyResolver = e, this.connectionProvider = ae(t) ? t : new $(t), this.storeHistory = n;
1216
- }
1217
- resolveRegisteredFiles(e, t) {
1218
- return this.connectionProvider.getConnectionRegisteredFiles?.(e) ?? t.listRegisteredFiles();
1219
- }
1220
- async executeQueriesBatch(e, t, n, r = [], i, a = {}, o, s, c, l, u = !1, d) {
1221
- if (n === "python") return {
1222
- cancellation: {
1223
- cancel: () => {},
1224
- isActive: () => !1
1225
- },
1226
- resultPromise: Promise.resolve({
1227
- success: !1,
1228
- results: [],
1229
- executionTime: 0
1230
- })
1231
- };
1232
- let f = (/* @__PURE__ */ new Date()).getTime(), p = new AbortController();
1233
- return {
1234
- cancellation: {
1235
- cancel: () => p.abort(),
1236
- isActive: () => !p.signal.aborted
1237
- },
1238
- resultPromise: this.executeQueriesBatchInternal(e, t, n, r, i || [], a, f, p, o, s, c, l, u, d)
1239
- };
1240
- }
1241
- async executeQueriesBatchInternal(t, n, r, a = [], o, s = {}, c, l, u, d, f, p, m = !1, h) {
1242
- u && u();
1243
- let g = this.connectionProvider.getConnection(t);
1244
- if (!g) return {
1245
- success: !1,
1246
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1247
- results: n.map((n) => ({
1248
- success: !1,
1249
- generated_sql: "",
1250
- columns: [],
1251
- error: `Connection ${t} not found.`,
1252
- executionTime: 0,
1253
- results: new e(/* @__PURE__ */ new Map(), []),
1254
- resultSize: 0,
1255
- columnCount: 0
1256
- }))
1257
- };
1258
- if (m) return {
1259
- success: !0,
1260
- results: n.map((t) => ({
1261
- success: !0,
1262
- generated_sql: t.query,
1263
- columns: [],
1264
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1265
- results: new e(/* @__PURE__ */ new Map(), []),
1266
- resultSize: 0,
1267
- columnCount: 0
1268
- })),
1269
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c
1270
- };
1271
- if (!g.isConnected()) try {
1272
- d && d({
1273
- message: "Connection is not active... Attempting to automatically reconnect.",
1274
- error: !0
1275
- }), await this.connectionProvider.ensureConnected(t), d && d({
1276
- message: "Reconnect Successful",
1277
- running: !0
1278
- });
1279
- } catch {
1280
- return f && Object.values(f).forEach((e) => e({
1281
- message: "Connection failed to reconnect.",
1282
- error: !0,
1283
- running: !1
1284
- })), {
1285
- success: !1,
1286
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1287
- results: n.map((n) => ({
1288
- success: !1,
1289
- generated_sql: "",
1290
- columns: [],
1291
- error: `Connection ${t} not active, failed to reconnect.`,
1292
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1293
- results: new e(/* @__PURE__ */ new Map(), []),
1294
- columnCount: 0,
1295
- resultSize: 0
1296
- }))
1297
- };
1298
- }
1299
- let _ = this.connectionProvider.getConnectionSources(t);
1300
- h && (_ = _.concat(h));
1301
- let v = this.resolveRegisteredFiles(t, g), y = this.connectionProvider.getConnectionWorkingPath?.(t) ?? null;
1302
- try {
1303
- let s = await Promise.race([this.trilogyResolver.resolve_queries_batch(n, g.queryType, _, a, o, null, v.length > 0 ? v : null, y), new Promise((e, t) => {
1304
- l.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query batch cancelled by user")));
1305
- })]), u = [];
1306
- if (s && Array.isArray(s.data.queries)) for (let a = 0; a < s.data.queries.length; a++) {
1307
- let d = s.data.queries[a];
1308
- if (d.generated_sql) {
1309
- let s = {
1310
- ...n[a]?.parameters || {},
1311
- ...d.parameters || {}
1312
- }, m = Object.keys(s).length ? s : null;
1313
- try {
1314
- let e = await Promise.race([g.executeSql(d.generated_sql, m), new Promise((e, t) => {
1315
- l.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query execution cancelled by user")));
1316
- })]);
1317
- i(r) && this.enrichTrilogyColumns(d.columns || [], e);
1318
- let f = Q(d.chart), h = await this.executeChartLayers(g, d.chart, e, s, l, r), _ = {
1319
- success: !0,
1320
- generatedSql: d.generated_sql,
1321
- results: e,
1322
- resultSize: e.data.length,
1323
- columnCount: e.headers.size,
1324
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1325
- chartConfig: f?.config,
1326
- chartWarnings: f?.warnings.length ? f.warnings : void 0,
1327
- layers: h
1328
- };
1329
- p && d.label && p[d.label] && p[d.label](_), u.push(_), this.storeHistory && w(t).recordQuery({
1330
- query: n[a].query,
1331
- generatedQuery: d.generated_sql,
1332
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1333
- status: "success",
1334
- resultSize: e.data.length,
1335
- resultColumns: e.headers.size,
1336
- errorMessage: null,
1337
- extraFilters: o
1338
- });
1339
- } catch (r) {
1340
- let i = l.signal.aborted ? "Query execution cancelled by user" : r instanceof Error ? r.message : "Unknown error occurred during execution", s = {
1341
- success: !1,
1342
- error: i,
1343
- generatedSql: d.generated_sql,
1344
- results: new e(/* @__PURE__ */ new Map(), []),
1345
- resultSize: 0,
1346
- columnCount: 0,
1347
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c
1348
- };
1349
- u.push(s), console.error("Error callback for ", d.label, f), console.error("Error details:", r), f && d.label && f[d.label] && f[d.label](s), this.storeHistory && w(t).recordQuery({
1350
- query: n[a].query,
1351
- generatedQuery: d.generated_sql,
1352
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1353
- status: "error",
1354
- resultSize: 0,
1355
- resultColumns: 0,
1356
- errorMessage: i,
1357
- extraFilters: o
1358
- });
1359
- }
1360
- } else if (d.error) {
1361
- let t = {
1362
- success: !1,
1363
- error: d.error,
1364
- generatedSql: "",
1365
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1366
- results: new e(/* @__PURE__ */ new Map(), []),
1367
- resultSize: 0,
1368
- columnCount: 0
1369
- };
1370
- f && d.label && f[d.label] && f[d.label](t), u.push(t);
1371
- } else {
1372
- let t = {
1373
- success: !1,
1374
- error: "No SQL was generated for this query",
1375
- generatedSql: "",
1376
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1377
- results: new e(/* @__PURE__ */ new Map(), []),
1378
- resultSize: 0,
1379
- columnCount: 0
1380
- };
1381
- u.push(t), f && d.label && f[d.label] && f[d.label](t);
1382
- }
1383
- }
1384
- return {
1385
- success: !0,
1386
- results: u,
1387
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c
1388
- };
1389
- } catch (e) {
1390
- let t = l.signal.aborted ? "Query batch cancelled by user" : e instanceof Error ? e.message : "Unknown error occurred";
1391
- return f && Object.values(f).forEach((e) => e({
1392
- message: t,
1393
- error: !0,
1394
- running: !1
1395
- })), {
1396
- success: !1,
1397
- executionTime: (/* @__PURE__ */ new Date()).getTime() - c,
1398
- results: []
1399
- };
1400
- }
1401
- }
1402
- async formatQuery(e, t, n, r = [], i, a, o, s) {
1403
- if (n === "python") return e;
1404
- try {
1405
- let c = await this.trilogyResolver.format_query(e, t, n, i, r, null, null, a || null, o && o.length > 0 ? o : null, s ?? null);
1406
- return c.data && c.data.text ? c.data.text : null;
1407
- } catch (e) {
1408
- throw console.error("Error formatting query:", e), e;
1409
- }
1410
- }
1411
- async createDrilldownQuery(e, t, n, r = [], i, a, o, s, c, l, u) {
1412
- if (n === "python") return null;
1413
- try {
1414
- 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);
1415
- return d.data && d.data.text ? d.data.text : null;
1416
- } catch (e) {
1417
- throw console.error("Error creating drilldown query:", e), e;
1418
- }
1419
- }
1420
- async createConnectionDrilldownQuery(e, t, n, r = [], i, a, o, s, c) {
1421
- let l = this.connectionProvider.getConnection(e);
1422
- if (!l) throw Error(`Connection ${e} not found.`);
1423
- return this.createDrilldownQuery(t, l.queryType, n, r, i, a, o, s, c, this.resolveRegisteredFiles(e, l), this.connectionProvider.getConnectionWorkingPath?.(e) ?? null);
1424
- }
1425
- async generateQuery(e, t) {
1426
- let n = this.connectionProvider.getConnection(e);
1427
- if (!n) throw Error(`Connection ${e} not found.`);
1428
- let r = this.connectionProvider.getConnectionSources(e);
1429
- t.extraContent && (r = r.concat(t.extraContent));
1430
- let i = this.resolveRegisteredFiles(e, n), a = this.connectionProvider.getConnectionWorkingPath?.(e) ?? null;
1431
- 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);
1432
- }
1433
- async validateQuery(e, t, n = !0, r = null) {
1434
- if (t.editorType === "sql" || t.editorType === "python") return null;
1435
- try {
1436
- n && console.log(`Validating ${t.editorType} query`);
1437
- } catch (e) {
1438
- console.log(e);
1439
- }
1440
- let i = this.connectionProvider.getConnection(e);
1441
- if (!i) return null;
1442
- r ||= this.connectionProvider.getConnectionSources(e), t.extraContent && (r = r.concat(t.extraContent));
1443
- let a = this.resolveRegisteredFiles(e, i), o = this.connectionProvider.getConnectionWorkingPath?.(e) ?? null;
1444
- 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);
1445
- }
1446
- async getEligibleCrossFilterFields(e, t = {}) {
1447
- let r = this.connectionProvider.getConnection(e);
1448
- if (!r) throw Error(`Connection ${e} not found.`);
1449
- let i = t.imports ?? [], a = t.extraFilters ?? [], o = t.extraContent ?? [], s = this.connectionProvider.getConnectionSources(e).concat(o), c = JSON.stringify({
1450
- connectionId: e,
1451
- queryType: r.queryType,
1452
- imports: i,
1453
- extraFilters: a,
1454
- sources: s,
1455
- currentFilename: t.currentFilename ?? null
1456
- }), l = this.eligibleCrossFilterFieldsCache.get(c);
1457
- if (l) return [...l];
1458
- let u = n((await this.validateQuery(e, {
1459
- text: "select 1 as cross_filter_probe;",
1460
- editorType: "trilogy",
1461
- imports: i,
1462
- extraFilters: a,
1463
- extraContent: o,
1464
- currentFilename: t.currentFilename
1465
- }, !1))?.data.completion_items ?? []);
1466
- return this.eligibleCrossFilterFieldsCache.set(c, u), [...u];
1467
- }
1468
- clearEligibleCrossFilterFieldsCache() {
1469
- this.eligibleCrossFilterFieldsCache.clear();
1470
- }
1471
- async executeQuery(e, t, n, r, i, a, o = !1) {
1472
- let s = (/* @__PURE__ */ new Date()).getTime(), c = new AbortController();
1473
- return {
1474
- cancellation: {
1475
- cancel: () => c.abort(),
1476
- isActive: () => !c.signal.aborted
1477
- },
1478
- resultPromise: this.executeQueryInternal(e, t, s, c, n, r, i, a, o)
1479
- };
1480
- }
1481
- async executeQueryInternal(n, r, a, o, s, c, l, u, d = !1) {
1482
- let f = 0, p = 0, m = "";
1483
- if (r.editorType === "python") {
1484
- let e = "Python files are editable but cannot be run locally.";
1485
- return l && l({
1486
- message: e,
1487
- error: !0,
1488
- running: !1
1489
- }), {
1490
- success: !1,
1491
- error: e,
1492
- executionTime: 0,
1493
- resultSize: 0,
1494
- columnCount: 0
1495
- };
1496
- }
1497
- s && s();
1498
- let h = this.connectionProvider.getConnection(n);
1499
- if (!h) return l && l({
1500
- message: `Connection ${n} not found.`,
1501
- error: !0,
1502
- running: !1
1503
- }), {
1504
- success: !1,
1505
- error: `Connection ${n} not found.`,
1506
- executionTime: 0,
1507
- resultSize: 0,
1508
- columnCount: 0
1509
- };
1510
- if (!h.isConnected() && !d) try {
1511
- c && c({
1512
- message: "Connection is not active... Attempting to automatically reconnect.",
1513
- error: !0
1514
- }), await this.connectionProvider.ensureConnected(n), c && c({
1515
- message: "Reconnect Successful",
1516
- running: !0
1517
- });
1518
- } catch {
1519
- return l && l({
1520
- message: "Connection failed to reconnect.",
1521
- error: !0,
1522
- running: !1
1523
- }), {
1524
- success: !1,
1525
- error: "Connection is not active.",
1526
- executionTime: 0,
1527
- resultSize: 0,
1528
- columnCount: 0
1529
- };
1530
- }
1531
- if (r.editorType === "sql") try {
1532
- let t = re(r.text);
1533
- if (t.length === 0) {
1534
- let t = {
1535
- success: !0,
1536
- generatedSql: r.text,
1537
- results: new e(/* @__PURE__ */ new Map(), []),
1538
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1539
- resultSize: 0,
1540
- columnCount: 0
1541
- };
1542
- return u && u(t), t;
1543
- }
1544
- if (t.length > 1) {
1545
- let e = t.slice(0, -1).join(";\n") + ";";
1546
- await Promise.race([h.runScript(e), new Promise((e, t) => {
1547
- o.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
1548
- })]);
1549
- }
1550
- let i = t[t.length - 1], s;
1551
- ie(i) ? (await Promise.race([h.runScript(i), new Promise((e, t) => {
1552
- o.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
1553
- })]), s = new e(/* @__PURE__ */ new Map(), [])) : s = await Promise.race([h.executeSql(i, r.parameters ?? null), new Promise((e, t) => {
1554
- o.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
1555
- })]);
1556
- let c = {
1557
- success: !0,
1558
- generatedSql: r.text,
1559
- results: s,
1560
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1561
- resultSize: s.data.length,
1562
- columnCount: s.headers.size
1563
- };
1564
- return this.storeHistory && w(n).recordQuery({
1565
- query: r.text,
1566
- generatedQuery: r.text,
1567
- executionTime: c.executionTime,
1568
- status: "success",
1569
- resultSize: c.resultSize,
1570
- resultColumns: c.columnCount,
1571
- errorMessage: null,
1572
- extraFilters: r.extraFilters
1573
- }), u && u(c), c;
1574
- } catch (e) {
1575
- let t = e instanceof Error ? e.message : String(e);
1576
- return l && l({
1577
- message: t,
1578
- error: !0,
1579
- running: !1
1580
- }), {
1581
- success: !1,
1582
- error: t,
1583
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1584
- resultSize: 0,
1585
- columnCount: 0
1586
- };
1587
- }
1588
- let g = this.connectionProvider.getConnectionSources(n);
1589
- r.extraContent && (g = g.concat(r.extraContent));
1590
- let _ = this.resolveRegisteredFiles(n, h), v = this.connectionProvider.getConnectionWorkingPath?.(n) ?? null, y = null;
1591
- try {
1592
- if (y = await Promise.race([this.trilogyResolver.resolve_query(r.text, h.queryType, r.editorType, g, r.imports, r.extraFilters, r.parameters, r.currentFilename || null, _.length > 0 ? _ : null, v), new Promise((e, t) => {
1593
- o.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
1594
- })]), y && y.data.generated_output) {
1595
- let n = y.data.columns || [], r = {
1596
- success: !0,
1597
- generatedSql: y.data.generated_sql,
1598
- results: new e(new Map(n.map((e) => [e.name, {
1599
- name: e.name,
1600
- type: t.STRING,
1601
- purpose: e.purpose
1602
- }])), y.data.generated_output),
1603
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1604
- resultSize: y.data.generated_output.length,
1605
- columnCount: n.length,
1606
- selectCount: y.data.select_count
1607
- };
1608
- return console.log(r), u && u(r), r;
1609
- } else if (!y || !y.data.generated_sql || d) {
1610
- let t = {
1611
- success: !0,
1612
- results: new e(/* @__PURE__ */ new Map(), []),
1613
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1614
- resultSize: 0,
1615
- columnCount: 0
1616
- };
1617
- return u && u(t), t;
1618
- }
1619
- m = y.data.generated_sql;
1620
- let s = Q(y.data.chart), c = y.data.columns, l = {
1621
- ...r.parameters || {},
1622
- ...y.data.parameters || {}
1623
- }, b = Object.keys(l).length ? l : null, x = await Promise.race([h.executeSql(m, b), new Promise((e, t) => {
1624
- o.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
1625
- })]);
1626
- i(r.editorType) && this.enrichTrilogyColumns(c, x), f = x.data.length, p = x.headers.size, this.storeHistory && w(n).recordQuery({
1627
- query: r.text,
1628
- generatedQuery: m,
1629
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1630
- status: "success",
1631
- resultSize: f,
1632
- resultColumns: p,
1633
- errorMessage: null,
1634
- extraFilters: r.extraFilters
1635
- });
1636
- let S = await this.executeChartLayers(h, y.data.chart, x, l, o, r.editorType), C = y?.data.select_count, T = {
1637
- success: !0,
1638
- generatedSql: m,
1639
- results: x,
1640
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1641
- resultSize: f,
1642
- columnCount: p,
1643
- selectCount: C,
1644
- chartConfig: s?.config,
1645
- chartWarnings: s?.warnings.length ? s.warnings : void 0,
1646
- layers: S
1647
- };
1648
- return u && u(T), T;
1649
- } catch (e) {
1650
- console.error("[query catch] raw error:", e, "type:", typeof e, "ctor:", e?.constructor?.name);
1651
- let t = o.signal.aborted ? "Query cancelled by user" : e instanceof Error ? e.message : typeof e == "string" ? e : (() => {
1652
- try {
1653
- return `Unknown error: ${JSON.stringify(e)}`;
1654
- } catch {
1655
- return `Unknown error: ${String(e)}`;
1656
- }
1657
- })();
1658
- return this.storeHistory && w(n).recordQuery({
1659
- query: r.text,
1660
- generatedQuery: m,
1661
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1662
- status: "error",
1663
- resultSize: f,
1664
- resultColumns: p,
1665
- errorMessage: t
1666
- }), l && l({
1667
- message: t,
1668
- error: !0,
1669
- running: !1,
1670
- generatedSql: m
1671
- }), {
1672
- success: !1,
1673
- error: t,
1674
- executionTime: (/* @__PURE__ */ new Date()).getTime() - a,
1675
- resultSize: f,
1676
- columnCount: p
1677
- };
1678
- }
1679
- }
1680
- async executeChartLayers(t, n, r, a, o, s) {
1681
- let c = n?.layers;
1682
- if (!c || c.length < 2) return;
1683
- let l = [r];
1684
- for (let n = 1; n < c.length; n++) {
1685
- let r = c[n];
1686
- if (!r.generated_sql) {
1687
- l.push(new e(/* @__PURE__ */ new Map(), []));
1688
- continue;
1689
- }
1690
- let u = {
1691
- ...a,
1692
- ...r.parameters || {}
1693
- }, d = await Promise.race([t.executeSql(r.generated_sql, Object.keys(u).length ? u : null), new Promise((e, t) => {
1694
- o.signal.addEventListener("abort", () => t(/* @__PURE__ */ Error("Query cancelled by user")));
1695
- })]);
1696
- i(s) && this.enrichTrilogyColumns(r.columns || [], d), l.push(d);
1697
- }
1698
- return l;
1699
- }
1700
- enrichTrilogyColumns(e, t) {
1701
- for (let n = 0; n < e.length; n++) {
1702
- let r = e[n], i = t.headers.get(r.name.replace("local.", "").replaceAll(".", "_"));
1703
- i && (i.traits = r.traits || [], i.address = r.name, i.purpose = r.purpose, i.keys = r.keys || [], t.headers.set(i.name, i));
1704
- }
1705
- }
1706
- };
1707
- //#endregion
1708
- export { B as a, U as i, oe as n, te as o, K as r, M as s, $ as t };