drizzle-cube 0.4.15 → 0.4.17

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 (45) 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-C1rOM9M_.cjs +25 -0
  6. package/dist/adapters/{handler-DZnCbydH.js → handler-nTycPMWF.js} +347 -265
  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 +2 -2
  12. package/dist/client/chunks/{analysis-builder-C5e52Z3p.js → analysis-builder-3z9fHE2F.js} +5 -5
  13. package/dist/client/chunks/{analysis-builder-C5e52Z3p.js.map → analysis-builder-3z9fHE2F.js.map} +1 -1
  14. package/dist/client/chunks/{analysis-builder-shared-EnM-8plh.js → analysis-builder-shared-Da-vlQa_.js} +2 -2
  15. package/dist/client/chunks/{analysis-builder-shared-EnM-8plh.js.map → analysis-builder-shared-Da-vlQa_.js.map} +1 -1
  16. package/dist/client/chunks/{chart-data-table-D5G8nMnb.js → chart-data-table-BsAjHe7o.js} +2 -2
  17. package/dist/client/chunks/{chart-data-table-D5G8nMnb.js.map → chart-data-table-BsAjHe7o.js.map} +1 -1
  18. package/dist/client/chunks/{chart-kpi-delta-Dgg2eYRl.js → chart-kpi-delta-DUD3f8vL.js} +3 -3
  19. package/dist/client/chunks/{chart-kpi-delta-Dgg2eYRl.js.map → chart-kpi-delta-DUD3f8vL.js.map} +1 -1
  20. package/dist/client/chunks/{chart-kpi-number-DkoO99c1.js → chart-kpi-number-iJh-PzsM.js} +2 -2
  21. package/dist/client/chunks/{chart-kpi-number-DkoO99c1.js.map → chart-kpi-number-iJh-PzsM.js.map} +1 -1
  22. package/dist/client/chunks/{chart-kpi-text-1O6_lmz7.js → chart-kpi-text-x6pV9v9Q.js} +2 -2
  23. package/dist/client/chunks/{chart-kpi-text-1O6_lmz7.js.map → chart-kpi-text-x6pV9v9Q.js.map} +1 -1
  24. package/dist/client/chunks/{charts-loader-AW3T1nv5.js → charts-loader-B3tt5oKG.js} +5 -5
  25. package/dist/client/chunks/{charts-loader-AW3T1nv5.js.map → charts-loader-B3tt5oKG.js.map} +1 -1
  26. package/dist/client/chunks/{components-BkeSy9xv.js → components-CMGGxqOB.js} +4 -4
  27. package/dist/client/chunks/{components-BkeSy9xv.js.map → components-CMGGxqOB.js.map} +1 -1
  28. package/dist/client/chunks/{icons-DAeqv1iX.js → icons-M7shurcH.js} +172 -160
  29. package/dist/client/chunks/icons-M7shurcH.js.map +1 -0
  30. package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +6 -0
  31. package/dist/client/components/AgenticNotebook/index.d.ts +6 -0
  32. package/dist/client/components.js +1 -1
  33. package/dist/client/hooks/useAgentChat.d.ts +2 -2
  34. package/dist/client/icons/types.d.ts +2 -0
  35. package/dist/client/icons.js +1 -1
  36. package/dist/client/index.js +707 -675
  37. package/dist/client/index.js.map +1 -1
  38. package/dist/client/utils.js +3 -3
  39. package/dist/client-bundle-stats.html +1 -1
  40. package/dist/server/index.cjs +36 -36
  41. package/dist/server/index.d.ts +45 -0
  42. package/dist/server/index.js +1291 -1209
  43. package/package.json +1 -1
  44. package/dist/adapters/handler-ZDYlokiM.cjs +0 -25
  45. package/dist/client/chunks/icons-DAeqv1iX.js.map +0 -1
@@ -1,6 +1,6 @@
1
- import { h as N, Q as P, j as L, D as R } from "./mcp-transport-m1X1GtwG.js";
2
- import { handleDiscover as Y, handleLoad as M } from "./utils.js";
3
- function z(o) {
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
4
  if (o.length === 0)
5
5
  return "No cubes are currently available.";
6
6
  const t = ["## Available Cubes", ""];
@@ -29,12 +29,12 @@ function z(o) {
29
29
  return t.join(`
30
30
  `);
31
31
  }
32
- function V(o) {
32
+ function I(o) {
33
33
  return o.messages.map((t) => t.content.text).join(`
34
34
 
35
35
  `);
36
36
  }
37
- function H(o) {
37
+ function W(o) {
38
38
  return [
39
39
  "# Drizzle Cube Analytics Agent",
40
40
  "",
@@ -160,19 +160,19 @@ function H(o) {
160
160
  "",
161
161
  "---",
162
162
  "",
163
- V(N),
163
+ I($),
164
164
  "",
165
165
  "---",
166
166
  "",
167
- V(P),
167
+ I(B),
168
168
  "",
169
169
  "---",
170
170
  "",
171
- V(L),
171
+ I(j),
172
172
  "",
173
173
  "---",
174
174
  "",
175
- V(R),
175
+ I(U),
176
176
  "",
177
177
  "---",
178
178
  "",
@@ -226,11 +226,11 @@ function H(o) {
226
226
  "",
227
227
  "---",
228
228
  "",
229
- z(o)
229
+ K(o)
230
230
  ].join(`
231
231
  `);
232
232
  }
233
- const B = {
233
+ const X = {
234
234
  label: "Bar Chart",
235
235
  description: "Compare values across categories",
236
236
  useCase: "Best for comparing discrete categories, showing rankings, or displaying changes over time",
@@ -296,7 +296,7 @@ const B = {
296
296
  description: "Number formatting for right Y-axis"
297
297
  }
298
298
  ]
299
- }, $ = {
299
+ }, J = {
300
300
  label: "Line Chart",
301
301
  description: "Show trends and changes over time",
302
302
  useCase: "Best for continuous data, trends, time series, and showing relationships between multiple series",
@@ -379,7 +379,7 @@ const B = {
379
379
  description: "Number formatting for right Y-axis"
380
380
  }
381
381
  ]
382
- }, j = {
382
+ }, Q = {
383
383
  label: "Area Chart",
384
384
  description: "Emphasize magnitude of change over time",
385
385
  useCase: "Best for showing cumulative totals, volume changes, or stacked comparisons over time",
@@ -451,7 +451,7 @@ const B = {
451
451
  description: "Number formatting for right Y-axis"
452
452
  }
453
453
  ]
454
- }, G = {
454
+ }, ee = {
455
455
  label: "Pie Chart",
456
456
  description: "Show proportions of a whole",
457
457
  useCase: "Best for showing percentage distribution or composition of a total (limit to 5-7 slices)",
@@ -485,7 +485,7 @@ const B = {
485
485
  description: "Number formatting for values"
486
486
  }
487
487
  ]
488
- }, K = {
488
+ }, te = {
489
489
  label: "Scatter Plot",
490
490
  description: "Reveal correlations between variables",
491
491
  useCase: "Best for identifying patterns, correlations, outliers, and relationships between two measures",
@@ -533,7 +533,7 @@ const B = {
533
533
  description: "Number formatting for Y-axis"
534
534
  }
535
535
  ]
536
- }, Z = {
536
+ }, ae = {
537
537
  label: "Bubble Chart",
538
538
  description: "Compare three dimensions of data",
539
539
  useCase: "Best for showing relationships between three variables (X, Y, and size), market analysis",
@@ -599,7 +599,7 @@ const B = {
599
599
  description: "Number formatting for Y-axis and values"
600
600
  }
601
601
  ]
602
- }, U = {
602
+ }, se = {
603
603
  label: "Radar Chart",
604
604
  description: "Compare multiple metrics across categories",
605
605
  useCase: "Best for multivariate comparisons, performance metrics, strengths/weaknesses analysis",
@@ -638,7 +638,7 @@ const B = {
638
638
  description: "Number formatting for values"
639
639
  }
640
640
  ]
641
- }, W = {
641
+ }, ie = {
642
642
  label: "Radial Bar Chart",
643
643
  description: "Circular progress and KPI visualization",
644
644
  useCase: "Best for showing progress toward goals, KPIs, or comparing percentages in a compact form",
@@ -670,7 +670,7 @@ const B = {
670
670
  description: "Number formatting for values"
671
671
  }
672
672
  ]
673
- }, X = {
673
+ }, oe = {
674
674
  label: "TreeMap",
675
675
  description: "Visualize hierarchical data with nested rectangles",
676
676
  useCase: "Best for showing part-to-whole relationships in hierarchical data, disk usage, budget allocation",
@@ -712,7 +712,7 @@ const B = {
712
712
  }
713
713
  ],
714
714
  clickableElements: { cell: !0 }
715
- }, J = {
715
+ }, re = {
716
716
  label: "Data Table",
717
717
  description: "Display detailed tabular data",
718
718
  useCase: "Best for precise values, detailed analysis, sortable/filterable data exploration",
@@ -735,7 +735,7 @@ const B = {
735
735
  description: "Number formatting for numeric values"
736
736
  }
737
737
  ]
738
- }, Q = {
738
+ }, ne = {
739
739
  label: "Activity Grid",
740
740
  description: "GitHub-style activity grid showing temporal patterns across different time scales",
741
741
  useCase: "Best for visualizing activity patterns over time. Supports hour (3hr blocks × days), day (days × weeks), week (weeks × months), month (months × quarters), and quarter (quarters × years) granularities",
@@ -780,7 +780,7 @@ const B = {
780
780
  } : { isValid: !0 };
781
781
  },
782
782
  clickableElements: { cell: !0 }
783
- }, ee = {
783
+ }, le = {
784
784
  label: "KPI Number",
785
785
  description: "Display key performance indicators as large numbers",
786
786
  useCase: "Perfect for showing important metrics like revenue, user count, or other key business metrics in a prominent, easy-to-read format",
@@ -850,7 +850,7 @@ const B = {
850
850
  }
851
851
  ],
852
852
  displayOptions: ["hideHeader"]
853
- }, te = {
853
+ }, de = {
854
854
  label: "KPI Delta",
855
855
  description: "Display change between latest and previous values with trend indicators",
856
856
  useCase: "Perfect for showing performance changes over time, such as revenue growth, user acquisition changes, or other metrics where the trend and delta are more important than the absolute value",
@@ -942,7 +942,7 @@ const B = {
942
942
  isValid: !1,
943
943
  message: "A measure is required for KPI Delta charts"
944
944
  } : { isValid: !0 }
945
- }, ae = {
945
+ }, pe = {
946
946
  label: "KPI Text",
947
947
  description: "Display key performance indicators as customizable text",
948
948
  useCase: "Perfect for showing metrics with custom formatting, combining multiple values, or displaying contextual KPI information using templates",
@@ -984,7 +984,7 @@ const B = {
984
984
  }
985
985
  ],
986
986
  displayOptions: ["hideHeader"]
987
- }, ie = {
987
+ }, ue = {
988
988
  label: "Markdown",
989
989
  description: "Display custom markdown content with formatting",
990
990
  useCase: "Perfect for adding documentation, notes, section headers, instructions, or formatted text to dashboards",
@@ -1076,7 +1076,7 @@ Use --- for horizontal rules.`,
1076
1076
  description: "Add an accent-colored border on one side of the content"
1077
1077
  }
1078
1078
  ]
1079
- }, se = {
1079
+ }, ce = {
1080
1080
  label: "Funnel Chart",
1081
1081
  description: "Show conversion through sequential steps",
1082
1082
  useCase: "Best for visualizing user journey funnels, sales pipelines, or multi-step processes",
@@ -1163,7 +1163,7 @@ Use --- for horizontal rules.`,
1163
1163
  description: "Display 90th percentile time to convert"
1164
1164
  }
1165
1165
  ]
1166
- }, oe = {
1166
+ }, me = {
1167
1167
  label: "Sankey Chart",
1168
1168
  description: "Show flow between states or steps",
1169
1169
  useCase: "Best for visualizing user journey flows, path analysis, or state transitions",
@@ -1219,7 +1219,7 @@ Use --- for horizontal rules.`,
1219
1219
  description: "Hide the statistics footer below the chart"
1220
1220
  }
1221
1221
  ]
1222
- }, re = {
1222
+ }, ye = {
1223
1223
  label: "Sunburst Chart",
1224
1224
  description: "Show hierarchical flow as radial rings",
1225
1225
  useCase: "Best for visualizing forward paths from a starting event in a compact radial layout",
@@ -1264,7 +1264,7 @@ Use --- for horizontal rules.`,
1264
1264
  description: "Hide the statistics footer below the chart"
1265
1265
  }
1266
1266
  ]
1267
- }, ne = {
1267
+ }, he = {
1268
1268
  label: "Heatmap",
1269
1269
  description: "Visualize intensity across two dimensions",
1270
1270
  useCase: "Best for showing patterns in matrix data like correlations, schedules, or category comparisons",
@@ -1336,7 +1336,7 @@ Use --- for horizontal rules.`,
1336
1336
  }
1337
1337
  ],
1338
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" }
1339
- }, le = {
1339
+ }, fe = {
1340
1340
  label: "Retention Matrix",
1341
1341
  // RetentionHeatmap auto-configures from the retention data structure
1342
1342
  // No drop zones needed as the chart maps directly to cohort × period matrix
@@ -1360,7 +1360,7 @@ Use --- for horizontal rules.`,
1360
1360
  ],
1361
1361
  description: "Cohort retention matrix visualization",
1362
1362
  useCase: "Visualize user retention over time by cohort"
1363
- }, de = {
1363
+ }, be = {
1364
1364
  label: "Retention Chart",
1365
1365
  // RetentionCombinedChart auto-configures from the retention data structure
1366
1366
  // No drop zones needed as the chart maps directly to retention result data
@@ -1403,7 +1403,7 @@ Use --- for horizontal rules.`,
1403
1403
  ],
1404
1404
  description: "Combined retention visualization with line chart and heatmap modes",
1405
1405
  useCase: "Visualize user retention over time with optional breakdown segmentation"
1406
- }, pe = {
1406
+ }, ge = {
1407
1407
  label: "Box Plot",
1408
1408
  description: "Show statistical distribution (median, IQR, whiskers) across categories",
1409
1409
  useCase: "Best for P&L spread per symbol, trade size distribution, latency distribution across platforms",
@@ -1436,7 +1436,7 @@ Use --- for horizontal rules.`,
1436
1436
  description: "Number formatting for the value axis"
1437
1437
  }
1438
1438
  ]
1439
- }, ue = {
1439
+ }, xe = {
1440
1440
  label: "Waterfall Chart",
1441
1441
  description: "Show cumulative effect of sequential positive and negative values",
1442
1442
  useCase: "Best for P&L decomposition, cash flow analysis, budget variance, or any sequential contribution breakdown",
@@ -1491,7 +1491,7 @@ Use --- for horizontal rules.`,
1491
1491
  description: "Number formatting for the Y-axis"
1492
1492
  }
1493
1493
  ]
1494
- }, ce = {
1494
+ }, we = {
1495
1495
  label: "Candlestick Chart",
1496
1496
  description: "Financial candlestick chart showing open/close body and high/low wicks",
1497
1497
  useCase: "Best for EOD quotes (bid/ask spread per date/symbol), markout distribution bands, or OHLC price data",
@@ -1556,7 +1556,7 @@ Use --- for horizontal rules.`,
1556
1556
  description: "Number formatting for the price axis"
1557
1557
  }
1558
1558
  ]
1559
- }, me = {
1559
+ }, ke = {
1560
1560
  label: "Measure Profile",
1561
1561
  description: "Plot N measures as sequential X-axis points to visualise a profile or shape across intervals",
1562
1562
  useCase: "Best for markout interval analysis (e.g. avgMinus2m → avgAtEvent → avgPlus2h), metric profiles, or any pattern across ordered measures",
@@ -1621,7 +1621,7 @@ Use --- for horizontal rules.`,
1621
1621
  description: "Number formatting for the Y-axis"
1622
1622
  }
1623
1623
  ]
1624
- }, ye = {
1624
+ }, ve = {
1625
1625
  label: "Gauge Chart",
1626
1626
  description: "Half-circle arc gauge for a single KPI value versus a maximum target",
1627
1627
  useCase: "Best for high-water marks vs equity, margin utilisation, or any single value progress toward a goal",
@@ -1680,36 +1680,36 @@ Use --- for horizontal rules.`,
1680
1680
  description: "Number formatting for the displayed value and axis labels"
1681
1681
  }
1682
1682
  ]
1683
- }, q = {
1684
- bar: B,
1685
- line: $,
1686
- area: j,
1687
- pie: G,
1688
- scatter: K,
1689
- bubble: Z,
1690
- radar: U,
1691
- radialBar: W,
1692
- treemap: X,
1693
- table: J,
1694
- activityGrid: Q,
1695
- kpiNumber: ee,
1696
- kpiDelta: te,
1697
- kpiText: ae,
1698
- markdown: ie,
1699
- funnel: se,
1700
- sankey: oe,
1701
- sunburst: re,
1702
- heatmap: ne,
1703
- retentionHeatmap: le,
1704
- retentionCombined: de,
1705
- boxPlot: pe,
1706
- waterfall: ue,
1707
- candlestick: ce,
1708
- measureProfile: me,
1709
- gauge: ye
1683
+ }, P = {
1684
+ bar: X,
1685
+ line: J,
1686
+ area: Q,
1687
+ pie: ee,
1688
+ scatter: te,
1689
+ bubble: ae,
1690
+ radar: se,
1691
+ radialBar: ie,
1692
+ treemap: oe,
1693
+ table: re,
1694
+ activityGrid: ne,
1695
+ kpiNumber: le,
1696
+ kpiDelta: de,
1697
+ kpiText: pe,
1698
+ markdown: ue,
1699
+ funnel: ce,
1700
+ sankey: me,
1701
+ sunburst: ye,
1702
+ heatmap: he,
1703
+ retentionHeatmap: fe,
1704
+ retentionCombined: be,
1705
+ boxPlot: ge,
1706
+ waterfall: xe,
1707
+ candlestick: we,
1708
+ measureProfile: ke,
1709
+ gauge: ve
1710
1710
  };
1711
- function he(o, t, a) {
1712
- const i = q[o];
1711
+ function Ce(o, t, a) {
1712
+ const i = P[o];
1713
1713
  if (!i)
1714
1714
  return { isValid: !0, errors: [] };
1715
1715
  if (i.skipQuery)
@@ -1717,19 +1717,19 @@ function he(o, t, a) {
1717
1717
  const e = [];
1718
1718
  for (const s of i.dropZones) {
1719
1719
  if (!s.mandatory) continue;
1720
- const r = t?.[s.key];
1721
- if (!(Array.isArray(r) ? r.length > 0 : !!r)) {
1722
- const m = s.acceptTypes?.join("/") ?? "fields";
1720
+ const l = t?.[s.key];
1721
+ if (!(Array.isArray(l) ? l.length > 0 : !!l)) {
1722
+ const u = s.acceptTypes?.join("/") ?? "fields";
1723
1723
  e.push(
1724
- `chartConfig.${s.key} is required for ${o} chart (${s.label}). Accepts: ${m}.`
1724
+ `chartConfig.${s.key} is required for ${o} chart (${s.label}). Accepts: ${u}.`
1725
1725
  );
1726
1726
  }
1727
1727
  }
1728
1728
  if (o === "bar") {
1729
1729
  const s = t?.xAxis;
1730
1730
  if (!(Array.isArray(s) ? s.length > 0 : !!s)) {
1731
- const p = a.dimensions ?? [], m = a.timeDimensions ?? [];
1732
- p.length > 0 || m.length > 0 ? e.push(
1731
+ const d = a.dimensions ?? [], u = a.timeDimensions ?? [];
1732
+ d.length > 0 || u.length > 0 ? e.push(
1733
1733
  "chartConfig.xAxis is required for bar charts. Put a dimension in xAxis so bars have category labels."
1734
1734
  ) : e.push(
1735
1735
  'Bar charts need an xAxis dimension for category labels. Add a dimension to the query or use "table" chart type instead.'
@@ -1739,74 +1739,74 @@ function he(o, t, a) {
1739
1739
  if (t?.xAxis && t?.series) {
1740
1740
  const s = new Set(
1741
1741
  Array.isArray(t.xAxis) ? t.xAxis : [t.xAxis]
1742
- ), p = (Array.isArray(t.series) ? t.series : [t.series]).filter((m) => s.has(m));
1743
- p.length > 0 && e.push(
1744
- `chartConfig.series must not contain the same field as xAxis (found: ${p.join(", ")}). The series field is only for splitting into grouped/stacked sub-series by a DIFFERENT dimension. Remove the duplicate from series.`
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.`
1745
1745
  );
1746
1746
  }
1747
1747
  return { isValid: e.length === 0, errors: e };
1748
1748
  }
1749
- function fe(o, t, a) {
1750
- const i = q[o];
1749
+ function Te(o, t, a) {
1750
+ const i = P[o];
1751
1751
  if (!i)
1752
1752
  return t ?? {};
1753
- const e = { ...t }, s = a.measures ?? [], r = a.dimensions ?? [], m = (a.timeDimensions ?? []).map((c) => c.dimension);
1754
- for (const c of i.dropZones) {
1755
- const y = e[c.key];
1756
- if (Array.isArray(y) ? y.length > 0 : !!y) continue;
1757
- const g = c.acceptTypes ?? [];
1758
- if (c.key === "sizeField" || c.key === "colorField") {
1759
- if (g.includes("measure")) {
1760
- const h = /* @__PURE__ */ new Set();
1761
- for (const x of i.dropZones) {
1762
- if (x.key === c.key) continue;
1763
- const u = e[x.key];
1764
- Array.isArray(u) ? u.forEach((A) => h.add(A)) : typeof u == "string" && h.add(u);
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];
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")) {
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);
1765
1765
  }
1766
- const d = s.filter((x) => !h.has(x));
1767
- d.length > 0 && (e[c.key] = d[0]);
1766
+ const C = s.filter((S) => !g.has(S));
1767
+ C.length > 0 && (e[p.key] = C[0]);
1768
1768
  }
1769
1769
  continue;
1770
1770
  }
1771
- const f = [];
1772
- if (g.includes("dimension") && f.push(...r), g.includes("timeDimension") && f.push(...m), g.includes("measure") && f.push(...s), f.length === 0) continue;
1773
- let b = f;
1774
- if (c.key === "series") {
1775
- const h = new Set(
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") {
1775
+ const g = new Set(
1776
1776
  Array.isArray(e.xAxis) ? e.xAxis : e.xAxis ? [e.xAxis] : []
1777
1777
  );
1778
- if (b = f.filter((d) => !h.has(d)), b.length === 0) continue;
1778
+ if (f = y.filter((C) => !g.has(C)), f.length === 0) continue;
1779
1779
  }
1780
- const w = c.maxItems ?? 1 / 0, C = b.slice(0, w);
1781
- C.length > 0 && (e[c.key] = C);
1780
+ const v = p.maxItems ?? 1 / 0, D = f.slice(0, v);
1781
+ D.length > 0 && (e[p.key] = D);
1782
1782
  }
1783
1783
  return e;
1784
1784
  }
1785
- function be(o) {
1785
+ function Ae(o) {
1786
1786
  const t = [`
1787
1787
  Chart config requirements by type:`];
1788
1788
  for (const a of o) {
1789
- const i = q[a];
1789
+ const i = P[a];
1790
1790
  if (!i) continue;
1791
- const e = i.description ?? "", s = i.useCase ?? "", r = [e, s].filter(Boolean).join(". "), p = r ? ` — ${r}.` : "", m = i.dropZones.filter((y) => y.mandatory);
1792
- if (m.length === 0 && !i.skipQuery) {
1793
- t.push(` ${a}${p} chartConfig auto-inferred from query.`);
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.`);
1794
1794
  continue;
1795
1795
  }
1796
1796
  if (i.skipQuery) {
1797
- t.push(` ${a}${p} No query needed.`);
1797
+ t.push(` ${a}${d} No query needed.`);
1798
1798
  continue;
1799
1799
  }
1800
- const c = m.map((y) => {
1801
- const l = y.acceptTypes?.join("/") ?? "any", g = y.maxItems ? ` (max ${y.maxItems})` : "";
1802
- return `${y.key}=[${l}]${g}`;
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}`;
1803
1803
  });
1804
- t.push(` ${a}${p} Requires ${c.join(", ")}.`);
1804
+ t.push(` ${a}${d} Requires ${p.join(", ")}.`);
1805
1805
  }
1806
1806
  return t.join(`
1807
1807
  `);
1808
1808
  }
1809
- const _ = [
1809
+ const N = [
1810
1810
  "bar",
1811
1811
  "line",
1812
1812
  "area",
@@ -1826,7 +1826,7 @@ const _ = [
1826
1826
  "boxPlot",
1827
1827
  "markdown"
1828
1828
  ];
1829
- function ge() {
1829
+ function De() {
1830
1830
  return [
1831
1831
  // Tool 1: discover_cubes
1832
1832
  {
@@ -1860,13 +1860,13 @@ function ge() {
1860
1860
  properties: {
1861
1861
  measures: {
1862
1862
  type: "array",
1863
- items: { type: "string" },
1864
- description: 'Aggregation measures (e.g., ["Employees.count"])'
1863
+ items: { type: "string", pattern: "^[A-Z][a-zA-Z0-9]*\\.[a-zA-Z][a-zA-Z0-9]*$" },
1864
+ description: 'Aggregation measures — MUST be "CubeName.measureName" format (e.g., ["PullRequests.count", "Issues.openCount"]). NEVER use just the cube name.'
1865
1865
  },
1866
1866
  dimensions: {
1867
1867
  type: "array",
1868
- items: { type: "string" },
1869
- description: 'Grouping dimensions (e.g., ["Employees.name"])'
1868
+ items: { type: "string", pattern: "^[A-Z][a-zA-Z0-9]*\\.[a-zA-Z][a-zA-Z0-9]*$" },
1869
+ description: 'Grouping dimensions — MUST be "CubeName.dimensionName" format (e.g., ["Teams.name", "Employees.department"]). NEVER use just the cube name.'
1870
1870
  },
1871
1871
  filters: {
1872
1872
  type: "array",
@@ -1978,7 +1978,7 @@ function ge() {
1978
1978
  {
1979
1979
  name: "add_portlet",
1980
1980
  description: `Add a chart visualization to the notebook.
1981
- ` + be(_) + `
1981
+ ` + Ae(N) + `
1982
1982
  The query is validated before adding. The portlet fetches its own data.`,
1983
1983
  input_schema: {
1984
1984
  type: "object",
@@ -1990,7 +1990,7 @@ The query is validated before adding. The portlet fetches its own data.`,
1990
1990
  },
1991
1991
  chartType: {
1992
1992
  type: "string",
1993
- enum: _,
1993
+ enum: N,
1994
1994
  description: "Chart type to render"
1995
1995
  },
1996
1996
  chartConfig: {
@@ -2050,7 +2050,7 @@ The query is validated before adding. The portlet fetches its own data.`,
2050
2050
  title: { type: "string", description: "Portlet title" },
2051
2051
  chartType: {
2052
2052
  type: "string",
2053
- enum: _,
2053
+ enum: N,
2054
2054
  description: 'Chart type. Use "markdown" for section headers.'
2055
2055
  },
2056
2056
  query: {
@@ -2121,10 +2121,10 @@ The query is validated before adding. The portlet fetches its own data.`,
2121
2121
  }
2122
2122
  ];
2123
2123
  }
2124
- function xe(o) {
2124
+ function Se(o) {
2125
2125
  const { semanticLayer: t, securityContext: a } = o, i = /* @__PURE__ */ new Map();
2126
2126
  return i.set("discover_cubes", async (e) => {
2127
- const s = await Y(t, {
2127
+ const s = await Z(t, {
2128
2128
  topic: e.topic,
2129
2129
  intent: e.intent,
2130
2130
  limit: e.limit,
@@ -2136,8 +2136,17 @@ function xe(o) {
2136
2136
  return { result: JSON.stringify(e, null, 2) };
2137
2137
  }), i.set("execute_query", async (e) => {
2138
2138
  try {
2139
- let s;
2140
- e.funnel ? s = { funnel: e.funnel } : e.flow ? s = { flow: e.flow } : e.retention ? s = { retention: e.retention } : s = {
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
+ );
2146
+ };
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 = {
2141
2150
  measures: e.measures,
2142
2151
  dimensions: e.dimensions,
2143
2152
  filters: e.filters,
@@ -2145,12 +2154,12 @@ function xe(o) {
2145
2154
  order: e.order,
2146
2155
  limit: e.limit
2147
2156
  };
2148
- const r = await M(t, a, { query: s });
2157
+ const d = await G(t, a, { query: l });
2149
2158
  return {
2150
2159
  result: JSON.stringify({
2151
- rowCount: r.data.length,
2152
- data: r.data,
2153
- annotation: r.annotation
2160
+ rowCount: d.data.length,
2161
+ data: d.data,
2162
+ annotation: d.annotation
2154
2163
  }, null, 2)
2155
2164
  };
2156
2165
  } catch (s) {
@@ -2160,138 +2169,138 @@ function xe(o) {
2160
2169
  };
2161
2170
  }
2162
2171
  }), i.set("add_portlet", async (e) => {
2163
- const r = {
2172
+ const l = {
2164
2173
  number: "kpiNumber",
2165
2174
  retention: "retentionHeatmap"
2166
2175
  }[e.chartType] ?? e.chartType;
2167
- let p;
2176
+ let d;
2168
2177
  try {
2169
- p = JSON.parse(e.query);
2178
+ d = JSON.parse(e.query);
2170
2179
  } catch {
2171
2180
  return {
2172
2181
  result: "Invalid query: could not parse JSON string. Ensure `query` is a valid JSON string.",
2173
2182
  isError: !0
2174
2183
  };
2175
2184
  }
2176
- const m = t.validateQuery(p);
2177
- if (!m.isValid)
2185
+ const u = t.validateQuery(d);
2186
+ if (!u.isValid)
2178
2187
  return {
2179
2188
  result: `Invalid query — fix these errors and retry:
2180
- ${m.errors.join(`
2189
+ ${u.errors.join(`
2181
2190
  `)}`,
2182
2191
  isError: !0
2183
2192
  };
2184
- const c = !!(p.funnel || p.flow || p.retention);
2185
- let y;
2186
- if (c)
2187
- y = e.chartConfig ?? {};
2193
+ const p = !!(d.funnel || d.flow || d.retention);
2194
+ let m;
2195
+ if (p)
2196
+ m = e.chartConfig ?? {};
2188
2197
  else {
2189
- const f = fe(r, e.chartConfig, p), b = he(r, f, p);
2190
- if (!b.isValid)
2198
+ const y = Te(l, e.chartConfig, d), f = Ce(l, y, d);
2199
+ if (!f.isValid)
2191
2200
  return {
2192
2201
  result: `Chart config invalid — fix these errors and retry:
2193
- ${b.errors.join(`
2202
+ ${f.errors.join(`
2194
2203
  `)}`,
2195
2204
  isError: !0
2196
2205
  };
2197
- y = f;
2206
+ m = y;
2198
2207
  }
2199
- const l = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, g = {
2200
- id: l,
2208
+ const n = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, b = {
2209
+ id: n,
2201
2210
  title: e.title,
2202
2211
  query: e.query,
2203
- chartType: r,
2204
- chartConfig: y,
2212
+ chartType: l,
2213
+ chartConfig: m,
2205
2214
  displayConfig: e.displayConfig
2206
2215
  };
2207
2216
  return {
2208
- result: `Portlet "${e.title}" added to notebook (id: ${l}, chart: ${r}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
2209
- sideEffect: { type: "add_portlet", data: g }
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 }
2210
2219
  };
2211
2220
  }), i.set("add_markdown", async (e) => {
2212
- const s = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, r = {
2221
+ const s = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, l = {
2213
2222
  id: s,
2214
2223
  title: e.title,
2215
2224
  content: e.content
2216
2225
  };
2217
2226
  return {
2218
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.]`,
2219
- sideEffect: { type: "add_markdown", data: r }
2228
+ sideEffect: { type: "add_markdown", data: l }
2220
2229
  };
2221
2230
  }), i.set("save_as_dashboard", async (e) => {
2222
2231
  try {
2223
2232
  const s = e.portlets;
2224
2233
  if (!s || s.length === 0)
2225
2234
  return { result: "Dashboard must contain at least one portlet.", isError: !0 };
2226
- const r = [];
2227
- for (const l of s) {
2228
- if (l.chartType === "markdown") continue;
2229
- const f = l.query;
2230
- if (!f) {
2231
- r.push(`Portlet "${l.title}": missing query`);
2235
+ const l = [];
2236
+ for (const n of s) {
2237
+ if (n.chartType === "markdown") continue;
2238
+ const y = n.query;
2239
+ if (!y) {
2240
+ l.push(`Portlet "${n.title}": missing query`);
2232
2241
  continue;
2233
2242
  }
2234
- let b;
2243
+ let f;
2235
2244
  try {
2236
- b = JSON.parse(f);
2245
+ f = JSON.parse(y);
2237
2246
  } catch {
2238
- r.push(`Portlet "${l.title}": invalid JSON query`);
2247
+ l.push(`Portlet "${n.title}": invalid JSON query`);
2239
2248
  continue;
2240
2249
  }
2241
- const w = t.validateQuery(b);
2242
- w.isValid || r.push(`Portlet "${l.title}": ${w.errors.join(", ")}`);
2250
+ const v = t.validateQuery(f);
2251
+ v.isValid || l.push(`Portlet "${n.title}": ${v.errors.join(", ")}`);
2243
2252
  }
2244
- if (r.length > 0)
2253
+ if (l.length > 0)
2245
2254
  return {
2246
2255
  result: `Dashboard has invalid portlets — fix these errors and retry:
2247
- ${r.join(`
2256
+ ${l.join(`
2248
2257
  `)}`,
2249
2258
  isError: !0
2250
2259
  };
2251
- const p = {
2252
- portlets: s.map((l) => {
2253
- const g = l.chartType, f = g === "markdown", b = f ? "query" : l.analysisType || "query", w = b === "funnel" ? "funnel" : b === "flow" ? "flow" : b === "retention" ? "retention" : "query", C = l.query || "{}";
2254
- let h;
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;
2255
2264
  try {
2256
- h = JSON.parse(C);
2265
+ g = JSON.parse(D);
2257
2266
  } catch {
2258
- h = {};
2267
+ g = {};
2259
2268
  }
2260
- const d = {
2269
+ const C = {
2261
2270
  version: 1,
2262
- analysisType: w,
2271
+ analysisType: v,
2263
2272
  activeView: "chart",
2264
2273
  charts: {
2265
- [w]: {
2266
- chartType: g,
2267
- chartConfig: l.chartConfig || {},
2268
- displayConfig: l.displayConfig || {}
2274
+ [v]: {
2275
+ chartType: b,
2276
+ chartConfig: n.chartConfig || {},
2277
+ displayConfig: n.displayConfig || {}
2269
2278
  }
2270
2279
  },
2271
- query: f ? {} : h
2280
+ query: y ? {} : g
2272
2281
  };
2273
2282
  return {
2274
- id: l.id,
2275
- title: l.title,
2276
- analysisConfig: d,
2277
- dashboardFilterMapping: l.dashboardFilterMapping,
2278
- w: l.w,
2279
- h: l.h,
2280
- x: l.x,
2281
- y: l.y
2283
+ id: n.id,
2284
+ title: n.title,
2285
+ analysisConfig: C,
2286
+ dashboardFilterMapping: n.dashboardFilterMapping,
2287
+ w: n.w,
2288
+ h: n.h,
2289
+ x: n.x,
2290
+ y: n.y
2282
2291
  };
2283
2292
  }),
2284
2293
  filters: e.filters,
2285
2294
  colorPalette: e.colorPalette
2286
- }, m = e.title, c = p.portlets.length, y = p.filters?.length || 0;
2295
+ }, u = e.title, p = d.portlets.length, m = d.filters?.length || 0;
2287
2296
  return {
2288
- result: `Dashboard "${m}" created with ${c} portlets and ${y} filters.`,
2297
+ result: `Dashboard "${u}" created with ${p} portlets and ${m} filters.`,
2289
2298
  sideEffect: {
2290
2299
  type: "dashboard_saved",
2291
2300
  data: {
2292
- title: m,
2301
+ title: u,
2293
2302
  description: e.description,
2294
- dashboardConfig: p
2303
+ dashboardConfig: d
2295
2304
  }
2296
2305
  }
2297
2306
  };
@@ -2303,15 +2312,15 @@ ${r.join(`
2303
2312
  }
2304
2313
  }), i;
2305
2314
  }
2306
- async function* Ce(o) {
2307
- const { message: t, sessionId: a, history: i, semanticLayer: e, securityContext: s, agentConfig: r, apiKey: p } = o;
2308
- let m;
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;
2309
2318
  try {
2310
- const d = await import(
2319
+ const c = await import(
2311
2320
  /* webpackIgnore: true */
2312
2321
  "@anthropic-ai/sdk"
2313
2322
  );
2314
- m = d.default || d.Anthropic || d;
2323
+ n = c.default || c.Anthropic || c;
2315
2324
  } catch {
2316
2325
  yield {
2317
2326
  type: "error",
@@ -2321,140 +2330,213 @@ async function* Ce(o) {
2321
2330
  };
2322
2331
  return;
2323
2332
  }
2324
- const c = new m({ apiKey: p }), y = ge(), l = xe({ semanticLayer: e, securityContext: s }), g = e.getMetadata(), f = H(g), b = r.model || "claude-sonnet-4-6", w = r.maxTurns || 25, C = r.maxTokens || 4096, h = [];
2325
- if (i && i.length > 0) {
2326
- for (const d of i)
2327
- if (d.role === "user")
2328
- h.push({ role: "user", content: d.content });
2329
- else if (d.role === "assistant") {
2330
- const x = [];
2331
- if (d.content && x.push({ type: "text", text: d.content }), d.toolCalls && d.toolCalls.length > 0) {
2332
- for (const u of d.toolCalls)
2333
- x.push({
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;
2334
+ try {
2335
+ u?.onChatStart?.({
2336
+ traceId: p,
2337
+ sessionId: d,
2338
+ message: t,
2339
+ model: g,
2340
+ historyLength: a?.length ?? 0
2341
+ });
2342
+ } catch {
2343
+ }
2344
+ const x = [];
2345
+ 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") {
2350
+ 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)
2353
+ F.push({
2334
2354
  type: "tool_use",
2335
- id: u.id,
2336
- name: u.name,
2337
- input: u.input || {}
2355
+ id: h.id,
2356
+ name: h.name,
2357
+ input: h.input || {}
2338
2358
  });
2339
- h.push({ role: "assistant", content: x }), h.push({
2359
+ x.push({ role: "assistant", content: F }), x.push({
2340
2360
  role: "user",
2341
- content: d.toolCalls.map((u) => ({
2361
+ content: c.toolCalls.map((h) => ({
2342
2362
  type: "tool_result",
2343
- tool_use_id: u.id,
2344
- content: typeof u.result == "string" ? u.result : JSON.stringify(u.result ?? ""),
2345
- ...u.status === "error" ? { is_error: !0 } : {}
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 } : {}
2346
2366
  }))
2347
2367
  });
2348
- } else x.length > 0 && h.push({ role: "assistant", content: d.content });
2368
+ } else F.length > 0 && x.push({ role: "assistant", content: c.content });
2349
2369
  }
2350
2370
  }
2351
- h.push({ role: "user", content: t });
2371
+ x.push({ role: "user", content: t });
2372
+ let V = 0;
2352
2373
  try {
2353
- for (let d = 0; d < w; d++) {
2354
- const x = await c.messages.create({
2355
- model: b,
2356
- max_tokens: C,
2357
- system: f,
2374
+ for (let c = 0; c < C; c++) {
2375
+ V = c + 1;
2376
+ const F = await b.messages.create({
2377
+ model: g,
2378
+ max_tokens: S,
2379
+ system: D,
2358
2380
  tools: y,
2359
- messages: h,
2381
+ messages: x,
2360
2382
  stream: !0
2361
- }), u = [];
2362
- let A = -1, D = "", E = "";
2363
- for await (const k of x)
2364
- switch (k.type) {
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) {
2365
2388
  case "content_block_start": {
2366
- A++;
2367
- const n = k.content_block;
2368
- n.type === "tool_use" ? (u.push({ type: "tool_use", id: n.id, name: n.name, input: {} }), D = "", yield {
2389
+ 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 {
2369
2392
  type: "tool_use_start",
2370
- data: { id: n.id, name: n.name, input: void 0 }
2371
- }) : n.type === "text" && u.push({ type: "text", text: "" });
2393
+ data: { id: r.id, name: r.name, input: void 0 }
2394
+ }) : r.type === "text" && h.push({ type: "text", text: "" });
2372
2395
  break;
2373
2396
  }
2374
2397
  case "content_block_delta": {
2375
- const n = k.delta;
2376
- if (n.type === "text_delta" && n.text) {
2377
- const S = u[A];
2378
- S && (S.text = (S.text || "") + n.text), yield { type: "text_delta", data: n.text };
2379
- } else n.type === "input_json_delta" && n.partial_json && (D += n.partial_json);
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);
2380
2403
  break;
2381
2404
  }
2382
2405
  case "content_block_stop": {
2383
- const n = u[A];
2384
- if (n?.type === "tool_use" && D) {
2406
+ const r = h[q];
2407
+ if (r?.type === "tool_use" && _) {
2385
2408
  try {
2386
- n.input = JSON.parse(D);
2409
+ r.input = JSON.parse(_);
2387
2410
  } catch {
2388
- n.input = {};
2411
+ r.input = {};
2389
2412
  }
2390
- D = "";
2413
+ _ = "";
2391
2414
  }
2392
2415
  break;
2393
2416
  }
2417
+ case "message_start": {
2418
+ const r = w.message;
2419
+ r?.usage?.input_tokens != null && (L = r.usage.input_tokens);
2420
+ break;
2421
+ }
2394
2422
  case "message_delta": {
2395
- const n = k.delta;
2396
- n.stop_reason && (E = n.stop_reason);
2423
+ const r = w.delta, T = w.usage;
2424
+ T?.output_tokens != null && (R = T.output_tokens), r.stop_reason && (O = r.stop_reason);
2397
2425
  break;
2398
2426
  }
2399
2427
  }
2400
- if (h.push({ role: "assistant", content: u }), E !== "tool_use")
2428
+ try {
2429
+ u?.onGenerationEnd?.({
2430
+ traceId: p,
2431
+ turn: c,
2432
+ model: g,
2433
+ stopReason: O,
2434
+ inputTokens: L,
2435
+ outputTokens: R,
2436
+ durationMs: Date.now() - H
2437
+ });
2438
+ } catch {
2439
+ }
2440
+ if (x.push({ role: "assistant", content: h }), O !== "tool_use")
2401
2441
  break;
2402
- const F = [];
2403
- for (const k of u) {
2404
- if (k.type !== "tool_use") continue;
2405
- const n = k.name, S = k.input || {}, T = k.id, I = l.get(n);
2406
- if (!I) {
2407
- F.push({
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({
2408
2448
  type: "tool_result",
2409
- tool_use_id: T,
2410
- content: `Unknown tool: ${n}`,
2449
+ tool_use_id: A,
2450
+ content: `Unknown tool: ${r}`,
2411
2451
  is_error: !0
2412
2452
  }), yield {
2413
2453
  type: "tool_use_result",
2414
- data: { id: T, name: n, result: `Unknown tool: ${n}`, isError: !0 }
2454
+ data: { id: A, name: r, result: `Unknown tool: ${r}`, isError: !0 }
2415
2455
  };
2416
2456
  continue;
2417
2457
  }
2458
+ const Y = Date.now();
2418
2459
  try {
2419
- const v = await I(S);
2420
- v.sideEffect && (yield v.sideEffect), F.push({
2460
+ const k = await M(T);
2461
+ k.sideEffect && (yield k.sideEffect), E.push({
2421
2462
  type: "tool_result",
2422
- tool_use_id: T,
2423
- content: v.result,
2424
- ...v.isError ? { is_error: !0 } : {}
2463
+ tool_use_id: A,
2464
+ content: k.result,
2465
+ ...k.isError ? { is_error: !0 } : {}
2425
2466
  }), yield {
2426
2467
  type: "tool_use_result",
2427
- data: { id: T, name: n, result: v.result, ...v.isError ? { isError: !0 } : {} }
2468
+ data: { id: A, name: r, result: k.result, ...k.isError ? { isError: !0 } : {} }
2428
2469
  };
2429
- } catch (v) {
2430
- const O = v instanceof Error ? v.message : "Tool execution failed";
2431
- F.push({
2470
+ try {
2471
+ u?.onToolEnd?.({
2472
+ traceId: p,
2473
+ turn: c,
2474
+ toolName: r,
2475
+ toolUseId: A,
2476
+ isError: !!k.isError,
2477
+ durationMs: Date.now() - Y
2478
+ });
2479
+ } catch {
2480
+ }
2481
+ } catch (k) {
2482
+ const z = k instanceof Error ? k.message : "Tool execution failed";
2483
+ E.push({
2432
2484
  type: "tool_result",
2433
- tool_use_id: T,
2434
- content: O,
2485
+ tool_use_id: A,
2486
+ content: z,
2435
2487
  is_error: !0
2436
2488
  }), yield {
2437
2489
  type: "tool_use_result",
2438
- data: { id: T, name: n, result: O, isError: !0 }
2490
+ data: { id: A, name: r, result: z, isError: !0 }
2439
2491
  };
2492
+ try {
2493
+ u?.onToolEnd?.({
2494
+ traceId: p,
2495
+ turn: c,
2496
+ toolName: r,
2497
+ toolUseId: A,
2498
+ isError: !0,
2499
+ durationMs: Date.now() - Y
2500
+ });
2501
+ } catch {
2502
+ }
2440
2503
  }
2441
2504
  }
2442
- yield { type: "turn_complete", data: {} }, h.push({ role: "user", content: F });
2505
+ yield { type: "turn_complete", data: {} }, x.push({ role: "user", content: E });
2506
+ }
2507
+ try {
2508
+ u?.onChatEnd?.({
2509
+ traceId: p,
2510
+ sessionId: d,
2511
+ totalTurns: V,
2512
+ durationMs: Date.now() - m
2513
+ });
2514
+ } catch {
2443
2515
  }
2444
2516
  yield {
2445
2517
  type: "done",
2446
- data: { sessionId: a || "" }
2518
+ data: { sessionId: d || "", traceId: p }
2447
2519
  };
2448
- } catch (d) {
2520
+ } catch (c) {
2521
+ try {
2522
+ u?.onChatEnd?.({
2523
+ traceId: p,
2524
+ sessionId: d,
2525
+ totalTurns: 0,
2526
+ durationMs: Date.now() - m,
2527
+ error: c instanceof Error ? c.message : "Unknown error"
2528
+ });
2529
+ } catch {
2530
+ }
2449
2531
  yield {
2450
2532
  type: "error",
2451
2533
  data: {
2452
- message: we(d)
2534
+ message: Fe(c)
2453
2535
  }
2454
2536
  };
2455
2537
  }
2456
2538
  }
2457
- function we(o) {
2539
+ function Fe(o) {
2458
2540
  if (!o || !(o instanceof Error))
2459
2541
  return "Something went wrong. Please try again.";
2460
2542
  const t = o.message || "", a = {
@@ -2481,5 +2563,5 @@ function we(o) {
2481
2563
  return t;
2482
2564
  }
2483
2565
  export {
2484
- Ce as handleAgentChat
2566
+ Ee as handleAgentChat
2485
2567
  };