drizzle-cube 0.4.17 → 0.4.18

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.
@@ -1,22 +1,22 @@
1
- import { h as $, Q as B, j, D as U } from "./mcp-transport-m1X1GtwG.js";
2
- import { handleDiscover as Z, handleLoad as G } from "./utils.js";
3
- function K(o) {
4
- if (o.length === 0)
1
+ import { h as H, Q as B, j, D as Z } from "./mcp-transport-m1X1GtwG.js";
2
+ import { handleDiscover as U, handleLoad as G } from "./utils.js";
3
+ function K(l) {
4
+ if (l.length === 0)
5
5
  return "No cubes are currently available.";
6
6
  const t = ["## Available Cubes", ""];
7
- for (const a of o) {
7
+ for (const a of l) {
8
8
  if (t.push(`### ${a.name}`), a.description && t.push(a.description), a.measures && a.measures.length > 0) {
9
9
  t.push(""), t.push("**Measures:**");
10
10
  for (const i of a.measures) {
11
- const e = i.description ? ` - ${i.description}` : "";
12
- t.push(`- \`${a.name}.${i.name}\` (${i.type})${e}`);
11
+ const d = i.description ? ` - ${i.description}` : "";
12
+ t.push(`- \`${a.name}.${i.name}\` (${i.type})${d}`);
13
13
  }
14
14
  }
15
15
  if (a.dimensions && a.dimensions.length > 0) {
16
16
  t.push(""), t.push("**Dimensions:**");
17
17
  for (const i of a.dimensions) {
18
- const e = i.description ? ` - ${i.description}` : "";
19
- t.push(`- \`${a.name}.${i.name}\` (${i.type})${e}`);
18
+ const d = i.description ? ` - ${i.description}` : "";
19
+ t.push(`- \`${a.name}.${i.name}\` (${i.type})${d}`);
20
20
  }
21
21
  }
22
22
  if (a.relationships && a.relationships.length > 0) {
@@ -29,12 +29,12 @@ function K(o) {
29
29
  return t.join(`
30
30
  `);
31
31
  }
32
- function I(o) {
33
- return o.messages.map((t) => t.content.text).join(`
32
+ function I(l) {
33
+ return l.messages.map((t) => t.content.text).join(`
34
34
 
35
35
  `);
36
36
  }
37
- function W(o) {
37
+ function W(l) {
38
38
  return [
39
39
  "# Drizzle Cube Analytics Agent",
40
40
  "",
@@ -160,7 +160,7 @@ function W(o) {
160
160
  "",
161
161
  "---",
162
162
  "",
163
- I($),
163
+ I(H),
164
164
  "",
165
165
  "---",
166
166
  "",
@@ -172,7 +172,7 @@ function W(o) {
172
172
  "",
173
173
  "---",
174
174
  "",
175
- I(U),
175
+ I(Z),
176
176
  "",
177
177
  "---",
178
178
  "",
@@ -226,7 +226,7 @@ function W(o) {
226
226
  "",
227
227
  "---",
228
228
  "",
229
- K(o)
229
+ K(l)
230
230
  ].join(`
231
231
  `);
232
232
  }
@@ -769,8 +769,8 @@ const X = {
769
769
  description: "Automatically size blocks to fill portlet width and height while maintaining aspect ratio"
770
770
  }
771
771
  ],
772
- validate: (o) => {
773
- const { dateField: t, valueField: a } = o;
772
+ validate: (l) => {
773
+ const { dateField: t, valueField: a } = l;
774
774
  return !t || Array.isArray(t) && t.length === 0 ? {
775
775
  isValid: !1,
776
776
  message: "Time dimension is required for activity grid"
@@ -938,7 +938,7 @@ const X = {
938
938
  }
939
939
  ],
940
940
  displayOptions: ["hideHeader"],
941
- validate: (o) => !o.yAxis || Array.isArray(o.yAxis) && o.yAxis.length === 0 ? {
941
+ validate: (l) => !l.yAxis || Array.isArray(l.yAxis) && l.yAxis.length === 0 ? {
942
942
  isValid: !1,
943
943
  message: "A measure is required for KPI Delta charts"
944
944
  } : { isValid: !0 }
@@ -1335,7 +1335,7 @@ Use --- for horizontal rules.`,
1335
1335
  description: "Number formatting for cell values and legend"
1336
1336
  }
1337
1337
  ],
1338
- validate: (o) => o.xAxis?.length ? o.yAxis?.length ? o.valueField?.length ? { isValid: !0 } : { isValid: !1, message: "Value measure required" } : { isValid: !1, message: "Y-axis dimension required" } : { isValid: !1, message: "X-axis dimension required" }
1338
+ validate: (l) => l.xAxis?.length ? l.yAxis?.length ? l.valueField?.length ? { isValid: !0 } : { isValid: !1, message: "Value measure required" } : { isValid: !1, message: "Y-axis dimension required" } : { isValid: !1, message: "X-axis dimension required" }
1339
1339
  }, fe = {
1340
1340
  label: "Retention Matrix",
1341
1341
  // RetentionHeatmap auto-configures from the retention data structure
@@ -1708,100 +1708,100 @@ Use --- for horizontal rules.`,
1708
1708
  measureProfile: ke,
1709
1709
  gauge: ve
1710
1710
  };
1711
- function Ce(o, t, a) {
1712
- const i = P[o];
1711
+ function Ce(l, t, a) {
1712
+ const i = P[l];
1713
1713
  if (!i)
1714
1714
  return { isValid: !0, errors: [] };
1715
1715
  if (i.skipQuery)
1716
1716
  return { isValid: !0, errors: [] };
1717
- const e = [];
1718
- for (const s of i.dropZones) {
1719
- if (!s.mandatory) continue;
1720
- const l = t?.[s.key];
1721
- if (!(Array.isArray(l) ? l.length > 0 : !!l)) {
1722
- const u = s.acceptTypes?.join("/") ?? "fields";
1723
- e.push(
1724
- `chartConfig.${s.key} is required for ${o} chart (${s.label}). Accepts: ${u}.`
1717
+ const d = [];
1718
+ for (const u of i.dropZones) {
1719
+ if (!u.mandatory) continue;
1720
+ const e = t?.[u.key];
1721
+ if (!(Array.isArray(e) ? e.length > 0 : !!e)) {
1722
+ const r = u.acceptTypes?.join("/") ?? "fields";
1723
+ d.push(
1724
+ `chartConfig.${u.key} is required for ${l} chart (${u.label}). Accepts: ${r}.`
1725
1725
  );
1726
1726
  }
1727
1727
  }
1728
- if (o === "bar") {
1729
- const s = t?.xAxis;
1730
- if (!(Array.isArray(s) ? s.length > 0 : !!s)) {
1731
- const d = a.dimensions ?? [], u = a.timeDimensions ?? [];
1732
- d.length > 0 || u.length > 0 ? e.push(
1728
+ if (l === "bar") {
1729
+ const u = t?.xAxis;
1730
+ if (!(Array.isArray(u) ? u.length > 0 : !!u)) {
1731
+ const o = a.dimensions ?? [], r = a.timeDimensions ?? [];
1732
+ o.length > 0 || r.length > 0 ? d.push(
1733
1733
  "chartConfig.xAxis is required for bar charts. Put a dimension in xAxis so bars have category labels."
1734
- ) : e.push(
1734
+ ) : d.push(
1735
1735
  'Bar charts need an xAxis dimension for category labels. Add a dimension to the query or use "table" chart type instead.'
1736
1736
  );
1737
1737
  }
1738
1738
  }
1739
1739
  if (t?.xAxis && t?.series) {
1740
- const s = new Set(
1740
+ const u = new Set(
1741
1741
  Array.isArray(t.xAxis) ? t.xAxis : [t.xAxis]
1742
- ), d = (Array.isArray(t.series) ? t.series : [t.series]).filter((u) => s.has(u));
1743
- d.length > 0 && e.push(
1744
- `chartConfig.series must not contain the same field as xAxis (found: ${d.join(", ")}). The series field is only for splitting into grouped/stacked sub-series by a DIFFERENT dimension. Remove the duplicate from series.`
1742
+ ), o = (Array.isArray(t.series) ? t.series : [t.series]).filter((r) => u.has(r));
1743
+ o.length > 0 && d.push(
1744
+ `chartConfig.series must not contain the same field as xAxis (found: ${o.join(", ")}). The series field is only for splitting into grouped/stacked sub-series by a DIFFERENT dimension. Remove the duplicate from series.`
1745
1745
  );
1746
1746
  }
1747
- return { isValid: e.length === 0, errors: e };
1747
+ return { isValid: d.length === 0, errors: d };
1748
1748
  }
1749
- function Te(o, t, a) {
1750
- const i = P[o];
1749
+ function Te(l, t, a) {
1750
+ const i = P[l];
1751
1751
  if (!i)
1752
1752
  return t ?? {};
1753
- const e = { ...t }, s = a.measures ?? [], l = a.dimensions ?? [], u = (a.timeDimensions ?? []).map((p) => p.dimension);
1754
- for (const p of i.dropZones) {
1755
- const m = e[p.key];
1753
+ const d = { ...t }, u = a.measures ?? [], e = a.dimensions ?? [], r = (a.timeDimensions ?? []).map((s) => s.dimension);
1754
+ for (const s of i.dropZones) {
1755
+ const m = d[s.key];
1756
1756
  if (Array.isArray(m) ? m.length > 0 : !!m) continue;
1757
- const b = p.acceptTypes ?? [];
1758
- if (p.key === "sizeField" || p.key === "colorField") {
1759
- if (b.includes("measure")) {
1757
+ const y = s.acceptTypes ?? [];
1758
+ if (s.key === "sizeField" || s.key === "colorField") {
1759
+ if (y.includes("measure")) {
1760
1760
  const g = /* @__PURE__ */ new Set();
1761
- for (const S of i.dropZones) {
1762
- if (S.key === p.key) continue;
1763
- const x = e[S.key];
1764
- Array.isArray(x) ? x.forEach((V) => g.add(V)) : typeof x == "string" && g.add(x);
1761
+ for (const C of i.dropZones) {
1762
+ if (C.key === s.key) continue;
1763
+ const k = d[C.key];
1764
+ Array.isArray(k) ? k.forEach((E) => g.add(E)) : typeof k == "string" && g.add(k);
1765
1765
  }
1766
- const C = s.filter((S) => !g.has(S));
1767
- C.length > 0 && (e[p.key] = C[0]);
1766
+ const A = u.filter((C) => !g.has(C));
1767
+ A.length > 0 && (d[s.key] = A[0]);
1768
1768
  }
1769
1769
  continue;
1770
1770
  }
1771
- const y = [];
1772
- if (b.includes("dimension") && y.push(...l), b.includes("timeDimension") && y.push(...u), b.includes("measure") && y.push(...s), y.length === 0) continue;
1773
- let f = y;
1774
- if (p.key === "series") {
1771
+ const n = [];
1772
+ if (y.includes("dimension") && n.push(...e), y.includes("timeDimension") && n.push(...r), y.includes("measure") && n.push(...u), n.length === 0) continue;
1773
+ let x = n;
1774
+ if (s.key === "series") {
1775
1775
  const g = new Set(
1776
- Array.isArray(e.xAxis) ? e.xAxis : e.xAxis ? [e.xAxis] : []
1776
+ Array.isArray(d.xAxis) ? d.xAxis : d.xAxis ? [d.xAxis] : []
1777
1777
  );
1778
- if (f = y.filter((C) => !g.has(C)), f.length === 0) continue;
1778
+ if (x = n.filter((A) => !g.has(A)), x.length === 0) continue;
1779
1779
  }
1780
- const v = p.maxItems ?? 1 / 0, D = f.slice(0, v);
1781
- D.length > 0 && (e[p.key] = D);
1780
+ const b = s.maxItems ?? 1 / 0, c = x.slice(0, b);
1781
+ c.length > 0 && (d[s.key] = c);
1782
1782
  }
1783
- return e;
1783
+ return d;
1784
1784
  }
1785
- function Ae(o) {
1785
+ function Ae(l) {
1786
1786
  const t = [`
1787
1787
  Chart config requirements by type:`];
1788
- for (const a of o) {
1788
+ for (const a of l) {
1789
1789
  const i = P[a];
1790
1790
  if (!i) continue;
1791
- const e = i.description ?? "", s = i.useCase ?? "", l = [e, s].filter(Boolean).join(". "), d = l ? ` — ${l}.` : "", u = i.dropZones.filter((m) => m.mandatory);
1792
- if (u.length === 0 && !i.skipQuery) {
1793
- t.push(` ${a}${d} chartConfig auto-inferred from query.`);
1791
+ const d = i.description ?? "", u = i.useCase ?? "", e = [d, u].filter(Boolean).join(". "), o = e ? ` — ${e}.` : "", r = i.dropZones.filter((m) => m.mandatory);
1792
+ if (r.length === 0 && !i.skipQuery) {
1793
+ t.push(` ${a}${o} chartConfig auto-inferred from query.`);
1794
1794
  continue;
1795
1795
  }
1796
1796
  if (i.skipQuery) {
1797
- t.push(` ${a}${d} No query needed.`);
1797
+ t.push(` ${a}${o} No query needed.`);
1798
1798
  continue;
1799
1799
  }
1800
- const p = u.map((m) => {
1801
- const n = m.acceptTypes?.join("/") ?? "any", b = m.maxItems ? ` (max ${m.maxItems})` : "";
1802
- return `${m.key}=[${n}]${b}`;
1800
+ const s = r.map((m) => {
1801
+ const f = m.acceptTypes?.join("/") ?? "any", y = m.maxItems ? ` (max ${m.maxItems})` : "";
1802
+ return `${m.key}=[${f}]${y}`;
1803
1803
  });
1804
- t.push(` ${a}${d} Requires ${p.join(", ")}.`);
1804
+ t.push(` ${a}${o} Requires ${s.join(", ")}.`);
1805
1805
  }
1806
1806
  return t.join(`
1807
1807
  `);
@@ -2121,32 +2121,75 @@ The query is validated before adding. The portlet fetches its own data.`,
2121
2121
  }
2122
2122
  ];
2123
2123
  }
2124
- function Se(o) {
2125
- const { semanticLayer: t, securityContext: a } = o, i = /* @__PURE__ */ new Map();
2126
- return i.set("discover_cubes", async (e) => {
2127
- const s = await Z(t, {
2124
+ function Se(l) {
2125
+ const { semanticLayer: t, securityContext: a } = l, i = /* @__PURE__ */ new Map();
2126
+ i.set("discover_cubes", async (e) => {
2127
+ const o = await U(t, {
2128
2128
  topic: e.topic,
2129
2129
  intent: e.intent,
2130
2130
  limit: e.limit,
2131
2131
  minScore: e.minScore
2132
2132
  });
2133
- return { result: JSON.stringify(s, null, 2) };
2133
+ return { result: JSON.stringify(o, null, 2) };
2134
2134
  }), i.set("get_cube_metadata", async () => {
2135
2135
  const e = t.getMetadata();
2136
2136
  return { result: JSON.stringify(e, null, 2) };
2137
- }), i.set("execute_query", async (e) => {
2137
+ });
2138
+ const d = /* @__PURE__ */ new Map();
2139
+ for (const e of t.getMetadata())
2140
+ d.set(e.name, {
2141
+ measures: (e.measures || []).map((o) => o.name),
2142
+ dimensions: (e.dimensions || []).map((o) => o.name)
2143
+ });
2144
+ const u = (e, o) => {
2145
+ const r = d.get(e), s = o === "measures" ? r?.measures : r?.dimensions;
2146
+ return !s || s.length === 0 ? "" : ` Available ${o}: ${s.slice(0, 5).map((m) => `"${m}"`).join(", ")}`;
2147
+ };
2148
+ return i.set("execute_query", async (e) => {
2138
2149
  try {
2139
- const s = (u, p) => {
2140
- if (!Array.isArray(u)) return;
2141
- const m = u.filter((n) => typeof n == "string" && !n.includes("."));
2142
- if (m.length > 0)
2143
- throw new Error(
2144
- `Invalid ${p}: ${m.map((n) => `"${n}"`).join(", ")}. All ${p} must use "CubeName.fieldName" format (e.g., "PullRequests.count", "Teams.name"). Use discover_cubes or get_cube_metadata to find valid field names.`
2145
- );
2150
+ const o = (f, y) => {
2151
+ if (!Array.isArray(f)) return;
2152
+ const n = [], x = [];
2153
+ for (const b of f) {
2154
+ if (typeof b != "string") {
2155
+ x.push(b);
2156
+ continue;
2157
+ }
2158
+ const c = b.split(".");
2159
+ if (c.length === 1) {
2160
+ n.push(`"${b}" is not valid — must be "CubeName.fieldName".${u(b, y)}`);
2161
+ continue;
2162
+ }
2163
+ if (c.length === 3 && c[0] === c[1]) {
2164
+ const g = `${c[0]}.${c[2]}`;
2165
+ x.push(g);
2166
+ continue;
2167
+ }
2168
+ if (c.length === 2 && c[0] === c[1]) {
2169
+ n.push(`"${b}" is WRONG — "${c[0]}" is the cube name, not a ${y.replace(/s$/, "")}.${u(c[0], y)}`);
2170
+ continue;
2171
+ }
2172
+ x.push(b);
2173
+ }
2174
+ if (n.length > 0)
2175
+ throw new Error(`Invalid ${y}:
2176
+ ${n.join(`
2177
+ `)}`);
2178
+ return x;
2179
+ };
2180
+ e.measures = o(e.measures, "measures") ?? e.measures, e.dimensions = o(e.dimensions, "dimensions") ?? e.dimensions;
2181
+ const r = (f) => {
2182
+ const y = f.split(".");
2183
+ return y.length === 3 && y[0] === y[1] ? `${y[0]}.${y[2]}` : f;
2146
2184
  };
2147
- s(e.measures, "measures"), s(e.dimensions, "dimensions");
2148
- let l;
2149
- e.funnel ? l = { funnel: e.funnel } : e.flow ? l = { flow: e.flow } : e.retention ? l = { retention: e.retention } : l = {
2185
+ if (Array.isArray(e.filters))
2186
+ for (const f of e.filters)
2187
+ typeof f.member == "string" && (f.member = r(f.member));
2188
+ if (Array.isArray(e.timeDimensions))
2189
+ for (const f of e.timeDimensions)
2190
+ typeof f.dimension == "string" && (f.dimension = r(f.dimension));
2191
+ let s;
2192
+ e.funnel ? s = { funnel: e.funnel } : e.flow ? s = { flow: e.flow } : e.retention ? s = { retention: e.retention } : s = {
2150
2193
  measures: e.measures,
2151
2194
  dimensions: e.dimensions,
2152
2195
  filters: e.filters,
@@ -2154,135 +2197,152 @@ function Se(o) {
2154
2197
  order: e.order,
2155
2198
  limit: e.limit
2156
2199
  };
2157
- const d = await G(t, a, { query: l });
2200
+ const m = await G(t, a, { query: s });
2158
2201
  return {
2159
2202
  result: JSON.stringify({
2160
- rowCount: d.data.length,
2161
- data: d.data,
2162
- annotation: d.annotation
2203
+ rowCount: m.data.length,
2204
+ data: m.data,
2205
+ annotation: m.annotation
2163
2206
  }, null, 2)
2164
2207
  };
2165
- } catch (s) {
2208
+ } catch (o) {
2209
+ const r = {
2210
+ measures: e.measures,
2211
+ dimensions: e.dimensions,
2212
+ filters: e.filters,
2213
+ timeDimensions: e.timeDimensions,
2214
+ order: e.order,
2215
+ limit: e.limit,
2216
+ ...e.funnel ? { funnel: e.funnel } : {},
2217
+ ...e.flow ? { flow: e.flow } : {},
2218
+ ...e.retention ? { retention: e.retention } : {}
2219
+ };
2166
2220
  return {
2167
- result: `Query execution failed: ${s instanceof Error ? s.message : "Unknown error"}`,
2221
+ result: `Query execution failed: ${o instanceof Error ? o.message : "Unknown error"}
2222
+
2223
+ Attempted query:
2224
+ ${JSON.stringify(r, null, 2)}`,
2168
2225
  isError: !0
2169
2226
  };
2170
2227
  }
2171
2228
  }), i.set("add_portlet", async (e) => {
2172
- const l = {
2229
+ const r = {
2173
2230
  number: "kpiNumber",
2174
2231
  retention: "retentionHeatmap"
2175
2232
  }[e.chartType] ?? e.chartType;
2176
- let d;
2233
+ let s;
2177
2234
  try {
2178
- d = JSON.parse(e.query);
2235
+ s = JSON.parse(e.query);
2179
2236
  } catch {
2180
2237
  return {
2181
2238
  result: "Invalid query: could not parse JSON string. Ensure `query` is a valid JSON string.",
2182
2239
  isError: !0
2183
2240
  };
2184
2241
  }
2185
- const u = t.validateQuery(d);
2186
- if (!u.isValid)
2242
+ const m = t.validateQuery(s);
2243
+ if (!m.isValid)
2187
2244
  return {
2188
2245
  result: `Invalid query — fix these errors and retry:
2189
- ${u.errors.join(`
2190
- `)}`,
2246
+ ${m.errors.join(`
2247
+ `)}
2248
+
2249
+ Attempted query:
2250
+ ${JSON.stringify(s, null, 2)}`,
2191
2251
  isError: !0
2192
2252
  };
2193
- const p = !!(d.funnel || d.flow || d.retention);
2194
- let m;
2195
- if (p)
2196
- m = e.chartConfig ?? {};
2253
+ const f = !!(s.funnel || s.flow || s.retention);
2254
+ let y;
2255
+ if (f)
2256
+ y = e.chartConfig ?? {};
2197
2257
  else {
2198
- const y = Te(l, e.chartConfig, d), f = Ce(l, y, d);
2199
- if (!f.isValid)
2258
+ const b = Te(r, e.chartConfig, s), c = Ce(r, b, s);
2259
+ if (!c.isValid)
2200
2260
  return {
2201
2261
  result: `Chart config invalid — fix these errors and retry:
2202
- ${f.errors.join(`
2262
+ ${c.errors.join(`
2203
2263
  `)}`,
2204
2264
  isError: !0
2205
2265
  };
2206
- m = y;
2266
+ y = b;
2207
2267
  }
2208
- const n = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, b = {
2268
+ const n = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, x = {
2209
2269
  id: n,
2210
2270
  title: e.title,
2211
2271
  query: e.query,
2212
- chartType: l,
2213
- chartConfig: m,
2272
+ chartType: r,
2273
+ chartConfig: y,
2214
2274
  displayConfig: e.displayConfig
2215
2275
  };
2216
2276
  return {
2217
- result: `Portlet "${e.title}" added to notebook (id: ${n}, chart: ${l}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
2218
- sideEffect: { type: "add_portlet", data: b }
2277
+ result: `Portlet "${e.title}" added to notebook (id: ${n}, chart: ${r}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
2278
+ sideEffect: { type: "add_portlet", data: x }
2219
2279
  };
2220
2280
  }), i.set("add_markdown", async (e) => {
2221
- const s = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, l = {
2222
- id: s,
2281
+ const o = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, r = {
2282
+ id: o,
2223
2283
  title: e.title,
2224
2284
  content: e.content
2225
2285
  };
2226
2286
  return {
2227
- result: `Markdown block added to notebook (id: ${s}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
2228
- sideEffect: { type: "add_markdown", data: l }
2287
+ result: `Markdown block added to notebook (id: ${o}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
2288
+ sideEffect: { type: "add_markdown", data: r }
2229
2289
  };
2230
2290
  }), i.set("save_as_dashboard", async (e) => {
2231
2291
  try {
2232
- const s = e.portlets;
2233
- if (!s || s.length === 0)
2292
+ const o = e.portlets;
2293
+ if (!o || o.length === 0)
2234
2294
  return { result: "Dashboard must contain at least one portlet.", isError: !0 };
2235
- const l = [];
2236
- for (const n of s) {
2295
+ const r = [];
2296
+ for (const n of o) {
2237
2297
  if (n.chartType === "markdown") continue;
2238
- const y = n.query;
2239
- if (!y) {
2240
- l.push(`Portlet "${n.title}": missing query`);
2298
+ const b = n.query;
2299
+ if (!b) {
2300
+ r.push(`Portlet "${n.title}": missing query`);
2241
2301
  continue;
2242
2302
  }
2243
- let f;
2303
+ let c;
2244
2304
  try {
2245
- f = JSON.parse(y);
2305
+ c = JSON.parse(b);
2246
2306
  } catch {
2247
- l.push(`Portlet "${n.title}": invalid JSON query`);
2307
+ r.push(`Portlet "${n.title}": invalid JSON query`);
2248
2308
  continue;
2249
2309
  }
2250
- const v = t.validateQuery(f);
2251
- v.isValid || l.push(`Portlet "${n.title}": ${v.errors.join(", ")}`);
2310
+ const g = t.validateQuery(c);
2311
+ g.isValid || r.push(`Portlet "${n.title}": ${g.errors.join(", ")}`);
2252
2312
  }
2253
- if (l.length > 0)
2313
+ if (r.length > 0)
2254
2314
  return {
2255
2315
  result: `Dashboard has invalid portlets — fix these errors and retry:
2256
- ${l.join(`
2316
+ ${r.join(`
2257
2317
  `)}`,
2258
2318
  isError: !0
2259
2319
  };
2260
- const d = {
2261
- portlets: s.map((n) => {
2262
- const b = n.chartType, y = b === "markdown", f = y ? "query" : n.analysisType || "query", v = f === "funnel" ? "funnel" : f === "flow" ? "flow" : f === "retention" ? "retention" : "query", D = n.query || "{}";
2263
- let g;
2320
+ const s = {
2321
+ portlets: o.map((n) => {
2322
+ const x = n.chartType, b = x === "markdown", c = b ? "query" : n.analysisType || "query", g = c === "funnel" ? "funnel" : c === "flow" ? "flow" : c === "retention" ? "retention" : "query", A = n.query || "{}";
2323
+ let C;
2264
2324
  try {
2265
- g = JSON.parse(D);
2325
+ C = JSON.parse(A);
2266
2326
  } catch {
2267
- g = {};
2327
+ C = {};
2268
2328
  }
2269
- const C = {
2329
+ const k = {
2270
2330
  version: 1,
2271
- analysisType: v,
2331
+ analysisType: g,
2272
2332
  activeView: "chart",
2273
2333
  charts: {
2274
- [v]: {
2275
- chartType: b,
2334
+ [g]: {
2335
+ chartType: x,
2276
2336
  chartConfig: n.chartConfig || {},
2277
2337
  displayConfig: n.displayConfig || {}
2278
2338
  }
2279
2339
  },
2280
- query: y ? {} : g
2340
+ query: b ? {} : C
2281
2341
  };
2282
2342
  return {
2283
2343
  id: n.id,
2284
2344
  title: n.title,
2285
- analysisConfig: C,
2345
+ analysisConfig: k,
2286
2346
  dashboardFilterMapping: n.dashboardFilterMapping,
2287
2347
  w: n.w,
2288
2348
  h: n.h,
@@ -2292,35 +2352,35 @@ ${l.join(`
2292
2352
  }),
2293
2353
  filters: e.filters,
2294
2354
  colorPalette: e.colorPalette
2295
- }, u = e.title, p = d.portlets.length, m = d.filters?.length || 0;
2355
+ }, m = e.title, f = s.portlets.length, y = s.filters?.length || 0;
2296
2356
  return {
2297
- result: `Dashboard "${u}" created with ${p} portlets and ${m} filters.`,
2357
+ result: `Dashboard "${m}" created with ${f} portlets and ${y} filters.`,
2298
2358
  sideEffect: {
2299
2359
  type: "dashboard_saved",
2300
2360
  data: {
2301
- title: u,
2361
+ title: m,
2302
2362
  description: e.description,
2303
- dashboardConfig: d
2363
+ dashboardConfig: s
2304
2364
  }
2305
2365
  }
2306
2366
  };
2307
- } catch (s) {
2367
+ } catch (o) {
2308
2368
  return {
2309
- result: `Failed to save dashboard: ${s instanceof Error ? s.message : "Unknown error"}`,
2369
+ result: `Failed to save dashboard: ${o instanceof Error ? o.message : "Unknown error"}`,
2310
2370
  isError: !0
2311
2371
  };
2312
2372
  }
2313
2373
  }), i;
2314
2374
  }
2315
- async function* Ee(o) {
2316
- const { message: t, history: a, semanticLayer: i, securityContext: e, agentConfig: s, apiKey: l } = o, d = o.sessionId || crypto.randomUUID(), u = s.observability, p = crypto.randomUUID(), m = Date.now();
2317
- let n;
2375
+ async function* _e(l) {
2376
+ const { message: t, history: a, semanticLayer: i, securityContext: d, agentConfig: u, apiKey: e } = l, o = l.sessionId || crypto.randomUUID(), r = u.observability, s = crypto.randomUUID(), m = Date.now();
2377
+ let f;
2318
2378
  try {
2319
- const c = await import(
2379
+ const h = await import(
2320
2380
  /* webpackIgnore: true */
2321
2381
  "@anthropic-ai/sdk"
2322
2382
  );
2323
- n = c.default || c.Anthropic || c;
2383
+ f = h.default || h.Anthropic || h;
2324
2384
  } catch {
2325
2385
  yield {
2326
2386
  type: "error",
@@ -2330,171 +2390,171 @@ async function* Ee(o) {
2330
2390
  };
2331
2391
  return;
2332
2392
  }
2333
- const b = new n({ apiKey: l }), y = De(), f = Se({ semanticLayer: i, securityContext: e }), v = i.getMetadata(), D = W(v), g = s.model || "claude-sonnet-4-6", C = s.maxTurns || 25, S = s.maxTokens || 4096;
2393
+ const y = new f({ apiKey: e }), n = De(), x = Se({ semanticLayer: i, securityContext: d }), b = i.getMetadata(), c = W(b), g = u.model || "claude-sonnet-4-6", A = u.maxTurns || 25, C = u.maxTokens || 4096;
2334
2394
  try {
2335
- u?.onChatStart?.({
2336
- traceId: p,
2337
- sessionId: d,
2395
+ r?.onChatStart?.({
2396
+ traceId: s,
2397
+ sessionId: o,
2338
2398
  message: t,
2339
2399
  model: g,
2340
2400
  historyLength: a?.length ?? 0
2341
2401
  });
2342
2402
  } catch {
2343
2403
  }
2344
- const x = [];
2404
+ const k = [];
2345
2405
  if (a && a.length > 0) {
2346
- for (const c of a)
2347
- if (c.role === "user")
2348
- x.push({ role: "user", content: c.content });
2349
- else if (c.role === "assistant") {
2406
+ for (const h of a)
2407
+ if (h.role === "user")
2408
+ k.push({ role: "user", content: h.content });
2409
+ else if (h.role === "assistant") {
2350
2410
  const F = [];
2351
- if (c.content && F.push({ type: "text", text: c.content }), c.toolCalls && c.toolCalls.length > 0) {
2352
- for (const h of c.toolCalls)
2411
+ if (h.content && F.push({ type: "text", text: h.content }), h.toolCalls && h.toolCalls.length > 0) {
2412
+ for (const w of h.toolCalls)
2353
2413
  F.push({
2354
2414
  type: "tool_use",
2355
- id: h.id,
2356
- name: h.name,
2357
- input: h.input || {}
2415
+ id: w.id,
2416
+ name: w.name,
2417
+ input: w.input || {}
2358
2418
  });
2359
- x.push({ role: "assistant", content: F }), x.push({
2419
+ k.push({ role: "assistant", content: F }), k.push({
2360
2420
  role: "user",
2361
- content: c.toolCalls.map((h) => ({
2421
+ content: h.toolCalls.map((w) => ({
2362
2422
  type: "tool_result",
2363
- tool_use_id: h.id,
2364
- content: typeof h.result == "string" ? h.result : JSON.stringify(h.result ?? ""),
2365
- ...h.status === "error" ? { is_error: !0 } : {}
2423
+ tool_use_id: w.id,
2424
+ content: typeof w.result == "string" ? w.result : JSON.stringify(w.result ?? ""),
2425
+ ...w.status === "error" ? { is_error: !0 } : {}
2366
2426
  }))
2367
2427
  });
2368
- } else F.length > 0 && x.push({ role: "assistant", content: c.content });
2428
+ } else F.length > 0 && k.push({ role: "assistant", content: h.content });
2369
2429
  }
2370
2430
  }
2371
- x.push({ role: "user", content: t });
2372
- let V = 0;
2431
+ k.push({ role: "user", content: t });
2432
+ let E = 0;
2373
2433
  try {
2374
- for (let c = 0; c < C; c++) {
2375
- V = c + 1;
2376
- const F = await b.messages.create({
2434
+ for (let h = 0; h < A; h++) {
2435
+ E = h + 1;
2436
+ const F = await y.messages.create({
2377
2437
  model: g,
2378
- max_tokens: S,
2379
- system: D,
2380
- tools: y,
2381
- messages: x,
2438
+ max_tokens: C,
2439
+ system: c,
2440
+ tools: n,
2441
+ messages: k,
2382
2442
  stream: !0
2383
- }), h = [];
2384
- let q = -1, _ = "", O = "", L, R;
2385
- const H = Date.now();
2386
- for await (const w of F)
2387
- switch (w.type) {
2443
+ }), w = [];
2444
+ let q = -1, V = "", O = "", L, M;
2445
+ const z = Date.now();
2446
+ for await (const v of F)
2447
+ switch (v.type) {
2388
2448
  case "content_block_start": {
2389
2449
  q++;
2390
- const r = w.content_block;
2391
- r.type === "tool_use" ? (h.push({ type: "tool_use", id: r.id, name: r.name, input: {} }), _ = "", yield {
2450
+ const p = v.content_block;
2451
+ p.type === "tool_use" ? (w.push({ type: "tool_use", id: p.id, name: p.name, input: {} }), V = "", yield {
2392
2452
  type: "tool_use_start",
2393
- data: { id: r.id, name: r.name, input: void 0 }
2394
- }) : r.type === "text" && h.push({ type: "text", text: "" });
2453
+ data: { id: p.id, name: p.name, input: void 0 }
2454
+ }) : p.type === "text" && w.push({ type: "text", text: "" });
2395
2455
  break;
2396
2456
  }
2397
2457
  case "content_block_delta": {
2398
- const r = w.delta;
2399
- if (r.type === "text_delta" && r.text) {
2400
- const T = h[q];
2401
- T && (T.text = (T.text || "") + r.text), yield { type: "text_delta", data: r.text };
2402
- } else r.type === "input_json_delta" && r.partial_json && (_ += r.partial_json);
2458
+ const p = v.delta;
2459
+ if (p.type === "text_delta" && p.text) {
2460
+ const D = w[q];
2461
+ D && (D.text = (D.text || "") + p.text), yield { type: "text_delta", data: p.text };
2462
+ } else p.type === "input_json_delta" && p.partial_json && (V += p.partial_json);
2403
2463
  break;
2404
2464
  }
2405
2465
  case "content_block_stop": {
2406
- const r = h[q];
2407
- if (r?.type === "tool_use" && _) {
2466
+ const p = w[q];
2467
+ if (p?.type === "tool_use" && V) {
2408
2468
  try {
2409
- r.input = JSON.parse(_);
2469
+ p.input = JSON.parse(V);
2410
2470
  } catch {
2411
- r.input = {};
2471
+ p.input = {};
2412
2472
  }
2413
- _ = "";
2473
+ V = "";
2414
2474
  }
2415
2475
  break;
2416
2476
  }
2417
2477
  case "message_start": {
2418
- const r = w.message;
2419
- r?.usage?.input_tokens != null && (L = r.usage.input_tokens);
2478
+ const p = v.message;
2479
+ p?.usage?.input_tokens != null && (L = p.usage.input_tokens);
2420
2480
  break;
2421
2481
  }
2422
2482
  case "message_delta": {
2423
- const r = w.delta, T = w.usage;
2424
- T?.output_tokens != null && (R = T.output_tokens), r.stop_reason && (O = r.stop_reason);
2483
+ const p = v.delta, D = v.usage;
2484
+ D?.output_tokens != null && (M = D.output_tokens), p.stop_reason && (O = p.stop_reason);
2425
2485
  break;
2426
2486
  }
2427
2487
  }
2428
2488
  try {
2429
- u?.onGenerationEnd?.({
2430
- traceId: p,
2431
- turn: c,
2489
+ r?.onGenerationEnd?.({
2490
+ traceId: s,
2491
+ turn: h,
2432
2492
  model: g,
2433
2493
  stopReason: O,
2434
2494
  inputTokens: L,
2435
- outputTokens: R,
2436
- durationMs: Date.now() - H
2495
+ outputTokens: M,
2496
+ durationMs: Date.now() - z
2437
2497
  });
2438
2498
  } catch {
2439
2499
  }
2440
- if (x.push({ role: "assistant", content: h }), O !== "tool_use")
2500
+ if (k.push({ role: "assistant", content: w }), O !== "tool_use")
2441
2501
  break;
2442
- const E = [];
2443
- for (const w of h) {
2444
- if (w.type !== "tool_use") continue;
2445
- const r = w.name, T = w.input || {}, A = w.id, M = f.get(r);
2446
- if (!M) {
2447
- E.push({
2502
+ const _ = [];
2503
+ for (const v of w) {
2504
+ if (v.type !== "tool_use") continue;
2505
+ const p = v.name, D = v.input || {}, S = v.id, R = x.get(p);
2506
+ if (!R) {
2507
+ _.push({
2448
2508
  type: "tool_result",
2449
- tool_use_id: A,
2450
- content: `Unknown tool: ${r}`,
2509
+ tool_use_id: S,
2510
+ content: `Unknown tool: ${p}`,
2451
2511
  is_error: !0
2452
2512
  }), yield {
2453
2513
  type: "tool_use_result",
2454
- data: { id: A, name: r, result: `Unknown tool: ${r}`, isError: !0 }
2514
+ data: { id: S, name: p, result: `Unknown tool: ${p}`, isError: !0 }
2455
2515
  };
2456
2516
  continue;
2457
2517
  }
2458
2518
  const Y = Date.now();
2459
2519
  try {
2460
- const k = await M(T);
2461
- k.sideEffect && (yield k.sideEffect), E.push({
2520
+ const T = await R(D);
2521
+ T.sideEffect && (yield T.sideEffect), _.push({
2462
2522
  type: "tool_result",
2463
- tool_use_id: A,
2464
- content: k.result,
2465
- ...k.isError ? { is_error: !0 } : {}
2523
+ tool_use_id: S,
2524
+ content: T.result,
2525
+ ...T.isError ? { is_error: !0 } : {}
2466
2526
  }), yield {
2467
2527
  type: "tool_use_result",
2468
- data: { id: A, name: r, result: k.result, ...k.isError ? { isError: !0 } : {} }
2528
+ data: { id: S, name: p, result: T.result, ...T.isError ? { isError: !0 } : {} }
2469
2529
  };
2470
2530
  try {
2471
- u?.onToolEnd?.({
2472
- traceId: p,
2473
- turn: c,
2474
- toolName: r,
2475
- toolUseId: A,
2476
- isError: !!k.isError,
2531
+ r?.onToolEnd?.({
2532
+ traceId: s,
2533
+ turn: h,
2534
+ toolName: p,
2535
+ toolUseId: S,
2536
+ isError: !!T.isError,
2477
2537
  durationMs: Date.now() - Y
2478
2538
  });
2479
2539
  } catch {
2480
2540
  }
2481
- } catch (k) {
2482
- const z = k instanceof Error ? k.message : "Tool execution failed";
2483
- E.push({
2541
+ } catch (T) {
2542
+ const $ = T instanceof Error ? T.message : "Tool execution failed";
2543
+ _.push({
2484
2544
  type: "tool_result",
2485
- tool_use_id: A,
2486
- content: z,
2545
+ tool_use_id: S,
2546
+ content: $,
2487
2547
  is_error: !0
2488
2548
  }), yield {
2489
2549
  type: "tool_use_result",
2490
- data: { id: A, name: r, result: z, isError: !0 }
2550
+ data: { id: S, name: p, result: $, isError: !0 }
2491
2551
  };
2492
2552
  try {
2493
- u?.onToolEnd?.({
2494
- traceId: p,
2495
- turn: c,
2496
- toolName: r,
2497
- toolUseId: A,
2553
+ r?.onToolEnd?.({
2554
+ traceId: s,
2555
+ turn: h,
2556
+ toolName: p,
2557
+ toolUseId: S,
2498
2558
  isError: !0,
2499
2559
  durationMs: Date.now() - Y
2500
2560
  });
@@ -2502,60 +2562,60 @@ async function* Ee(o) {
2502
2562
  }
2503
2563
  }
2504
2564
  }
2505
- yield { type: "turn_complete", data: {} }, x.push({ role: "user", content: E });
2565
+ yield { type: "turn_complete", data: {} }, k.push({ role: "user", content: _ });
2506
2566
  }
2507
2567
  try {
2508
- u?.onChatEnd?.({
2509
- traceId: p,
2510
- sessionId: d,
2511
- totalTurns: V,
2568
+ r?.onChatEnd?.({
2569
+ traceId: s,
2570
+ sessionId: o,
2571
+ totalTurns: E,
2512
2572
  durationMs: Date.now() - m
2513
2573
  });
2514
2574
  } catch {
2515
2575
  }
2516
2576
  yield {
2517
2577
  type: "done",
2518
- data: { sessionId: d || "", traceId: p }
2578
+ data: { sessionId: o || "", traceId: s }
2519
2579
  };
2520
- } catch (c) {
2580
+ } catch (h) {
2521
2581
  try {
2522
- u?.onChatEnd?.({
2523
- traceId: p,
2524
- sessionId: d,
2582
+ r?.onChatEnd?.({
2583
+ traceId: s,
2584
+ sessionId: o,
2525
2585
  totalTurns: 0,
2526
2586
  durationMs: Date.now() - m,
2527
- error: c instanceof Error ? c.message : "Unknown error"
2587
+ error: h instanceof Error ? h.message : "Unknown error"
2528
2588
  });
2529
2589
  } catch {
2530
2590
  }
2531
2591
  yield {
2532
2592
  type: "error",
2533
2593
  data: {
2534
- message: Fe(c)
2594
+ message: Fe(h)
2535
2595
  }
2536
2596
  };
2537
2597
  }
2538
2598
  }
2539
- function Fe(o) {
2540
- if (!o || !(o instanceof Error))
2599
+ function Fe(l) {
2600
+ if (!l || !(l instanceof Error))
2541
2601
  return "Something went wrong. Please try again.";
2542
- const t = o.message || "", a = {
2602
+ const t = l.message || "", a = {
2543
2603
  overloaded_error: "The AI service is temporarily overloaded. Please try again in a moment.",
2544
2604
  rate_limit_error: "Too many requests. Please wait a moment and try again.",
2545
2605
  api_error: "The AI service encountered an error. Please try again.",
2546
2606
  authentication_error: "Authentication failed. Please check your API key configuration.",
2547
2607
  invalid_request_error: "There was a problem with the request. Please try again."
2548
- }, i = o;
2608
+ }, i = l;
2549
2609
  if (i.status || i.type) {
2550
- const e = i.error?.type || i.type || "";
2551
- if (a[e])
2552
- return a[e];
2610
+ const d = i.error?.type || i.type || "";
2611
+ if (a[d])
2612
+ return a[d];
2553
2613
  }
2554
2614
  if (t.startsWith("{") || t.startsWith("Error: {")) {
2555
2615
  try {
2556
- const e = JSON.parse(t.replace(/^Error:\s*/, "")), s = e.error?.type || e.type || "";
2557
- if (a[s])
2558
- return a[s];
2616
+ const d = JSON.parse(t.replace(/^Error:\s*/, "")), u = d.error?.type || d.type || "";
2617
+ if (a[u])
2618
+ return a[u];
2559
2619
  } catch {
2560
2620
  }
2561
2621
  return "The AI service encountered an error. Please try again.";
@@ -2563,5 +2623,5 @@ function Fe(o) {
2563
2623
  return t;
2564
2624
  }
2565
2625
  export {
2566
- Ee as handleAgentChat
2626
+ _e as handleAgentChat
2567
2627
  };