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