drizzle-cube 0.4.9 → 0.4.10

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 (34) hide show
  1. package/dist/adapters/express/index.cjs +1 -1
  2. package/dist/adapters/express/index.js +1 -1
  3. package/dist/adapters/fastify/index.cjs +1 -1
  4. package/dist/adapters/fastify/index.js +1 -1
  5. package/dist/adapters/{handler-CSHsefnC.js → handler-CySCodwi.js} +213 -172
  6. package/dist/adapters/{handler-Xe_2ItOo.cjs → handler-e6zofK2k.cjs} +11 -11
  7. package/dist/adapters/hono/index.cjs +1 -1
  8. package/dist/adapters/hono/index.js +1 -1
  9. package/dist/adapters/nextjs/index.cjs +1 -1
  10. package/dist/adapters/nextjs/index.js +1 -1
  11. package/dist/client/charts.js +4 -4
  12. package/dist/client/chunks/{analysis-builder-DFt9p8tj.js → analysis-builder-BMmWeFPr.js} +4 -4
  13. package/dist/client/chunks/{analysis-builder-DFt9p8tj.js.map → analysis-builder-BMmWeFPr.js.map} +1 -1
  14. package/dist/client/chunks/{analysis-builder-shared-DOHV2W8A.js → analysis-builder-shared-D56zYeV0.js} +2 -2
  15. package/dist/client/chunks/{analysis-builder-shared-DOHV2W8A.js.map → analysis-builder-shared-D56zYeV0.js.map} +1 -1
  16. package/dist/client/chunks/{chart-area-QKKboTbq.js → chart-area-BJAgusst.js} +2 -2
  17. package/dist/client/chunks/{chart-area-QKKboTbq.js.map → chart-area-BJAgusst.js.map} +1 -1
  18. package/dist/client/chunks/chart-bar-Blypx8O4.js +267 -0
  19. package/dist/client/chunks/chart-bar-Blypx8O4.js.map +1 -0
  20. package/dist/client/chunks/{chart-line-C7YcMWBw.js → chart-line-zi6olZet.js} +2 -2
  21. package/dist/client/chunks/{chart-line-C7YcMWBw.js.map → chart-line-zi6olZet.js.map} +1 -1
  22. package/dist/client/chunks/{charts-loader-HYQFVOo4.js → charts-loader-CH0_S06T.js} +4 -4
  23. package/dist/client/chunks/{charts-loader-HYQFVOo4.js.map → charts-loader-CH0_S06T.js.map} +1 -1
  24. package/dist/client/chunks/{components-8FAXo62Z.js → components-ClQziOcT.js} +3 -3
  25. package/dist/client/chunks/{components-8FAXo62Z.js.map → components-ClQziOcT.js.map} +1 -1
  26. package/dist/client/components.js +1 -1
  27. package/dist/client/index.js +4 -4
  28. package/dist/client/utils.js +1 -1
  29. package/dist/client-bundle-stats.html +1 -1
  30. package/dist/server/index.cjs +3 -3
  31. package/dist/server/index.js +51 -10
  32. package/package.json +1 -1
  33. package/dist/client/chunks/chart-bar-HpXF42H1.js +0 -254
  34. package/dist/client/chunks/chart-bar-HpXF42H1.js.map +0 -1
@@ -1,40 +1,40 @@
1
- import { h as q, Q as N, j as P, D as Y } from "./mcp-transport-CU5g9bxj.js";
2
- import { handleDiscover as z, handleLoad as M } from "./utils.js";
3
- function R(r) {
4
- if (r.length === 0)
1
+ import { h as O, Q as q, j as P, D as Y } from "./mcp-transport-CU5g9bxj.js";
2
+ import { handleDiscover as z, handleLoad as R } from "./utils.js";
3
+ function M(o) {
4
+ if (o.length === 0)
5
5
  return "No cubes are currently available.";
6
6
  const t = ["## Available Cubes", ""];
7
- for (const i of r) {
7
+ for (const i of o) {
8
8
  if (t.push(`### ${i.name}`), i.description && t.push(i.description), i.measures && i.measures.length > 0) {
9
9
  t.push(""), t.push("**Measures:**");
10
- for (const a of i.measures) {
11
- const e = a.description ? ` - ${a.description}` : "";
12
- t.push(`- \`${i.name}.${a.name}\` (${a.type})${e}`);
10
+ for (const s of i.measures) {
11
+ const e = s.description ? ` - ${s.description}` : "";
12
+ t.push(`- \`${i.name}.${s.name}\` (${s.type})${e}`);
13
13
  }
14
14
  }
15
15
  if (i.dimensions && i.dimensions.length > 0) {
16
16
  t.push(""), t.push("**Dimensions:**");
17
- for (const a of i.dimensions) {
18
- const e = a.description ? ` - ${a.description}` : "";
19
- t.push(`- \`${i.name}.${a.name}\` (${a.type})${e}`);
17
+ for (const s of i.dimensions) {
18
+ const e = s.description ? ` - ${s.description}` : "";
19
+ t.push(`- \`${i.name}.${s.name}\` (${s.type})${e}`);
20
20
  }
21
21
  }
22
22
  if (i.relationships && i.relationships.length > 0) {
23
23
  t.push(""), t.push("**Joins:**");
24
- for (const a of i.relationships)
25
- t.push(`- → \`${a.targetCube}\` (${a.relationship})`);
24
+ for (const s of i.relationships)
25
+ t.push(`- → \`${s.targetCube}\` (${s.relationship})`);
26
26
  }
27
27
  i.meta?.eventStream && (t.push(""), t.push("**Event Stream:** Yes (supports funnel, flow, retention queries)"), i.meta.eventStream.bindingKey && t.push(`- Binding key: \`${i.name}.${i.meta.eventStream.bindingKey}\``), i.meta.eventStream.timeDimension && t.push(`- Time dimension: \`${i.name}.${i.meta.eventStream.timeDimension}\``)), t.push("");
28
28
  }
29
29
  return t.join(`
30
30
  `);
31
31
  }
32
- function F(r) {
33
- return r.messages.map((t) => t.content.text).join(`
32
+ function S(o) {
33
+ return o.messages.map((t) => t.content.text).join(`
34
34
 
35
35
  `);
36
36
  }
37
- function L(r) {
37
+ function L(o) {
38
38
  return [
39
39
  "# Drizzle Cube Analytics Agent",
40
40
  "",
@@ -111,6 +111,21 @@ function L(r) {
111
111
  "",
112
112
  '**Chart selection priorities:** Default to `bar` for categories, `line` for time series, `table` for exploratory data. Use `kpiNumber`/`kpiDelta` only as a last resort — they are appropriate only when the user explicitly asks for a single headline number or KPI card. If the query returns multiple rows or the user asks a general question like "show me revenue", prefer `bar` or `table` over `kpiNumber`.',
113
113
  "",
114
+ "## Chart Axis Configuration Rules",
115
+ "",
116
+ "**Bar charts MUST have an xAxis.** Put a dimension in `chartConfig.xAxis` so bars have category labels. If your query has no dimensions, add one or use `table` instead.",
117
+ "",
118
+ "**Never duplicate xAxis in series.** Putting the same dimension in both `xAxis` and `series` creates a sparse, broken-looking chart. The `series` field is ONLY for splitting bars into grouped/stacked sub-series by a SECOND dimension.",
119
+ "",
120
+ "Correct bar chart examples:",
121
+ '- Categories only: `xAxis: ["Cube.category"], yAxis: ["Cube.count"]` — no series needed',
122
+ '- Grouped bars: `xAxis: ["Cube.category"], yAxis: ["Cube.count"], series: ["Cube.status"]` — series is a DIFFERENT dimension',
123
+ '- Multiple measures: `xAxis: ["Cube.category"], yAxis: ["Cube.count", "Cube.total"]` — each measure becomes a bar group',
124
+ "",
125
+ "Wrong:",
126
+ '- `xAxis: [], yAxis: ["Cube.avg1", "Cube.avg2"]` — missing xAxis, bars have no labels',
127
+ '- `xAxis: ["Cube.size"], series: ["Cube.size"]` — same field in both, creates sparse chart',
128
+ "",
114
129
  "## Analysis Mode Decision Tree",
115
130
  "",
116
131
  "The default mode is **query** (standard measures/dimensions). Switch to a special mode only when the user's question matches:",
@@ -139,27 +154,27 @@ function L(r) {
139
154
  "",
140
155
  "---",
141
156
  "",
142
- F(q),
157
+ S(O),
143
158
  "",
144
159
  "---",
145
160
  "",
146
- F(N),
161
+ S(q),
147
162
  "",
148
163
  "---",
149
164
  "",
150
- F(P),
165
+ S(P),
151
166
  "",
152
167
  "---",
153
168
  "",
154
- F(Y),
169
+ S(Y),
155
170
  "",
156
171
  "---",
157
172
  "",
158
- R(r)
173
+ M(o)
159
174
  ].join(`
160
175
  `);
161
176
  }
162
- const H = {
177
+ const $ = {
163
178
  label: "Bar Chart",
164
179
  description: "Compare values across categories",
165
180
  useCase: "Best for comparing discrete categories, showing rankings, or displaying changes over time",
@@ -225,7 +240,7 @@ const H = {
225
240
  description: "Number formatting for right Y-axis"
226
241
  }
227
242
  ]
228
- }, $ = {
243
+ }, B = {
229
244
  label: "Line Chart",
230
245
  description: "Show trends and changes over time",
231
246
  useCase: "Best for continuous data, trends, time series, and showing relationships between multiple series",
@@ -308,7 +323,7 @@ const H = {
308
323
  description: "Number formatting for right Y-axis"
309
324
  }
310
325
  ]
311
- }, B = {
326
+ }, H = {
312
327
  label: "Area Chart",
313
328
  description: "Emphasize magnitude of change over time",
314
329
  useCase: "Best for showing cumulative totals, volume changes, or stacked comparisons over time",
@@ -698,8 +713,8 @@ const H = {
698
713
  description: "Automatically size blocks to fill portlet width and height while maintaining aspect ratio"
699
714
  }
700
715
  ],
701
- validate: (r) => {
702
- const { dateField: t, valueField: i } = r;
716
+ validate: (o) => {
717
+ const { dateField: t, valueField: i } = o;
703
718
  return !t || Array.isArray(t) && t.length === 0 ? {
704
719
  isValid: !1,
705
720
  message: "Time dimension is required for activity grid"
@@ -867,7 +882,7 @@ const H = {
867
882
  }
868
883
  ],
869
884
  displayOptions: ["hideHeader"],
870
- validate: (r) => !r.yAxis || Array.isArray(r.yAxis) && r.yAxis.length === 0 ? {
885
+ validate: (o) => !o.yAxis || Array.isArray(o.yAxis) && o.yAxis.length === 0 ? {
871
886
  isValid: !1,
872
887
  message: "A measure is required for KPI Delta charts"
873
888
  } : { isValid: !0 }
@@ -1005,7 +1020,7 @@ Use --- for horizontal rules.`,
1005
1020
  description: "Add an accent-colored border on one side of the content"
1006
1021
  }
1007
1022
  ]
1008
- }, ae = {
1023
+ }, se = {
1009
1024
  label: "Funnel Chart",
1010
1025
  description: "Show conversion through sequential steps",
1011
1026
  useCase: "Best for visualizing user journey funnels, sales pipelines, or multi-step processes",
@@ -1092,7 +1107,7 @@ Use --- for horizontal rules.`,
1092
1107
  description: "Display 90th percentile time to convert"
1093
1108
  }
1094
1109
  ]
1095
- }, se = {
1110
+ }, ae = {
1096
1111
  label: "Sankey Chart",
1097
1112
  description: "Show flow between states or steps",
1098
1113
  useCase: "Best for visualizing user journey flows, path analysis, or state transitions",
@@ -1264,7 +1279,7 @@ Use --- for horizontal rules.`,
1264
1279
  description: "Number formatting for cell values and legend"
1265
1280
  }
1266
1281
  ],
1267
- validate: (r) => r.xAxis?.length ? r.yAxis?.length ? r.valueField?.length ? { isValid: !0 } : { isValid: !1, message: "Value measure required" } : { isValid: !1, message: "Y-axis dimension required" } : { isValid: !1, message: "X-axis dimension required" }
1282
+ 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" }
1268
1283
  }, ne = {
1269
1284
  label: "Retention Matrix",
1270
1285
  // RetentionHeatmap auto-configures from the retention data structure
@@ -1413,9 +1428,9 @@ Use --- for horizontal rules.`,
1413
1428
  }
1414
1429
  ]
1415
1430
  }, V = {
1416
- bar: H,
1417
- line: $,
1418
- area: B,
1431
+ bar: $,
1432
+ line: B,
1433
+ area: H,
1419
1434
  pie: j,
1420
1435
  scatter: K,
1421
1436
  bubble: G,
@@ -1428,87 +1443,113 @@ Use --- for horizontal rules.`,
1428
1443
  kpiDelta: ee,
1429
1444
  kpiText: te,
1430
1445
  markdown: ie,
1431
- funnel: ae,
1432
- sankey: se,
1446
+ funnel: se,
1447
+ sankey: ae,
1433
1448
  sunburst: oe,
1434
1449
  heatmap: re,
1435
1450
  retentionHeatmap: ne,
1436
1451
  retentionCombined: le,
1437
1452
  boxPlot: de
1438
1453
  };
1439
- function pe(r, t, i) {
1440
- const a = V[r];
1441
- if (!a)
1454
+ function pe(o, t, i) {
1455
+ const s = V[o];
1456
+ if (!s)
1442
1457
  return { isValid: !0, errors: [] };
1443
- if (a.skipQuery)
1458
+ if (s.skipQuery)
1444
1459
  return { isValid: !0, errors: [] };
1445
1460
  const e = [];
1446
- for (const s of a.dropZones) {
1447
- if (!s.mandatory) continue;
1448
- const n = t?.[s.key];
1461
+ for (const a of s.dropZones) {
1462
+ if (!a.mandatory) continue;
1463
+ const n = t?.[a.key];
1449
1464
  if (!(Array.isArray(n) ? n.length > 0 : !!n)) {
1450
- const m = s.acceptTypes?.join("/") ?? "fields";
1465
+ const u = a.acceptTypes?.join("/") ?? "fields";
1451
1466
  e.push(
1452
- `chartConfig.${s.key} is required for ${r} chart (${s.label}). Accepts: ${m}.`
1467
+ `chartConfig.${a.key} is required for ${o} chart (${a.label}). Accepts: ${u}.`
1453
1468
  );
1454
1469
  }
1455
1470
  }
1471
+ if (o === "bar") {
1472
+ const a = t?.xAxis;
1473
+ if (!(Array.isArray(a) ? a.length > 0 : !!a)) {
1474
+ const l = i.dimensions ?? [], u = i.timeDimensions ?? [];
1475
+ l.length > 0 || u.length > 0 ? e.push(
1476
+ "chartConfig.xAxis is required for bar charts. Put a dimension in xAxis so bars have category labels."
1477
+ ) : e.push(
1478
+ 'Bar charts need an xAxis dimension for category labels. Add a dimension to the query or use "table" chart type instead.'
1479
+ );
1480
+ }
1481
+ }
1482
+ if (t?.xAxis && t?.series) {
1483
+ const a = new Set(
1484
+ Array.isArray(t.xAxis) ? t.xAxis : [t.xAxis]
1485
+ ), l = (Array.isArray(t.series) ? t.series : [t.series]).filter((u) => a.has(u));
1486
+ l.length > 0 && e.push(
1487
+ `chartConfig.series must not contain the same field as xAxis (found: ${l.join(", ")}). The series field is only for splitting into grouped/stacked sub-series by a DIFFERENT dimension. Remove the duplicate from series.`
1488
+ );
1489
+ }
1456
1490
  return { isValid: e.length === 0, errors: e };
1457
1491
  }
1458
- function ue(r, t, i) {
1459
- const a = V[r];
1460
- if (!a)
1492
+ function ue(o, t, i) {
1493
+ const s = V[o];
1494
+ if (!s)
1461
1495
  return t ?? {};
1462
- const e = { ...t }, s = i.measures ?? [], n = i.dimensions ?? [], m = (i.timeDimensions ?? []).map((l) => l.dimension);
1463
- for (const l of a.dropZones) {
1464
- const d = e[l.key];
1465
- if (Array.isArray(d) ? d.length > 0 : !!d) continue;
1466
- const y = l.acceptTypes ?? [];
1467
- if (l.key === "sizeField" || l.key === "colorField") {
1468
- if (y.includes("measure")) {
1469
- const x = /* @__PURE__ */ new Set();
1470
- for (const w of a.dropZones) {
1471
- if (w.key === l.key) continue;
1472
- const c = e[w.key];
1473
- Array.isArray(c) ? c.forEach((C) => x.add(C)) : typeof c == "string" && x.add(c);
1496
+ const e = { ...t }, a = i.measures ?? [], n = i.dimensions ?? [], u = (i.timeDimensions ?? []).map((d) => d.dimension);
1497
+ for (const d of s.dropZones) {
1498
+ const p = e[d.key];
1499
+ if (Array.isArray(p) ? p.length > 0 : !!p) continue;
1500
+ const f = d.acceptTypes ?? [];
1501
+ if (d.key === "sizeField" || d.key === "colorField") {
1502
+ if (f.includes("measure")) {
1503
+ const m = /* @__PURE__ */ new Set();
1504
+ for (const y of s.dropZones) {
1505
+ if (y.key === d.key) continue;
1506
+ const g = e[y.key];
1507
+ Array.isArray(g) ? g.forEach((w) => m.add(w)) : typeof g == "string" && m.add(g);
1474
1508
  }
1475
- const u = s.filter((w) => !x.has(w));
1476
- u.length > 0 && (e[l.key] = u[0]);
1509
+ const C = a.filter((y) => !m.has(y));
1510
+ C.length > 0 && (e[d.key] = C[0]);
1477
1511
  }
1478
1512
  continue;
1479
1513
  }
1480
- const f = [];
1481
- if (y.includes("dimension") && f.push(...n), y.includes("timeDimension") && f.push(...m), y.includes("measure") && f.push(...s), f.length === 0) continue;
1482
- const k = l.maxItems ?? 1 / 0, D = f.slice(0, k);
1483
- D.length > 0 && (e[l.key] = D);
1514
+ const c = [];
1515
+ if (f.includes("dimension") && c.push(...n), f.includes("timeDimension") && c.push(...u), f.includes("measure") && c.push(...a), c.length === 0) continue;
1516
+ let b = c;
1517
+ if (d.key === "series") {
1518
+ const m = new Set(
1519
+ Array.isArray(e.xAxis) ? e.xAxis : e.xAxis ? [e.xAxis] : []
1520
+ );
1521
+ if (b = c.filter((C) => !m.has(C)), b.length === 0) continue;
1522
+ }
1523
+ const F = d.maxItems ?? 1 / 0, v = b.slice(0, F);
1524
+ v.length > 0 && (e[d.key] = v);
1484
1525
  }
1485
1526
  return e;
1486
1527
  }
1487
- function me(r) {
1528
+ function me(o) {
1488
1529
  const t = [`
1489
1530
  Chart config requirements by type:`];
1490
- for (const i of r) {
1491
- const a = V[i];
1492
- if (!a) continue;
1493
- const e = a.description ?? "", s = a.useCase ?? "", n = [e, s].filter(Boolean).join(". "), p = n ? ` — ${n}.` : "", m = a.dropZones.filter((d) => d.mandatory);
1494
- if (m.length === 0 && !a.skipQuery) {
1495
- t.push(` ${i}${p} chartConfig auto-inferred from query.`);
1531
+ for (const i of o) {
1532
+ const s = V[i];
1533
+ if (!s) continue;
1534
+ const e = s.description ?? "", a = s.useCase ?? "", n = [e, a].filter(Boolean).join(". "), l = n ? ` — ${n}.` : "", u = s.dropZones.filter((p) => p.mandatory);
1535
+ if (u.length === 0 && !s.skipQuery) {
1536
+ t.push(` ${i}${l} chartConfig auto-inferred from query.`);
1496
1537
  continue;
1497
1538
  }
1498
- if (a.skipQuery) {
1499
- t.push(` ${i}${p} No query needed.`);
1539
+ if (s.skipQuery) {
1540
+ t.push(` ${i}${l} No query needed.`);
1500
1541
  continue;
1501
1542
  }
1502
- const l = m.map((d) => {
1503
- const g = d.acceptTypes?.join("/") ?? "any", y = d.maxItems ? ` (max ${d.maxItems})` : "";
1504
- return `${d.key}=[${g}]${y}`;
1543
+ const d = u.map((p) => {
1544
+ const k = p.acceptTypes?.join("/") ?? "any", f = p.maxItems ? ` (max ${p.maxItems})` : "";
1545
+ return `${p.key}=[${k}]${f}`;
1505
1546
  });
1506
- t.push(` ${i}${p} Requires ${l.join(", ")}.`);
1547
+ t.push(` ${i}${l} Requires ${d.join(", ")}.`);
1507
1548
  }
1508
1549
  return t.join(`
1509
1550
  `);
1510
1551
  }
1511
- const O = [
1552
+ const N = [
1512
1553
  "bar",
1513
1554
  "line",
1514
1555
  "area",
@@ -1679,7 +1720,7 @@ function ce() {
1679
1720
  {
1680
1721
  name: "add_portlet",
1681
1722
  description: `Add a chart visualization to the notebook.
1682
- ` + me(O) + `
1723
+ ` + me(N) + `
1683
1724
  The query is validated before adding. The portlet fetches its own data.`,
1684
1725
  input_schema: {
1685
1726
  type: "object",
@@ -1691,7 +1732,7 @@ The query is validated before adding. The portlet fetches its own data.`,
1691
1732
  },
1692
1733
  chartType: {
1693
1734
  type: "string",
1694
- enum: O,
1735
+ enum: N,
1695
1736
  description: "Chart type to render"
1696
1737
  },
1697
1738
  chartConfig: {
@@ -1735,23 +1776,23 @@ The query is validated before adding. The portlet fetches its own data.`,
1735
1776
  }
1736
1777
  ];
1737
1778
  }
1738
- function ye(r) {
1739
- const { semanticLayer: t, securityContext: i } = r, a = /* @__PURE__ */ new Map();
1740
- return a.set("discover_cubes", async (e) => {
1741
- const s = await z(t, {
1779
+ function ye(o) {
1780
+ const { semanticLayer: t, securityContext: i } = o, s = /* @__PURE__ */ new Map();
1781
+ return s.set("discover_cubes", async (e) => {
1782
+ const a = await z(t, {
1742
1783
  topic: e.topic,
1743
1784
  intent: e.intent,
1744
1785
  limit: e.limit,
1745
1786
  minScore: e.minScore
1746
1787
  });
1747
- return { result: JSON.stringify(s, null, 2) };
1748
- }), a.set("get_cube_metadata", async () => {
1788
+ return { result: JSON.stringify(a, null, 2) };
1789
+ }), s.set("get_cube_metadata", async () => {
1749
1790
  const e = t.getMetadata();
1750
1791
  return { result: JSON.stringify(e, null, 2) };
1751
- }), a.set("execute_query", async (e) => {
1792
+ }), s.set("execute_query", async (e) => {
1752
1793
  try {
1753
- let s;
1754
- e.funnel ? s = { funnel: e.funnel } : e.flow ? s = { flow: e.flow } : e.retention ? s = { retention: e.retention } : s = {
1794
+ let a;
1795
+ e.funnel ? a = { funnel: e.funnel } : e.flow ? a = { flow: e.flow } : e.retention ? a = { retention: e.retention } : a = {
1755
1796
  measures: e.measures,
1756
1797
  dimensions: e.dimensions,
1757
1798
  filters: e.filters,
@@ -1759,7 +1800,7 @@ function ye(r) {
1759
1800
  order: e.order,
1760
1801
  limit: e.limit
1761
1802
  };
1762
- const n = await M(t, i, { query: s });
1803
+ const n = await R(t, i, { query: a });
1763
1804
  return {
1764
1805
  result: JSON.stringify({
1765
1806
  rowCount: n.data.length,
@@ -1767,82 +1808,82 @@ function ye(r) {
1767
1808
  annotation: n.annotation
1768
1809
  }, null, 2)
1769
1810
  };
1770
- } catch (s) {
1811
+ } catch (a) {
1771
1812
  return {
1772
- result: `Query execution failed: ${s instanceof Error ? s.message : "Unknown error"}`,
1813
+ result: `Query execution failed: ${a instanceof Error ? a.message : "Unknown error"}`,
1773
1814
  isError: !0
1774
1815
  };
1775
1816
  }
1776
- }), a.set("add_portlet", async (e) => {
1817
+ }), s.set("add_portlet", async (e) => {
1777
1818
  const n = {
1778
1819
  number: "kpiNumber",
1779
1820
  retention: "retentionHeatmap"
1780
1821
  }[e.chartType] ?? e.chartType;
1781
- let p;
1822
+ let l;
1782
1823
  try {
1783
- p = JSON.parse(e.query);
1824
+ l = JSON.parse(e.query);
1784
1825
  } catch {
1785
1826
  return {
1786
1827
  result: "Invalid query: could not parse JSON string. Ensure `query` is a valid JSON string.",
1787
1828
  isError: !0
1788
1829
  };
1789
1830
  }
1790
- const m = t.validateQuery(p);
1791
- if (!m.isValid)
1831
+ const u = t.validateQuery(l);
1832
+ if (!u.isValid)
1792
1833
  return {
1793
1834
  result: `Invalid query — fix these errors and retry:
1794
- ${m.errors.join(`
1835
+ ${u.errors.join(`
1795
1836
  `)}`,
1796
1837
  isError: !0
1797
1838
  };
1798
- const l = !!(p.funnel || p.flow || p.retention);
1799
- let d;
1800
- if (l)
1801
- d = e.chartConfig ?? {};
1839
+ const d = !!(l.funnel || l.flow || l.retention);
1840
+ let p;
1841
+ if (d)
1842
+ p = e.chartConfig ?? {};
1802
1843
  else {
1803
- const f = ue(n, e.chartConfig, p), k = pe(n, f);
1804
- if (!k.isValid)
1844
+ const c = ue(n, e.chartConfig, l), b = pe(n, c, l);
1845
+ if (!b.isValid)
1805
1846
  return {
1806
1847
  result: `Chart config invalid — fix these errors and retry:
1807
- ${k.errors.join(`
1848
+ ${b.errors.join(`
1808
1849
  `)}`,
1809
1850
  isError: !0
1810
1851
  };
1811
- d = f;
1852
+ p = c;
1812
1853
  }
1813
- const g = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, y = {
1814
- id: g,
1854
+ const k = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, f = {
1855
+ id: k,
1815
1856
  title: e.title,
1816
1857
  query: e.query,
1817
1858
  chartType: n,
1818
- chartConfig: d,
1859
+ chartConfig: p,
1819
1860
  displayConfig: e.displayConfig
1820
1861
  };
1821
1862
  return {
1822
- result: `Portlet "${e.title}" added to notebook (id: ${g}, chart: ${n}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
1823
- sideEffect: { type: "add_portlet", data: y }
1863
+ result: `Portlet "${e.title}" added to notebook (id: ${k}, chart: ${n}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
1864
+ sideEffect: { type: "add_portlet", data: f }
1824
1865
  };
1825
- }), a.set("add_markdown", async (e) => {
1826
- const s = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, n = {
1827
- id: s,
1866
+ }), s.set("add_markdown", async (e) => {
1867
+ const a = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, n = {
1868
+ id: a,
1828
1869
  title: e.title,
1829
1870
  content: e.content
1830
1871
  };
1831
1872
  return {
1832
- 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.]`,
1873
+ result: `Markdown block added to notebook (id: ${a}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
1833
1874
  sideEffect: { type: "add_markdown", data: n }
1834
1875
  };
1835
- }), a;
1876
+ }), s;
1836
1877
  }
1837
- async function* be(r) {
1838
- const { message: t, sessionId: i, semanticLayer: a, securityContext: e, agentConfig: s, apiKey: n } = r;
1839
- let p;
1878
+ async function* be(o) {
1879
+ const { message: t, sessionId: i, semanticLayer: s, securityContext: e, agentConfig: a, apiKey: n } = o;
1880
+ let l;
1840
1881
  try {
1841
- const u = await import(
1882
+ const m = await import(
1842
1883
  /* webpackIgnore: true */
1843
1884
  "@anthropic-ai/sdk"
1844
1885
  );
1845
- p = u.default || u.Anthropic || u;
1886
+ l = m.default || m.Anthropic || m;
1846
1887
  } catch {
1847
1888
  yield {
1848
1889
  type: "error",
@@ -1852,110 +1893,110 @@ async function* be(r) {
1852
1893
  };
1853
1894
  return;
1854
1895
  }
1855
- const m = new p({ apiKey: n }), l = ce(), d = ye({ semanticLayer: a, securityContext: e }), g = a.getMetadata(), y = L(g), f = s.model || "claude-sonnet-4-6", k = s.maxTurns || 25, D = s.maxTokens || 4096, x = [
1896
+ const u = new l({ apiKey: n }), d = ce(), p = ye({ semanticLayer: s, securityContext: e }), k = s.getMetadata(), f = L(k), c = a.model || "claude-sonnet-4-6", b = a.maxTurns || 25, F = a.maxTokens || 4096, v = [
1856
1897
  { role: "user", content: t }
1857
1898
  ];
1858
1899
  try {
1859
- for (let u = 0; u < k; u++) {
1860
- const w = await m.messages.create({
1861
- model: f,
1862
- max_tokens: D,
1863
- system: y,
1864
- tools: l,
1865
- messages: x,
1900
+ for (let m = 0; m < b; m++) {
1901
+ const C = await u.messages.create({
1902
+ model: c,
1903
+ max_tokens: F,
1904
+ system: f,
1905
+ tools: d,
1906
+ messages: v,
1866
1907
  stream: !0
1867
- }), c = [];
1868
- let C = -1, T = "", _ = "";
1869
- for await (const h of w)
1908
+ }), y = [];
1909
+ let g = -1, w = "", _ = "";
1910
+ for await (const h of C)
1870
1911
  switch (h.type) {
1871
1912
  case "content_block_start": {
1872
- C++;
1873
- const o = h.content_block;
1874
- o.type === "tool_use" ? (c.push({ type: "tool_use", id: o.id, name: o.name, input: {} }), T = "", yield {
1913
+ g++;
1914
+ const r = h.content_block;
1915
+ r.type === "tool_use" ? (y.push({ type: "tool_use", id: r.id, name: r.name, input: {} }), w = "", yield {
1875
1916
  type: "tool_use_start",
1876
- data: { id: o.id, name: o.name, input: void 0 }
1877
- }) : o.type === "text" && c.push({ type: "text", text: "" });
1917
+ data: { id: r.id, name: r.name, input: void 0 }
1918
+ }) : r.type === "text" && y.push({ type: "text", text: "" });
1878
1919
  break;
1879
1920
  }
1880
1921
  case "content_block_delta": {
1881
- const o = h.delta;
1882
- if (o.type === "text_delta" && o.text) {
1883
- const A = c[C];
1884
- A && (A.text = (A.text || "") + o.text), yield { type: "text_delta", data: o.text };
1885
- } else o.type === "input_json_delta" && o.partial_json && (T += o.partial_json);
1922
+ const r = h.delta;
1923
+ if (r.type === "text_delta" && r.text) {
1924
+ const A = y[g];
1925
+ A && (A.text = (A.text || "") + r.text), yield { type: "text_delta", data: r.text };
1926
+ } else r.type === "input_json_delta" && r.partial_json && (w += r.partial_json);
1886
1927
  break;
1887
1928
  }
1888
1929
  case "content_block_stop": {
1889
- const o = c[C];
1890
- if (o?.type === "tool_use" && T) {
1930
+ const r = y[g];
1931
+ if (r?.type === "tool_use" && w) {
1891
1932
  try {
1892
- o.input = JSON.parse(T);
1933
+ r.input = JSON.parse(w);
1893
1934
  } catch {
1894
- o.input = {};
1935
+ r.input = {};
1895
1936
  }
1896
- T = "";
1937
+ w = "";
1897
1938
  }
1898
1939
  break;
1899
1940
  }
1900
1941
  case "message_delta": {
1901
- const o = h.delta;
1902
- o.stop_reason && (_ = o.stop_reason);
1942
+ const r = h.delta;
1943
+ r.stop_reason && (_ = r.stop_reason);
1903
1944
  break;
1904
1945
  }
1905
1946
  }
1906
- if (x.push({ role: "assistant", content: c }), _ !== "tool_use")
1947
+ if (v.push({ role: "assistant", content: y }), _ !== "tool_use")
1907
1948
  break;
1908
- const S = [];
1909
- for (const h of c) {
1949
+ const D = [];
1950
+ for (const h of y) {
1910
1951
  if (h.type !== "tool_use") continue;
1911
- const o = h.name, A = h.input || {}, v = h.id, I = d.get(o);
1952
+ const r = h.name, A = h.input || {}, T = h.id, I = p.get(r);
1912
1953
  if (!I) {
1913
- S.push({
1954
+ D.push({
1914
1955
  type: "tool_result",
1915
- tool_use_id: v,
1916
- content: `Unknown tool: ${o}`,
1956
+ tool_use_id: T,
1957
+ content: `Unknown tool: ${r}`,
1917
1958
  is_error: !0
1918
1959
  }), yield {
1919
1960
  type: "tool_use_result",
1920
- data: { id: v, name: o, result: `Unknown tool: ${o}` }
1961
+ data: { id: T, name: r, result: `Unknown tool: ${r}` }
1921
1962
  };
1922
1963
  continue;
1923
1964
  }
1924
1965
  try {
1925
- const b = await I(A);
1926
- b.sideEffect && (yield b.sideEffect), S.push({
1966
+ const x = await I(A);
1967
+ x.sideEffect && (yield x.sideEffect), D.push({
1927
1968
  type: "tool_result",
1928
- tool_use_id: v,
1929
- content: b.result,
1930
- ...b.isError ? { is_error: !0 } : {}
1969
+ tool_use_id: T,
1970
+ content: x.result,
1971
+ ...x.isError ? { is_error: !0 } : {}
1931
1972
  }), yield {
1932
1973
  type: "tool_use_result",
1933
- data: { id: v, name: o, result: b.result }
1974
+ data: { id: T, name: r, result: x.result }
1934
1975
  };
1935
- } catch (b) {
1936
- const E = b instanceof Error ? b.message : "Tool execution failed";
1937
- S.push({
1976
+ } catch (x) {
1977
+ const E = x instanceof Error ? x.message : "Tool execution failed";
1978
+ D.push({
1938
1979
  type: "tool_result",
1939
- tool_use_id: v,
1980
+ tool_use_id: T,
1940
1981
  content: E,
1941
1982
  is_error: !0
1942
1983
  }), yield {
1943
1984
  type: "tool_use_result",
1944
- data: { id: v, name: o, result: E }
1985
+ data: { id: T, name: r, result: E }
1945
1986
  };
1946
1987
  }
1947
1988
  }
1948
- yield { type: "turn_complete", data: {} }, x.push({ role: "user", content: S });
1989
+ yield { type: "turn_complete", data: {} }, v.push({ role: "user", content: D });
1949
1990
  }
1950
1991
  yield {
1951
1992
  type: "done",
1952
1993
  data: { sessionId: i || "" }
1953
1994
  };
1954
- } catch (u) {
1995
+ } catch (m) {
1955
1996
  yield {
1956
1997
  type: "error",
1957
1998
  data: {
1958
- message: u instanceof Error ? u.message : "Agent execution failed"
1999
+ message: m instanceof Error ? m.message : "Agent execution failed"
1959
2000
  }
1960
2001
  };
1961
2002
  }