@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
@@ -1,972 +0,0 @@
1
- import { on as e, sn as t } from "./editorRefinementToolExecutor-mX8ClQ63.js";
2
- import { C as n, D as r, M as i, S as a, i as o, t as s, w as c, x as l } from "./editorRefinementRuntime-C_YmXRy4.js";
3
- import { s as u } from "./base-C8IuZWqY.js";
4
- import { r as d, t as f } from "./connections-CJSb1TZl.js";
5
- import { a as p, i as m, o as h, s as g, t as _ } from "./remoteWorker-Dkv3TJ0j.js";
6
- import "./llm-_807I79k.js";
7
- import { reactive as v } from "vue";
8
- import { defineStore as y } from "pinia";
9
- //#region stores/modelStore.ts
10
- var b = y("models", {
11
- state: () => ({ models: {} }),
12
- getters: {
13
- modelList: (e) => Object.keys(e.models).map((t) => e.models[t]),
14
- unsavedModels: (e) => Object.values(e.models).filter((e) => e.changed).length
15
- },
16
- actions: {
17
- newModelConfig(t, n = !1) {
18
- let r = new e({
19
- name: t,
20
- storage: "local",
21
- sources: [],
22
- description: ""
23
- });
24
- if (t in this.models && !n) throw Error(`ModelConfig with ${t} already exists.`);
25
- return this.models[r.name] = r, r;
26
- },
27
- addModelConfig(e) {
28
- this.models[e.name] = e;
29
- },
30
- removeModelConfig(e) {
31
- if (this.models[e]) Q().connectionList.forEach((t) => {
32
- t.model === e && (t.model = null, t.changed = !0);
33
- }), delete this.models[e];
34
- else throw Error(`ModelConfig with name "${e}" not found.`);
35
- },
36
- updateModelName(e, t) {
37
- e !== t && (console.log(`Renaming model from ${e} to ${t}`), Q().connectionList.forEach((n) => {
38
- n.model === e && (n.model = t, n.changed = !0);
39
- }), this.models[t] = this.models[e], this.models[t].name = t, this.models[t].changed = !0, delete this.models[e]);
40
- },
41
- addEditorAsModelSource(e, n) {
42
- this.addModelConfigSource(e, new t(n.id, n.name, [], []));
43
- },
44
- addModelConfigSource(e, t) {
45
- if (this.models[e]) this.models[e].sources.push(t);
46
- else throw Error(`ModelConfig with name "${e}" not found.`);
47
- },
48
- removeModelConfigSource(e, t) {
49
- if (this.models[e]) {
50
- let n = this.models[e];
51
- n.sources = n.sources.filter((e) => e.alias !== t);
52
- } else throw Error(`ModelConfig with name "${e}" not found.`);
53
- },
54
- setModelConfigParseResults(e, t) {
55
- if (this.models[e]) {
56
- let n = this.models[e];
57
- n.setParseResults(t), n.sources = [...n.sources], this.models = { ...this.models };
58
- } else throw Error(`ModelConfig with name "${e}" not found.`);
59
- },
60
- setModelParseError(e, t) {
61
- if (this.models[e]) this.models[e].setParseError(t), this.models = { ...this.models };
62
- else throw Error(`ModelConfig with name "${e}" not found.`);
63
- }
64
- }
65
- }), x = class {
66
- type;
67
- constructor() {
68
- this.type = "abstract";
69
- }
70
- async saveProjects(e) {}
71
- async loadProjects() {
72
- return {};
73
- }
74
- async deleteProject(e) {}
75
- async clearProjects() {}
76
- }, S = (e) => new Promise((t) => setTimeout(t, e)), ee = /* @__PURE__ */ new Set(), te = /* @__PURE__ */ new Set(), ne = (e) => {
77
- if (ee.has(e)) return !0;
78
- let t = e;
79
- e.includes("://") || (t = `http://${e}`);
80
- try {
81
- let e = new URL(t), n = e.host, r = e.hostname;
82
- if (te.has(n) || te.has(r)) return !0;
83
- } catch {}
84
- return !1;
85
- }, C = async (e, t, n = 5, r = 1e3) => {
86
- if (ne(e)) throw Error(`Cannot connect to ${e} - blocked by Content Security Policy. This URL is not allowed by the browser's security settings.`);
87
- let i = 0, a = r;
88
- for (;;) try {
89
- let r = await fetch(e, t);
90
- if (r.status === 429 && i < n) {
91
- let e = r.headers.get("Retry-After"), t = e ? parseInt(e) * 1e3 : a;
92
- console.log(`Rate limited. Retrying after ${t}ms (Attempt ${i + 1}/${n})`), await S(t), a = a * 2 * (.8 + Math.random() * .4), i++;
93
- continue;
94
- }
95
- return r;
96
- } catch (t) {
97
- if (ne(e)) throw Error(`Cannot connect to ${e} - blocked by Content Security Policy. This URL is not allowed by the browser's security settings.`);
98
- let r = t instanceof Error ? t.message : String(t);
99
- if (t instanceof TypeError || r.includes("Failed to fetch") || r.includes("NetworkError") || r.includes("ERR_CONNECTION_REFUSED") || r.includes("Load failed") || r.includes("network connection was lost") || r.includes("Could not connect to the server") || r.includes("fetch failed") || i >= n) throw t;
100
- console.log(`Network error, retrying after ${a}ms (Attempt ${i + 1}/${n})`), await S(a), a = a * 2 * (.8 + Math.random() * .4), i++;
101
- }
102
- }, re = (e, t, n, r, i) => e.filter((e) => {
103
- let a = e.name.toLowerCase().includes(t.toLowerCase()), o = !n || e.engine === n, s = !0;
104
- if (r !== "all") {
105
- let t = i(e.name);
106
- s = r === "imported" && t || r === "not-imported" && !t;
107
- }
108
- return a && o && s;
109
- }), ie = (e) => {
110
- switch (e) {
111
- case "bigquery": return "new-bigquery-oauth";
112
- case "duckdb": return "new-duckdb";
113
- default: return `new-${e}`;
114
- }
115
- }, ae = (e) => {
116
- let t = /* @__PURE__ */ new Set();
117
- return e.forEach((e) => {
118
- e.engine && t.add(e.engine);
119
- }), Array.from(t).sort();
120
- }, w = (e) => {
121
- if (e) return { headers: { "X-Trilogy-Token": e } };
122
- }, T = async (e) => {
123
- let t = await C(`${e.baseUrl}/index.json`, w(e.token));
124
- if (!t.ok) throw Error(`Failed to fetch store index: ${t.status} ${t.statusText}`);
125
- return t.json();
126
- }, oe = async (e) => {
127
- let t = null, n = [];
128
- try {
129
- let t = (await T(e)).models.map(async (t) => {
130
- try {
131
- let n = await C(t.url, w(e.token));
132
- if (!n.ok) return console.warn(`Failed to fetch model ${t.name}: ${n.statusText}`), null;
133
- let r = await n.json();
134
- return r.downloadUrl = t.url, r.store = e, r;
135
- } catch (e) {
136
- return console.warn(`Error fetching model ${t.name}:`, e), null;
137
- }
138
- });
139
- n = (await Promise.all(t)).filter((e) => e !== null);
140
- } catch (e) {
141
- t = e instanceof Error ? e.message : "Error fetching store data", console.error("Error fetching from generic store:", e);
142
- }
143
- return {
144
- files: n,
145
- error: t
146
- };
147
- }, se = async (e) => {
148
- let t = null, n = [];
149
- try {
150
- let t, r;
151
- e.owner === "trilogy-data" && e.repo === "trilogy-public-models" ? (t = "https://trilogy-data.github.io/trilogy-public-models/studio/index.json", r = "https://trilogy-data.github.io/trilogy-public-models/studio/") : (t = `https://api.github.com/repos/${e.owner}/${e.repo}/contents/studio/index.json?ref=${e.branch}`, r = `https://raw.githubusercontent.com/${e.owner}/${e.repo}/${e.branch}/studio/`);
152
- let i = await C(t);
153
- if (i.status !== 200) throw Error(`Error fetching community data: ${await i.text()}`);
154
- let a;
155
- if (e.owner === "trilogy-data" && e.repo === "trilogy-public-models") a = await i.json();
156
- else {
157
- let e = await i.json();
158
- a = JSON.parse(atob(e.content));
159
- }
160
- let o = a.files.filter((e) => e.filename.endsWith(".json")).map(async (t) => {
161
- let n = `${r}${t.filename}`, i = await C(n);
162
- if (!i.ok) throw Error(`Error fetching file ${t.filename}: ${i.statusText}`);
163
- let a = await i.json();
164
- return a.downloadUrl = n, a.store = e, a;
165
- });
166
- n = await Promise.all(o);
167
- } catch (e) {
168
- t = e instanceof Error ? e.message : "Error fetching files", console.error("Error fetching from GitHub store:", e);
169
- }
170
- return {
171
- files: n,
172
- error: t
173
- };
174
- }, E = async (e) => e.type === "github" ? se(e) : oe(e), ce = async (e, t) => {
175
- let n = {}, r = {};
176
- return await Promise.all(e.map(async (e) => {
177
- try {
178
- let { files: i, error: a } = await E(e);
179
- n[e.id] = i, a && (r[e.id] = a), t && t(e.id, {
180
- files: i,
181
- error: a
182
- });
183
- } catch (i) {
184
- let a = i instanceof Error ? i.message : "Unknown error";
185
- r[e.id] = a, n[e.id] = [], t && t(e.id, {
186
- files: [],
187
- error: a
188
- });
189
- }
190
- })), {
191
- filesByStore: n,
192
- errors: r
193
- };
194
- }, le = {
195
- stale: 3,
196
- unknown: 2,
197
- fresh: 1
198
- }, D = (e) => le[e] ?? 0, ue = (e) => e.observed_watermarks.reduce((e, t) => e ? t.probed_at > e.probed_at ? t : e : t, null), O = (e) => {
199
- let t = e.datasources.reduce((e, t) => !e || D(t.status) > D(e) ? t.status : e, null);
200
- return t && D(t) > D(e.status) ? t : e.status;
201
- }, de = (e) => e.partition_by.map((e) => e.column), fe = (e) => {
202
- let t = Object.entries(e.values).map(([e, t]) => `${e}=${t ?? "—"}`);
203
- return t.length ? t.join(", ") : e.partition_id;
204
- }, pe = (e) => {
205
- let t = {
206
- total: e.partitions.length,
207
- fresh: 0,
208
- stale: 0,
209
- unknown: 0,
210
- missing: 0,
211
- rowCount: null,
212
- complete: e.partitions_complete
213
- };
214
- return e.partitions.forEach((e) => {
215
- e.status === "fresh" ? t.fresh += 1 : e.status === "stale" ? t.stale += 1 : t.unknown += 1, e.expected && !e.observed && (t.missing += 1), typeof e.row_count == "number" && (t.rowCount = (t.rowCount ?? 0) + e.row_count);
216
- }), t;
217
- }, me = (e) => [...e].sort((e, t) => {
218
- let n = D(t.status) - D(e.status);
219
- if (n !== 0) return n;
220
- let r = Number(!e.observed) - Number(!t.observed);
221
- return r === 0 ? e.partition_id.localeCompare(t.partition_id) : -r;
222
- }), he = (e) => [...e].sort((e, t) => {
223
- let n = D(O(t)) - D(O(e));
224
- return n === 0 ? e.address.localeCompare(t.address) : n;
225
- }), k = "::", ge = (e, t) => `${e}${k}${t || "."}`, _e = (e) => {
226
- let t = e.indexOf(k);
227
- return t === -1 ? null : {
228
- storeId: e.slice(0, t),
229
- target: e.slice(t + 2)
230
- };
231
- }, A = (e) => e || ".", ve = (e, t) => {
232
- let n = A(e), r = A(t);
233
- return n === r || n === "." || r.startsWith(`${n}/`);
234
- }, j = class extends Error {
235
- status;
236
- constructor(e, t) {
237
- super(e), this.name = "JobsServiceError", this.status = t;
238
- }
239
- }, M = (e, t = {}) => {
240
- let n = new Headers(t.headers);
241
- return e && n.set("X-Trilogy-Token", e), {
242
- ...t,
243
- headers: n
244
- };
245
- }, N = (e) => e.split("/").filter(Boolean).map((e) => encodeURIComponent(e)).join("/"), P = async (e, t) => {
246
- if (e.ok) return e;
247
- let n = "";
248
- try {
249
- if ((e.headers.get("content-type") || "").includes("application/json")) {
250
- let t = await e.json();
251
- n = typeof t?.detail == "string" ? t.detail : typeof t?.message == "string" ? t.message : JSON.stringify(t);
252
- } else n = await e.text();
253
- } catch {
254
- n = "";
255
- }
256
- throw new j(n || t, e.status);
257
- }, F = async (e) => {
258
- let t = await fetch(`${e.baseUrl}/files`, M(e.token, { method: "GET" }));
259
- return await P(t, `Failed to fetch files for ${e.name}`), t.json();
260
- }, ye = async (e, t) => {
261
- let n = N(t), r = await fetch(`${e.baseUrl}/files/${n}`, M(e.token, { method: "GET" }));
262
- return await P(r, `Failed to fetch ${t}`), r.text();
263
- }, I = async (e, t, n) => {
264
- let r = await fetch(`${e.baseUrl}/files`, M(e.token, {
265
- method: "POST",
266
- headers: { "Content-Type": "application/json" },
267
- body: JSON.stringify({
268
- path: t,
269
- content: n
270
- })
271
- }));
272
- if (r.status === 409) {
273
- await L(e, t, n);
274
- return;
275
- }
276
- await P(r, `Failed to create ${t}`);
277
- }, L = async (e, t, n) => {
278
- let r = await fetch(`${e.baseUrl}/files/${N(t)}`, M(e.token, {
279
- method: "PUT",
280
- headers: { "Content-Type": "application/json" },
281
- body: JSON.stringify({ content: n })
282
- }));
283
- if (r.status === 404) {
284
- await P(await fetch(`${e.baseUrl}/files`, M(e.token, {
285
- method: "POST",
286
- headers: { "Content-Type": "application/json" },
287
- body: JSON.stringify({
288
- path: t,
289
- content: n
290
- })
291
- })), `Failed to update ${t}`);
292
- return;
293
- }
294
- await P(r, `Failed to update ${t}`);
295
- }, R = async (e, t) => {
296
- let n = await fetch(`${e.baseUrl}/files/${N(t)}`, M(e.token, { method: "DELETE" }));
297
- n.status !== 404 && await P(n, `Failed to delete ${t}`);
298
- }, be = async (e, t, n = !1) => {
299
- let r = new URLSearchParams({ target: A(t) });
300
- n && r.set("refresh", "true");
301
- let i = await fetch(`${e.baseUrl}/state?${r.toString()}`, M(e.token, { method: "GET" }));
302
- await P(i, `Failed to fetch state for ${A(t)}`);
303
- let a = i.headers.get("X-Trilogy-Cached");
304
- return {
305
- snapshot: await i.json(),
306
- cached: a === null ? null : a.toLowerCase() === "true",
307
- computedAt: i.headers.get("X-Trilogy-Computed-At")
308
- };
309
- }, xe = async (e, t, n) => {
310
- let r = await fetch(`${e.baseUrl}/${t}`, M(e.token, {
311
- method: "POST",
312
- headers: { "Content-Type": "application/json" },
313
- body: JSON.stringify({ target: n })
314
- }));
315
- return await P(r, `Failed to ${t} ${n}`), r.json();
316
- }, Se = async (e, t) => {
317
- let n = await fetch(`${e.baseUrl}/jobs/${t}`, M(e.token, { method: "GET" }));
318
- return await P(n, `Failed to fetch job ${t}`), n.json();
319
- }, Ce = async (e, t) => {
320
- let n = await fetch(`${e.baseUrl}/jobs/${t}/cancel`, M(e.token, { method: "POST" }));
321
- return await P(n, `Failed to cancel job ${t}`), n.json();
322
- }, z = (e) => e.trim().replace(/[\\/:*?"<>|]+/g, "-").replace(/\s+/g, " "), B = (e) => e.replace(/\/$/, ""), V = (e) => B(e).replace(/^https?:\/\//, "").replace(/\//g, "-"), H = (e) => {
323
- try {
324
- let t = new URL(B(e));
325
- return z(t.hostname + (t.port ? `:${t.port}` : "") || t.host || e);
326
- } catch {
327
- return z(B(e));
328
- }
329
- }, U = (e) => z(e.name || H(e.baseUrl)), W = (e) => `${U(e)}-connection`, G = (e) => U(e), we = (e) => e.replace(/\.[^.]+$/, ""), Te = (e) => e.flatMap((e) => e.files.map((t) => e.directory ? `${e.directory}/${t}` : t)), Ee = class extends x {
330
- type;
331
- communityStore;
332
- constructor(e) {
333
- super(), this.communityStore = e, this.type = "remote";
334
- }
335
- getGenericStores() {
336
- return this.communityStore.stores.filter((e) => e.type === "generic");
337
- }
338
- getStoreById(e) {
339
- return this.getGenericStores().find((t) => t.id === e) || null;
340
- }
341
- buildEditorId(e, t) {
342
- return `remote:${e.id}:${encodeURIComponent(t)}`;
343
- }
344
- async detectEngineForFallback(e) {
345
- try {
346
- return (await E(e)).files[0]?.engine || "duck_db";
347
- } catch {
348
- return "duck_db";
349
- }
350
- }
351
- buildRuntimeConnection(e, t, n, r, i) {
352
- let a = r?.options || {}, o;
353
- switch (r?.type) {
354
- case "duckdb":
355
- case "duck_db":
356
- o = new g(t, n);
357
- break;
358
- case "sqlite":
359
- o = new f(t, n);
360
- break;
361
- case "motherduck":
362
- o = new d(t, "", n);
363
- break;
364
- case "bigquery":
365
- o = new h(t, a.projectId || "", n);
366
- break;
367
- case "snowflake":
368
- o = new p(t, {
369
- account: a.account || "",
370
- username: a.username || "",
371
- privateKey: "",
372
- warehouse: a.warehouse || "",
373
- role: a.role,
374
- database: a.database,
375
- schema: a.schema
376
- }, n);
377
- break;
378
- default: return r?.type && console.warn(`Remote store "${e.name}" advertised unknown connection type "${r.type}". Falling back to browse-only RemoteProjectConnection.`), new m(t, e.id, i, n);
379
- }
380
- return o.remoteStoreId = e.id, o.storage = "remote", o.recomputeId(), o.model = n, o;
381
- }
382
- async loadStore(r) {
383
- let o = this.getStoreById(r);
384
- if (!o) return {
385
- editors: {},
386
- connections: {},
387
- models: {}
388
- };
389
- let s = {
390
- editors: {},
391
- connections: {},
392
- models: {}
393
- }, [u, d] = await Promise.all([T(o).catch((e) => (console.warn(`Failed to fetch /index.json for store "${o.name}":`, e), null)), F(o)]), f = u?.connection ?? null, p = W(o), h = G(o), g = new Set(u?.startup_scripts ?? []), _ = Te(d.directories), y = _.filter((e) => n(e) !== null);
394
- (await Promise.all(y.map(async (e) => ({
395
- path: e,
396
- content: await ye(o, e)
397
- })))).forEach(({ path: e, content: t }) => {
398
- let r = n(e);
399
- if (!r) return;
400
- let c = [];
401
- i(r) && c.push(a.SOURCE), g.has(e) && c.push(a.STARTUP_SCRIPT);
402
- let u = v(new l({
403
- id: this.buildEditorId(o, e),
404
- name: e,
405
- type: r,
406
- connection: p,
407
- storage: "remote",
408
- contents: t,
409
- tags: c,
410
- remoteStoreId: o.id,
411
- remotePath: e,
412
- remotePersisted: !0
413
- }));
414
- u.changed = !1, s.editors[u.id] = u;
415
- });
416
- let b;
417
- if (f && f.type) b = this.buildRuntimeConnection(o, p, h, f, f.type);
418
- else {
419
- let e = await this.detectEngineForFallback(o);
420
- e && e !== "duck_db" && e !== "duckdb" && console.warn(`Remote store "${o.name}" did not declare a runtime connection but its model engine is "${e}". Queries will not run until /index.json includes a connection block.`), b = new m(p, o.id, e, h);
421
- }
422
- let x = v(b);
423
- x.changed = !1, s.connections[p] = x;
424
- let S = v(new e({
425
- name: h,
426
- storage: "remote",
427
- description: `${U(o)} remote project`,
428
- sources: _.filter((e) => c(e) === ".preql").map((e) => new t(this.buildEditorId(o, e), we(e), [], []))
429
- }));
430
- return S.changed = !1, s.models[S.name] = S, s;
431
- }
432
- async saveEditor(e) {
433
- await this.saveEditors([e]);
434
- }
435
- async saveEditors(e) {
436
- for (let t of e) {
437
- if (!t.remoteStoreId) continue;
438
- let e = this.getStoreById(t.remoteStoreId);
439
- if (!e) continue;
440
- let n = t.remotePath || t.name, r = t.remoteOriginalPath;
441
- if (t.deleted) {
442
- (t.remotePersisted || r) && await R(e, r || n), t.changed = !1;
443
- continue;
444
- }
445
- t.changed &&= (r && r !== n ? (await I(e, n, t.contents), await R(e, r)) : t.remotePersisted ? await L(e, n, t.contents) : await I(e, n, t.contents), t.remotePath = n, t.remoteOriginalPath = null, t.remotePersisted = !0, !1);
446
- }
447
- }
448
- async loadEditors() {
449
- let e = {}, t = this.getGenericStores();
450
- return await Promise.allSettled(t.map(async (t) => {
451
- Object.assign(e, (await this.loadStore(t.id)).editors);
452
- })), e;
453
- }
454
- async deleteEditor(e) {}
455
- async clearEditors() {}
456
- async saveConnections(e) {
457
- e.forEach((e) => {
458
- e.changed = !1;
459
- });
460
- }
461
- async loadConnections() {
462
- let e = {}, t = this.getGenericStores();
463
- return await Promise.allSettled(t.map(async (t) => {
464
- Object.assign(e, (await this.loadStore(t.id)).connections);
465
- })), e;
466
- }
467
- async deleteConnection(e) {}
468
- async loadModelConfig() {
469
- let e = {}, t = this.getGenericStores();
470
- return await Promise.allSettled(t.map(async (t) => {
471
- Object.assign(e, (await this.loadStore(t.id)).models);
472
- })), e;
473
- }
474
- async saveModelConfig(e) {
475
- e.forEach((e) => {
476
- e.changed = !1;
477
- });
478
- }
479
- clearModelConfig() {}
480
- async saveLLMConnections(e) {}
481
- async loadLLMConnections() {
482
- return {};
483
- }
484
- async deleteLLMConnection(e) {}
485
- async saveDashboards(e) {}
486
- async loadDashboards() {
487
- return {};
488
- }
489
- async deleteDashboard(e) {}
490
- async clearDashboards() {}
491
- async saveChats(e) {}
492
- async loadChats() {
493
- return {};
494
- }
495
- async deleteChat(e) {}
496
- async clearChats() {}
497
- }, K = {
498
- type: "github",
499
- id: "trilogy-data-trilogy-public-models-main",
500
- name: "Trilogy Public Models",
501
- owner: "trilogy-data",
502
- repo: "trilogy-public-models",
503
- branch: "main"
504
- }, q = "trilogy-community-stores", De = (e) => {
505
- let t = new URLSearchParams(window.location.search), n = t.get("store"), r = t.get("token");
506
- if (!n || !r) return;
507
- let i = B(n), a = e.find((e) => e.type === "generic" && B(e.baseUrl) === i);
508
- a && !a.token && (a.token = r);
509
- }, Oe = y("communityApi", {
510
- state: () => ({
511
- stores: [K],
512
- filesByStore: {},
513
- errors: {},
514
- storeStatus: { [K.id]: "idle" },
515
- loading: !1,
516
- showAddStoreModal: !1,
517
- addingStore: !1,
518
- newStore: {
519
- type: "generic",
520
- name: "",
521
- baseUrl: "",
522
- owner: "",
523
- repo: "",
524
- branch: "main"
525
- }
526
- }),
527
- getters: {
528
- allFiles: (e) => {
529
- let t = [];
530
- return Object.values(e.filesByStore).forEach((e) => {
531
- t.push(...e);
532
- }), t;
533
- },
534
- availableEngines: (e) => {
535
- let t = [];
536
- return Object.values(e.filesByStore).forEach((e) => {
537
- t.push(...e);
538
- }), ae(t);
539
- },
540
- hasErrors: (e) => Object.keys(e.errors).length > 0,
541
- errorList: (e) => Object.entries(e.errors).map(([t, n]) => ({
542
- root: t,
543
- name: e.stores.find((e) => e.id === t)?.name || t,
544
- error: n
545
- }))
546
- },
547
- actions: {
548
- loadStoresFromStorage() {
549
- try {
550
- let e = localStorage.getItem(q);
551
- if (e) {
552
- let t = JSON.parse(e), n = new Map(this.stores.map((e) => [e.id, e])), r = [K, ...t.map((e) => {
553
- let t = n.get(e.id);
554
- if (!t || t.type !== e.type) return e;
555
- if (e.type === "generic") {
556
- let n = t.type === "generic" ? t : null;
557
- return {
558
- ...e,
559
- ...t,
560
- token: n?.token || e.token
561
- };
562
- }
563
- return {
564
- ...e,
565
- ...t
566
- };
567
- })].filter((e, t, n) => t === n.findIndex((t) => t.id === e.id));
568
- De(r), this.stores = r, r.forEach((e) => {
569
- this.storeStatus[e.id] || (this.storeStatus[e.id] = "idle");
570
- });
571
- }
572
- e || De(this.stores);
573
- } catch (e) {
574
- console.error("Error loading stores from localStorage:", e);
575
- }
576
- },
577
- saveStoresToStorage() {
578
- try {
579
- let e = this.stores.filter((e) => e.id !== K.id);
580
- localStorage.setItem(q, JSON.stringify(e));
581
- } catch (e) {
582
- console.error("Error saving stores to localStorage:", e);
583
- }
584
- },
585
- async fetchAllFiles() {
586
- this.loading = !0;
587
- for (let e of this.stores) this.storeStatus[e.id] = "idle";
588
- try {
589
- console.log(`Fetching community model files from ${this.stores.map((e) => e.id).join(", ")}...`);
590
- let e = await ce(this.stores, (e, t) => {
591
- this.filesByStore[e] = t.files, t.error ? (this.errors[e] = t.error, this.storeStatus[e] = "failed") : this.storeStatus[e] = "connected", console.log(`Store ${e} completed: ${t.error ? "failed" : "success"}`);
592
- });
593
- console.log("All stores fetched:", e);
594
- } catch (e) {
595
- console.error("Error fetching all model files:", e), this.errors = { general: e instanceof Error ? e.message : "Unknown error" };
596
- } finally {
597
- this.loading = !1;
598
- }
599
- },
600
- async refreshData() {
601
- await this.fetchAllFiles();
602
- },
603
- async fetchStoreFiles(e) {
604
- let t = this.stores.find((t) => t.id === e);
605
- if (t) {
606
- this.loading = !0, this.storeStatus[e] = "idle";
607
- try {
608
- let n = await E(t);
609
- this.filesByStore[e] = n.files, n.error ? (this.errors[e] = n.error, this.storeStatus[e] = "failed") : (delete this.errors[e], this.storeStatus[e] = "connected");
610
- } finally {
611
- this.loading = !1;
612
- }
613
- }
614
- },
615
- filteredFiles(e, t, n, r, i = null) {
616
- let a = (e) => e in r.models, o = this.allFiles;
617
- return i && (o = this.filesByStore[i]), o ? re(o, e, t, n, a) : [];
618
- },
619
- getFilesByStore(e) {
620
- return this.filesByStore[e] || [];
621
- },
622
- async initialize() {
623
- this.loadStoresFromStorage(), await this.fetchAllFiles();
624
- },
625
- async addStore(e) {
626
- if (e.type === "generic") {
627
- if (!e.baseUrl) throw Error("Base URL is required for generic stores");
628
- e.baseUrl = B(e.baseUrl), e.id = e.id || V(e.baseUrl), e.name = e.name || H(e.baseUrl);
629
- } else if (e.type === "github" && (!e.owner || !e.repo || !e.branch)) throw Error("Owner, repo, and branch are required for GitHub stores");
630
- if (this.stores.some((t) => t.id === e.id)) throw Error("This store is already added");
631
- this.addingStore = !0;
632
- try {
633
- return this.stores.push(e), this.saveStoresToStorage(), await this.fetchAllFiles(), !0;
634
- } catch (t) {
635
- console.error("Error adding store:", t);
636
- let n = this.stores.findIndex((t) => t.id === e.id);
637
- throw n > -1 && this.stores.splice(n, 1), t;
638
- } finally {
639
- this.addingStore = !1;
640
- }
641
- },
642
- removeStore(e) {
643
- let t = this.stores.findIndex((t) => t.id === e);
644
- t > -1 && (this.stores.splice(t, 1), delete this.filesByStore[e], delete this.errors[e], this.saveStoresToStorage());
645
- },
646
- updateStoreToken(e, t) {
647
- let n = this.stores.find((t) => t.id === e);
648
- !n || n.type !== "generic" || (n.token = t || void 0, this.saveStoresToStorage());
649
- },
650
- openAddStoreModal() {
651
- this.showAddStoreModal = !0, this.newStore = {
652
- type: "generic",
653
- name: "",
654
- baseUrl: "",
655
- owner: "",
656
- repo: "",
657
- branch: "main"
658
- };
659
- },
660
- closeAddStoreModal() {
661
- this.showAddStoreModal = !1, this.newStore = {
662
- type: "generic",
663
- name: "",
664
- baseUrl: "",
665
- owner: "",
666
- repo: "",
667
- branch: "main"
668
- };
669
- },
670
- async handleAddStore() {
671
- let { type: e, name: t, baseUrl: n, owner: r, repo: i, branch: a } = this.newStore;
672
- if (e === "generic") {
673
- if (!n) throw Error("Please fill in all required fields");
674
- let e = B(n), r = {
675
- type: "generic",
676
- id: V(e),
677
- name: t || H(e),
678
- baseUrl: e
679
- };
680
- await this.addStore(r);
681
- } else {
682
- if (!t || !r || !i || !a) throw Error("Please fill in all required fields");
683
- let e = {
684
- type: "github",
685
- id: `${r}-${i}-${a}`,
686
- name: t,
687
- owner: r,
688
- repo: i,
689
- branch: a
690
- };
691
- await this.addStore(e);
692
- }
693
- this.closeAddStoreModal();
694
- },
695
- clearErrors() {
696
- this.errors = {};
697
- },
698
- clearStoreError(e) {
699
- delete this.errors[e], this.storeStatus[e] = "idle";
700
- },
701
- getStoreStatus(e) {
702
- return this.storeStatus[e] || "idle";
703
- }
704
- }
705
- }), J = /* @__PURE__ */ new Map();
706
- async function ke(e) {
707
- let t = b();
708
- if (t.models[e]) return !0;
709
- let n = J.get(e);
710
- if (n) return n;
711
- let r = Oe();
712
- r.stores.length <= 1 && r.loadStoresFromStorage();
713
- let i = r.stores.find((t) => t.type === "generic" && G(t) === e);
714
- if (!i) return !1;
715
- let a = (async () => {
716
- try {
717
- let n = await new Ee(r).loadStore(i.id), a = $();
718
- for (let e of Object.values(n.editors)) a.editors[e.id] || a.addEditor(e);
719
- for (let e of Object.values(n.models)) t.models[e.name] || t.addModelConfig(e);
720
- return !!t.models[e];
721
- } catch (t) {
722
- return console.warn(`Failed to rehydrate remote model "${e}":`, t), !1;
723
- } finally {
724
- J.delete(e);
725
- }
726
- })();
727
- return J.set(e, a), a;
728
- }
729
- //#endregion
730
- //#region stores/connectionStore.ts
731
- var Y = /* @__PURE__ */ new Map(), X = 6e4;
732
- async function Ae(e) {
733
- let t = $().getConnectionEditors(e.id, [a.STARTUP_SCRIPT]);
734
- await Promise.all(t.map(async (t) => {
735
- console.log(`running startup script ${t.name}`), await e.runScript(t.contents);
736
- }));
737
- }
738
- function Z(e) {
739
- if (e.model && !b().models[e.model]) return ke(e.model);
740
- }
741
- var je = [
742
- {
743
- label: "DuckDB",
744
- value: "duckdb"
745
- },
746
- {
747
- label: "BigQuery (OAuth)",
748
- value: "bigquery-oauth"
749
- },
750
- {
751
- label: "BigQuery (Service Account)",
752
- value: "bigquery"
753
- },
754
- {
755
- label: "Snowflake (Key Pair Auth)",
756
- value: "snowflake"
757
- },
758
- {
759
- label: "SQLite",
760
- value: "sqlite"
761
- },
762
- {
763
- label: "MotherDuck (Token)",
764
- value: "motherduck"
765
- },
766
- {
767
- label: "DuckDB (Native)",
768
- value: "remote-worker-duckdb"
769
- }
770
- ], Q = y("connections", {
771
- state: () => ({ connections: {} }),
772
- getters: {
773
- connectionList: (e) => Object.keys(e.connections).map((t) => e.connections[t]),
774
- unsavedConnections: (e) => Object.values(e.connections).filter((e) => e.changed).length,
775
- connectionByName: (e) => (t) => {
776
- let n = Object.values(e.connections).filter((e) => e.name === t);
777
- if (n.length !== 0) return n.find((e) => e.storage !== "remote") || n[0];
778
- }
779
- },
780
- actions: {
781
- addConnection(e) {
782
- return this.connections[e.id] = e, e;
783
- },
784
- async connectConnection(e) {
785
- if (!this.connections[e]) throw Error(`Connection with id "${e}" not found.`);
786
- let t = `connect:${e}`;
787
- if (Y.has(t)) return Y.get(t);
788
- let n = new Promise((e, t) => {
789
- setTimeout(() => t(/* @__PURE__ */ Error(`Connection timed out after ${X / 1e3} seconds`)), X);
790
- }), r = Promise.race([(async () => {
791
- let t = Z(this.connections[e]);
792
- t && await t, await this.connections[e].reset(), await Ae(this.connections[e]);
793
- })(), n]).catch((t) => {
794
- throw this.connections[e]?.setError?.(t instanceof Error ? t.message : String(t)), t;
795
- }).finally(() => {
796
- Y.delete(t);
797
- });
798
- return Y.set(t, r), r;
799
- },
800
- async resetConnection(e) {
801
- if (!this.connections[e]) throw Error(`Connection with id "${e}" not found.`);
802
- let t = `reset:${e}`;
803
- if (Y.has(t)) return Y.get(t);
804
- let n = new Promise((e, t) => {
805
- setTimeout(() => t(/* @__PURE__ */ Error(`Reset operation timed out after ${X / 1e3} seconds`)), X);
806
- }), r = Z(this.connections[e]), i = (r ? r.then(() => this.connections[e].reset()) : this.connections[e].reset()).then(() => Ae(this.connections[e])), a = Promise.race([i, n]).catch((t) => {
807
- throw this.connections[e]?.setError?.(t instanceof Error ? t.message : String(t)), t;
808
- }).finally(() => {
809
- Y.delete(t);
810
- });
811
- return Y.set(t, a), a;
812
- },
813
- deleteConnection(e) {
814
- this.connections[e] && this.connections[e].delete();
815
- },
816
- purgeDeletedConnections() {
817
- for (let e of Object.keys(this.connections)) this.connections[e].deleted && delete this.connections[e];
818
- },
819
- connectionStateToStatus(e) {
820
- return e ? e.error ? "failed" : e.running ? "running" : e.connected ? "connected" : "disabled" : "disabled";
821
- },
822
- getConnectionSources(e) {
823
- let t = this.connections[e], n = b(), r = $();
824
- if (!t || !t.model) return [];
825
- let i = n.models[t.model];
826
- return i ? i.sources.map((e) => ({
827
- alias: e.alias,
828
- contents: r.editors[e.editor] ? r.editors[e.editor].contents : ""
829
- })) : (console.warn(`Connection "${t.name}" references model "${t.model}", which is not loaded; running with no model sources.`), []);
830
- },
831
- newConnection(e, t, n) {
832
- let r = u({
833
- name: e,
834
- storage: "local"
835
- });
836
- if (this.connections[r]) throw Error(`Connection with name "${e}" already exists.`);
837
- let i;
838
- if (t === "duckdb") i = new g(e);
839
- else if (t === "sqlite") i = new f(e);
840
- else if (t === "bigquery-oauth") i = new h(e, n.projectId);
841
- else if (t === "bigquery") i = new h(e, n.projectId);
842
- else if (t === "snowflake") i = new p(e, {
843
- account: n.account,
844
- username: n.username,
845
- privateKey: n.privateKey,
846
- warehouse: n.warehouse,
847
- role: n.role,
848
- database: n.database,
849
- schema: n.schema
850
- });
851
- else if (t === "motherduck") i = new d(e, n.mdToken, n.saveCredential);
852
- else if (t === "remote-worker-duckdb") i = new _(e, {
853
- driver: "duckdb",
854
- config: n.config ?? {},
855
- queryType: "duckdb"
856
- });
857
- else throw Error(`Connection type "${t}" not found.`);
858
- if (this.connections[i.id] = i, n.model) i.model = n.model;
859
- else {
860
- let t = b();
861
- i.model = t.newModelConfig(e).name;
862
- }
863
- return i;
864
- }
865
- }
866
- }), $ = y("editors", {
867
- state: () => ({
868
- editors: {},
869
- activeEditorName: "",
870
- activeEditorId: ""
871
- }),
872
- getters: {
873
- editorList: (e) => Object.keys(e.editors).map((t) => e.editors[t]),
874
- unsavedEditors: (e) => Object.values(e.editors).filter((e) => e.changed).length
875
- },
876
- actions: {
877
- newEditor(e, t, n, i, a = {}) {
878
- let o = Q().connectionByName(n), s = a.storage || o?.storage || "local", c = a.remoteStoreId || s === "remote" && o?.remoteStoreId || null, u = s === "remote" ? r(e, t) : e, d = s === "remote" ? r(a.remotePath || u, t) : null, f = s === "remote" ? `remote:${c || "store"}:${encodeURIComponent(d || u)}` : u, p = f, m = 1;
879
- for (; this.editors[p];) p = `${f}#${m}`, m++;
880
- let h = new l({
881
- id: p,
882
- name: u,
883
- type: t,
884
- connection: n,
885
- storage: s,
886
- contents: i || "",
887
- remoteStoreId: c,
888
- remotePath: d || void 0,
889
- remotePersisted: a.remotePersisted || !1
890
- });
891
- return this.editors[h.id] = h, h;
892
- },
893
- addEditor(e) {
894
- this.editors[e.id] = e;
895
- },
896
- getEditorByName(e) {
897
- let t = Object.values(this.editors).filter((t) => t.name === e);
898
- return t.find((e) => !e.deleted) ?? t[0];
899
- },
900
- getConnectionEditors(e, t = []) {
901
- let n = Object.values(this.editors).filter((t) => t.connectionId === e);
902
- return t.length === 0 ? n : n.filter((e) => t.every((t) => e.tags.includes(t)));
903
- },
904
- updateEditorName(e, t) {
905
- this.editors[e].setName(t);
906
- },
907
- removeEditor(e) {
908
- if (this.editors[e]) this.editors[e].deleted = !0;
909
- else return !1;
910
- },
911
- setEditorScrollPosition(e, t) {
912
- if (this.editors[e]) this.editors[e].scrollPosition = t;
913
- else throw Error(`Editor with id "${e}" not found.`);
914
- },
915
- setEditorContents(e, t) {
916
- if (this.editors[e]) this.editors[e].setContent(t);
917
- else throw Error(`Editor with id "${e}" not found.`);
918
- },
919
- setEditorResults(e, t) {
920
- if (this.editors[e]) {
921
- let n = this.editors[e];
922
- n.results = t, n.setError(null);
923
- } else throw Error(`Editor with id "${e}" not found.`);
924
- },
925
- getCurrentEditorAutocomplete(e) {
926
- if (!this.activeEditorId) return [];
927
- let t = this.editors[this.activeEditorId];
928
- return e ? t.getAutocomplete(e) : [];
929
- },
930
- startRefinementSession(e, t = {}) {
931
- let n = this.editors[e];
932
- if (!n) return;
933
- let r = {
934
- messages: [],
935
- artifacts: [],
936
- originalContent: n.contents,
937
- originalChartConfig: n.chartConfig || void 0,
938
- currentContent: n.contents,
939
- currentChartConfig: n.chartConfig || void 0,
940
- selectedText: t.selectedText,
941
- selectionRange: t.selectionRange,
942
- wasLoading: !1
943
- };
944
- n.setRefinementSession(r);
945
- },
946
- updateRefinementSession(e, t) {
947
- let n = this.editors[e];
948
- !n || !n.refinementSession || n.setRefinementSession({
949
- ...n.refinementSession,
950
- ...t
951
- });
952
- },
953
- clearRefinementSession(e) {
954
- let t = this.editors[e];
955
- t && (s(e, {
956
- editorStore: this,
957
- chatStore: o()
958
- }), t.setRefinementSession(null));
959
- },
960
- discardRefinement(e, t) {
961
- let n = this.editors[e];
962
- if (!n?.refinementSession) return;
963
- let r = n.refinementSession;
964
- n.setContent(r.originalContent), t?.onContentChange?.(r.originalContent), r.originalChartConfig && (n.setChartConfig(r.originalChartConfig), t?.onChartConfigChange?.(r.originalChartConfig)), t?.onDiscard?.(), this.clearRefinementSession(e);
965
- },
966
- acceptRefinement(e, t) {
967
- t?.onFinish?.("Changes accepted"), this.clearRefinementSession(e);
968
- }
969
- }
970
- });
971
- //#endregion
972
- export { he as C, ie as D, pe as E, x as O, O as S, ve as T, ge as _, K as a, _e as b, H as c, j as d, Ce as f, xe as g, be as h, Oe as i, b as k, V as l, Se as m, je as n, Ee as o, F as p, Q as r, W as s, $ as t, B as u, fe as v, me as w, de as x, ue as y };