drizzle-cube 0.4.5 → 0.4.8

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 (140) hide show
  1. package/dist/adapters/express/index.cjs +8 -4
  2. package/dist/adapters/express/index.d.ts +7 -0
  3. package/dist/adapters/express/index.js +189 -139
  4. package/dist/adapters/fastify/index.cjs +8 -4
  5. package/dist/adapters/fastify/index.d.ts +7 -0
  6. package/dist/adapters/fastify/index.js +209 -150
  7. package/dist/adapters/handler-BLcxTuwi.cjs +23 -0
  8. package/dist/adapters/handler-odjn7MIB.js +1880 -0
  9. package/dist/adapters/hono/index.cjs +8 -4
  10. package/dist/adapters/hono/index.d.ts +7 -0
  11. package/dist/adapters/hono/index.js +202 -144
  12. package/dist/adapters/{mcp-transport-YHDZWKOi.js → mcp-transport-CU5g9bxj.js} +7 -3
  13. package/dist/adapters/{mcp-transport-BqLo4hKi.cjs → mcp-transport-KX92EgkF.cjs} +21 -21
  14. package/dist/adapters/nextjs/index.cjs +7 -3
  15. package/dist/adapters/nextjs/index.d.ts +14 -0
  16. package/dist/adapters/nextjs/index.js +220 -144
  17. package/dist/client/charts/chartConfigs.d.ts +2 -9
  18. package/dist/client/charts.js +72 -70
  19. package/dist/client/charts.js.map +1 -1
  20. package/dist/client/chunks/{RetentionCombinedChart.config-C-ILIaEb.js → RetentionCombinedChart.config-Bbp2ghim.js} +2 -1
  21. package/dist/client/chunks/RetentionCombinedChart.config-Bbp2ghim.js.map +1 -0
  22. package/dist/client/chunks/{RetentionHeatmap.config-CIvhc-GT.js → RetentionHeatmap.config-BWf_-vdj.js} +2 -1
  23. package/dist/client/chunks/RetentionHeatmap.config-BWf_-vdj.js.map +1 -0
  24. package/dist/client/chunks/{analysis-builder-CG5VIMYB.js → analysis-builder-Bov_gLsf.js} +1408 -1393
  25. package/dist/client/chunks/analysis-builder-Bov_gLsf.js.map +1 -0
  26. package/dist/client/chunks/{analysis-builder-shared-CjlKJgyA.js → analysis-builder-shared-NBk6y0md.js} +3 -3
  27. package/dist/client/chunks/{analysis-builder-shared-CjlKJgyA.js.map → analysis-builder-shared-NBk6y0md.js.map} +1 -1
  28. package/dist/client/chunks/{chart-activity-grid-DStNr34n.js → chart-activity-grid-CE7xGFQo.js} +2 -2
  29. package/dist/client/chunks/{chart-activity-grid-DStNr34n.js.map → chart-activity-grid-CE7xGFQo.js.map} +1 -1
  30. package/dist/client/chunks/chart-box-plot-Dja4LS3O.js +313 -0
  31. package/dist/client/chunks/chart-box-plot-Dja4LS3O.js.map +1 -0
  32. package/dist/client/chunks/{chart-config-activity-grid-CAlo1cHA.js → chart-config-activity-grid-CmOqDuOT.js} +4 -5
  33. package/dist/client/chunks/chart-config-activity-grid-CmOqDuOT.js.map +1 -0
  34. package/dist/client/chunks/{chart-config-area-CyyJOO2T.js → chart-config-area-CK_GVApT.js} +4 -5
  35. package/dist/client/chunks/chart-config-area-CK_GVApT.js.map +1 -0
  36. package/dist/client/chunks/{chart-config-bar-soxw6m2o.js → chart-config-bar-C8uzktxl.js} +4 -5
  37. package/dist/client/chunks/chart-config-bar-C8uzktxl.js.map +1 -0
  38. package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js +85 -0
  39. package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js.map +1 -0
  40. package/dist/client/chunks/{chart-config-bubble-CuSsCHZ4.js → chart-config-bubble-q3DoQX5F.js} +4 -5
  41. package/dist/client/chunks/chart-config-bubble-q3DoQX5F.js.map +1 -0
  42. package/dist/client/chunks/{chart-config-data-table-BhgqwoqT.js → chart-config-data-table-B20Y5JCm.js} +4 -5
  43. package/dist/client/chunks/chart-config-data-table-B20Y5JCm.js.map +1 -0
  44. package/dist/client/chunks/{chart-config-funnel-BlSQYng0.js → chart-config-funnel-3eYnGg8M.js} +4 -5
  45. package/dist/client/chunks/chart-config-funnel-3eYnGg8M.js.map +1 -0
  46. package/dist/client/chunks/{chart-config-heat-map-DHQGFZhX.js → chart-config-heat-map-_wEnTnRA.js} +4 -5
  47. package/dist/client/chunks/chart-config-heat-map-_wEnTnRA.js.map +1 -0
  48. package/dist/client/chunks/{chart-config-kpi-delta-yTA5ug_l.js → chart-config-kpi-delta-DLGZ2A3X.js} +4 -5
  49. package/dist/client/chunks/chart-config-kpi-delta-DLGZ2A3X.js.map +1 -0
  50. package/dist/client/chunks/{chart-config-kpi-number-nVAwDXzq.js → chart-config-kpi-number-K-wzviXF.js} +4 -5
  51. package/dist/client/chunks/chart-config-kpi-number-K-wzviXF.js.map +1 -0
  52. package/dist/client/chunks/{chart-config-kpi-text-DZjqsx-b.js → chart-config-kpi-text-BjYqwqaJ.js} +4 -5
  53. package/dist/client/chunks/chart-config-kpi-text-BjYqwqaJ.js.map +1 -0
  54. package/dist/client/chunks/{chart-config-line-D5ME6w0v.js → chart-config-line-JNagi9tf.js} +4 -5
  55. package/dist/client/chunks/chart-config-line-JNagi9tf.js.map +1 -0
  56. package/dist/client/chunks/{chart-config-markdown-BXKL5TbQ.js → chart-config-markdown-BWQSjJpy.js} +4 -5
  57. package/dist/client/chunks/chart-config-markdown-BWQSjJpy.js.map +1 -0
  58. package/dist/client/chunks/{chart-config-pie-DlHa2jTy.js → chart-config-pie-CNLXb-fr.js} +4 -5
  59. package/dist/client/chunks/chart-config-pie-CNLXb-fr.js.map +1 -0
  60. package/dist/client/chunks/{chart-config-radar-BBAVIF0S.js → chart-config-radar-oxHfRAa3.js} +4 -5
  61. package/dist/client/chunks/chart-config-radar-oxHfRAa3.js.map +1 -0
  62. package/dist/client/chunks/{chart-config-radial-bar-CTwjDRnB.js → chart-config-radial-bar-_Aw3jAEm.js} +4 -5
  63. package/dist/client/chunks/chart-config-radial-bar-_Aw3jAEm.js.map +1 -0
  64. package/dist/client/chunks/{chart-config-sankey-CNAgsMQ4.js → chart-config-sankey-C8FX9hGF.js} +4 -5
  65. package/dist/client/chunks/chart-config-sankey-C8FX9hGF.js.map +1 -0
  66. package/dist/client/chunks/{chart-config-scatter-CWvN2E-X.js → chart-config-scatter-DFKM80eO.js} +4 -5
  67. package/dist/client/chunks/chart-config-scatter-DFKM80eO.js.map +1 -0
  68. package/dist/client/chunks/{chart-config-sunburst-W_SKwaj0.js → chart-config-sunburst-BmC0NLTU.js} +4 -5
  69. package/dist/client/chunks/chart-config-sunburst-BmC0NLTU.js.map +1 -0
  70. package/dist/client/chunks/{chart-config-tree-map-IRAYf9YM.js → chart-config-tree-map-DGMbNTaa.js} +4 -5
  71. package/dist/client/chunks/chart-config-tree-map-DGMbNTaa.js.map +1 -0
  72. package/dist/client/chunks/{chart-data-table-Ch_1c1Zo.js → chart-data-table-Ba_6tuJw.js} +2 -2
  73. package/dist/client/chunks/{chart-data-table-Ch_1c1Zo.js.map → chart-data-table-Ba_6tuJw.js.map} +1 -1
  74. package/dist/client/chunks/{chart-kpi-delta-CWCmi8vL.js → chart-kpi-delta-D9XJoKuA.js} +3 -3
  75. package/dist/client/chunks/{chart-kpi-delta-CWCmi8vL.js.map → chart-kpi-delta-D9XJoKuA.js.map} +1 -1
  76. package/dist/client/chunks/{chart-kpi-number-C-5m3qt5.js → chart-kpi-number-C29Vj2g8.js} +2 -2
  77. package/dist/client/chunks/{chart-kpi-number-C-5m3qt5.js.map → chart-kpi-number-C29Vj2g8.js.map} +1 -1
  78. package/dist/client/chunks/{chart-kpi-text--t4ibPmx.js → chart-kpi-text-CgjjrurK.js} +2 -2
  79. package/dist/client/chunks/{chart-kpi-text--t4ibPmx.js.map → chart-kpi-text-CgjjrurK.js.map} +1 -1
  80. package/dist/client/chunks/chart-markdown-Du4Z2iqK.js +2695 -0
  81. package/dist/client/chunks/chart-markdown-Du4Z2iqK.js.map +1 -0
  82. package/dist/client/chunks/{charts-loader-m5Ussksz.js → charts-loader-HYQFVOo4.js} +14 -13
  83. package/dist/client/chunks/charts-loader-HYQFVOo4.js.map +1 -0
  84. package/dist/client/chunks/{components-D-5p1LVQ.js → components-O0hh7ooo.js} +6 -6
  85. package/dist/client/chunks/components-O0hh7ooo.js.map +1 -0
  86. package/dist/client/chunks/{icons-DRreo6m8.js → icons-DAeqv1iX.js} +7 -7
  87. package/dist/client/chunks/{icons-DRreo6m8.js.map → icons-DAeqv1iX.js.map} +1 -1
  88. package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +8 -0
  89. package/dist/client/components/AgenticNotebook/ChatInput.d.ts +14 -0
  90. package/dist/client/components/AgenticNotebook/ChatMessage.d.ts +7 -0
  91. package/dist/client/components/AgenticNotebook/NotebookCanvas.d.ts +3 -0
  92. package/dist/client/components/AgenticNotebook/NotebookMarkdownBlock.d.ts +12 -0
  93. package/dist/client/components/AgenticNotebook/NotebookPortletBlock.d.ts +12 -0
  94. package/dist/client/components/AgenticNotebook/index.d.ts +34 -0
  95. package/dist/client/components/charts/BoxPlotChart.config.d.ts +11 -0
  96. package/dist/client/components/charts/BoxPlotChart.d.ts +4 -0
  97. package/dist/client/components/charts/index.d.ts +1 -0
  98. package/dist/client/components.js +1 -1
  99. package/dist/client/hooks/useAgentChat.d.ts +36 -0
  100. package/dist/client/icons.js +1 -1
  101. package/dist/client/index.d.ts +6 -0
  102. package/dist/client/index.js +923 -187
  103. package/dist/client/index.js.map +1 -1
  104. package/dist/client/stores/notebookStore.d.ts +152 -0
  105. package/dist/client/styles.css +1 -1
  106. package/dist/client/types.d.ts +1 -1
  107. package/dist/client/utils.js +3 -3
  108. package/dist/client-bundle-stats.html +4 -4
  109. package/dist/server/index.cjs +116 -90
  110. package/dist/server/index.d.ts +155 -0
  111. package/dist/server/index.js +7088 -4852
  112. package/package.json +12 -6
  113. package/dist/client/chunks/RetentionCombinedChart.config-C-ILIaEb.js.map +0 -1
  114. package/dist/client/chunks/RetentionHeatmap.config-CIvhc-GT.js.map +0 -1
  115. package/dist/client/chunks/analysis-builder-CG5VIMYB.js.map +0 -1
  116. package/dist/client/chunks/chart-config-activity-grid-CAlo1cHA.js.map +0 -1
  117. package/dist/client/chunks/chart-config-area-CyyJOO2T.js.map +0 -1
  118. package/dist/client/chunks/chart-config-bar-soxw6m2o.js.map +0 -1
  119. package/dist/client/chunks/chart-config-bubble-CuSsCHZ4.js.map +0 -1
  120. package/dist/client/chunks/chart-config-data-table-BhgqwoqT.js.map +0 -1
  121. package/dist/client/chunks/chart-config-funnel-BlSQYng0.js.map +0 -1
  122. package/dist/client/chunks/chart-config-heat-map-DHQGFZhX.js.map +0 -1
  123. package/dist/client/chunks/chart-config-kpi-delta-yTA5ug_l.js.map +0 -1
  124. package/dist/client/chunks/chart-config-kpi-number-nVAwDXzq.js.map +0 -1
  125. package/dist/client/chunks/chart-config-kpi-text-DZjqsx-b.js.map +0 -1
  126. package/dist/client/chunks/chart-config-line-D5ME6w0v.js.map +0 -1
  127. package/dist/client/chunks/chart-config-markdown-BXKL5TbQ.js.map +0 -1
  128. package/dist/client/chunks/chart-config-pie-DlHa2jTy.js.map +0 -1
  129. package/dist/client/chunks/chart-config-radar-BBAVIF0S.js.map +0 -1
  130. package/dist/client/chunks/chart-config-radial-bar-CTwjDRnB.js.map +0 -1
  131. package/dist/client/chunks/chart-config-sankey-CNAgsMQ4.js.map +0 -1
  132. package/dist/client/chunks/chart-config-scatter-CWvN2E-X.js.map +0 -1
  133. package/dist/client/chunks/chart-config-sunburst-W_SKwaj0.js.map +0 -1
  134. package/dist/client/chunks/chart-config-tree-map-IRAYf9YM.js.map +0 -1
  135. package/dist/client/chunks/chart-markdown-Rq6ORisB.js +0 -276
  136. package/dist/client/chunks/chart-markdown-Rq6ORisB.js.map +0 -1
  137. package/dist/client/chunks/chartConfigRegistry-C5dZm-ZK.js +0 -44
  138. package/dist/client/chunks/chartConfigRegistry-C5dZm-ZK.js.map +0 -1
  139. package/dist/client/chunks/charts-loader-m5Ussksz.js.map +0 -1
  140. package/dist/client/chunks/components-D-5p1LVQ.js.map +0 -1
@@ -1,57 +1,58 @@
1
- import { S as D, v as H, b as C, a as V, n as z, p as T, w as _, d as B, i as $, M as F, c as U, e as q, s as R } from "../mcp-transport-YHDZWKOi.js";
2
- import { formatErrorResponse as u, formatCubeResponse as j, handleBatchRequest as G, formatMetaResponse as K, formatSqlResponse as M, handleDryRun as I } from "../utils.js";
3
- const N = function(n, O, E) {
1
+ import { S as D, v as K, b as x, a as T, n as V, p as z, w as _, d as B, i as j, M as F, c as U, e as E, s as P } from "../mcp-transport-CU5g9bxj.js";
2
+ import { formatErrorResponse as d, formatCubeResponse as A, handleBatchRequest as X, formatMetaResponse as G, formatSqlResponse as I, handleDryRun as M } from "../utils.js";
3
+ const N = function(i, k, R) {
4
4
  const {
5
- cubes: w,
6
- drizzle: k,
7
- schema: A,
8
- extractSecurityContext: y,
5
+ cubes: S,
6
+ drizzle: O,
7
+ schema: J,
8
+ extractSecurityContext: p,
9
9
  engineType: L,
10
- cors: Q,
11
- basePath: p = "/cubejs-api/v1",
12
- bodyLimit: m = 10485760,
10
+ cors: q,
11
+ basePath: m = "/cubejs-api/v1",
12
+ bodyLimit: g = 10485760,
13
13
  // 10MB
14
- cache: J,
15
- mcp: g = { enabled: !0 }
16
- } = O;
17
- if (!w || w.length === 0)
18
- return E(new Error("At least one cube must be provided in the cubes array"));
19
- Q && n.register(import("@fastify/cors"), Q), n.addHook("onRequest", async (r, t) => {
20
- r.method === "POST" && (r.body = void 0);
14
+ cache: H,
15
+ mcp: b = { enabled: !0 },
16
+ agent: f
17
+ } = k;
18
+ if (!S || S.length === 0)
19
+ return R(new Error("At least one cube must be provided in the cubes array"));
20
+ q && i.register(import("@fastify/cors"), q), i.addHook("onRequest", async (t, r) => {
21
+ t.method === "POST" && (t.body = void 0);
21
22
  });
22
23
  const c = new D({
23
- drizzle: k,
24
- schema: A,
24
+ drizzle: O,
25
+ schema: J,
25
26
  engineType: L,
26
- cache: J
27
+ cache: H
27
28
  });
28
- if (w.forEach((r) => {
29
- c.registerCube(r);
30
- }), n.post(`${p}/load`, {
31
- bodyLimit: m,
29
+ if (S.forEach((t) => {
30
+ c.registerCube(t);
31
+ }), i.post(`${m}/load`, {
32
+ bodyLimit: g,
32
33
  schema: {
33
34
  body: {
34
35
  type: "object",
35
36
  additionalProperties: !0
36
37
  }
37
38
  }
38
- }, async (r, t) => {
39
+ }, async (t, r) => {
39
40
  try {
40
- const e = r.body, a = e.query || e, s = await y(r), o = c.validateQuery(a);
41
+ const e = t.body, a = e.query || e, n = await p(t), o = c.validateQuery(a);
41
42
  if (!o.isValid)
42
- return t.status(400).send(u(
43
+ return r.status(400).send(d(
43
44
  `Query validation failed: ${o.errors.join(", ")}`,
44
45
  400
45
46
  ));
46
- const i = r.headers["x-cache-control"] === "no-cache", d = await c.executeMultiCubeQuery(a, s, { skipCache: i });
47
- return j(a, d, c);
47
+ const s = t.headers["x-cache-control"] === "no-cache", l = await c.executeMultiCubeQuery(a, n, { skipCache: s });
48
+ return A(a, l, c);
48
49
  } catch (e) {
49
- return r.log.error(e, "Query execution error"), t.status(500).send(u(
50
+ return t.log.error(e, "Query execution error"), r.status(500).send(d(
50
51
  e instanceof Error ? e.message : "Query execution failed",
51
52
  500
52
53
  ));
53
54
  }
54
- }), n.get(`${p}/load`, {
55
+ }), i.get(`${m}/load`, {
55
56
  schema: {
56
57
  querystring: {
57
58
  type: "object",
@@ -61,34 +62,34 @@ const N = function(n, O, E) {
61
62
  required: ["query"]
62
63
  }
63
64
  }
64
- }, async (r, t) => {
65
+ }, async (t, r) => {
65
66
  try {
66
- const { query: e } = r.query;
67
+ const { query: e } = t.query;
67
68
  let a;
68
69
  try {
69
70
  a = JSON.parse(e);
70
71
  } catch {
71
- return t.status(400).send(u(
72
+ return r.status(400).send(d(
72
73
  "Invalid JSON in query parameter",
73
74
  400
74
75
  ));
75
76
  }
76
- const s = await y(r), o = c.validateQuery(a);
77
+ const n = await p(t), o = c.validateQuery(a);
77
78
  if (!o.isValid)
78
- return t.status(400).send(u(
79
+ return r.status(400).send(d(
79
80
  `Query validation failed: ${o.errors.join(", ")}`,
80
81
  400
81
82
  ));
82
- const i = r.headers["x-cache-control"] === "no-cache", d = await c.executeMultiCubeQuery(a, s, { skipCache: i });
83
- return j(a, d, c);
83
+ const s = t.headers["x-cache-control"] === "no-cache", l = await c.executeMultiCubeQuery(a, n, { skipCache: s });
84
+ return A(a, l, c);
84
85
  } catch (e) {
85
- return r.log.error(e, "Query execution error"), t.status(500).send(u(
86
+ return t.log.error(e, "Query execution error"), r.status(500).send(d(
86
87
  e instanceof Error ? e.message : "Query execution failed",
87
88
  500
88
89
  ));
89
90
  }
90
- }), n.post(`${p}/batch`, {
91
- bodyLimit: m,
91
+ }), i.post(`${m}/batch`, {
92
+ bodyLimit: g,
92
93
  schema: {
93
94
  body: {
94
95
  type: "object",
@@ -101,68 +102,68 @@ const N = function(n, O, E) {
101
102
  }
102
103
  }
103
104
  }
104
- }, async (r, t) => {
105
+ }, async (t, r) => {
105
106
  try {
106
- const { queries: e } = r.body;
107
+ const { queries: e } = t.body;
107
108
  if (!e || !Array.isArray(e))
108
- return t.status(400).send(u(
109
+ return r.status(400).send(d(
109
110
  'Request body must contain a "queries" array',
110
111
  400
111
112
  ));
112
113
  if (e.length === 0)
113
- return t.status(400).send(u(
114
+ return r.status(400).send(d(
114
115
  "Queries array cannot be empty",
115
116
  400
116
117
  ));
117
- const a = await y(r), s = r.headers["x-cache-control"] === "no-cache";
118
- return await G(e, a, c, { skipCache: s });
118
+ const a = await p(t), n = t.headers["x-cache-control"] === "no-cache";
119
+ return await X(e, a, c, { skipCache: n });
119
120
  } catch (e) {
120
- return r.log.error(e, "Batch execution error"), t.status(500).send(u(
121
+ return t.log.error(e, "Batch execution error"), r.status(500).send(d(
121
122
  e instanceof Error ? e.message : "Batch execution failed",
122
123
  500
123
124
  ));
124
125
  }
125
- }), n.get(`${p}/meta`, async (r, t) => {
126
+ }), i.get(`${m}/meta`, async (t, r) => {
126
127
  try {
127
128
  const e = c.getMetadata();
128
- return K(e);
129
+ return G(e);
129
130
  } catch (e) {
130
- return r.log.error(e, "Metadata error"), t.status(500).send(u(
131
+ return t.log.error(e, "Metadata error"), r.status(500).send(d(
131
132
  e instanceof Error ? e.message : "Failed to fetch metadata",
132
133
  500
133
134
  ));
134
135
  }
135
- }), n.post(`${p}/sql`, {
136
- bodyLimit: m,
136
+ }), i.post(`${m}/sql`, {
137
+ bodyLimit: g,
137
138
  schema: {
138
139
  body: {
139
140
  type: "object",
140
141
  additionalProperties: !0
141
142
  }
142
143
  }
143
- }, async (r, t) => {
144
+ }, async (t, r) => {
144
145
  try {
145
- const e = r.body, a = await y(r), s = c.validateQuery(e);
146
- if (!s.isValid)
147
- return t.status(400).send(u(
148
- `Query validation failed: ${s.errors.join(", ")}`,
146
+ const e = t.body, a = await p(t), n = c.validateQuery(e);
147
+ if (!n.isValid)
148
+ return r.status(400).send(d(
149
+ `Query validation failed: ${n.errors.join(", ")}`,
149
150
  400
150
151
  ));
151
152
  const o = e.measures?.[0] || e.dimensions?.[0];
152
153
  if (!o)
153
- return t.status(400).send(u(
154
+ return r.status(400).send(d(
154
155
  "No measures or dimensions specified",
155
156
  400
156
157
  ));
157
- const i = o.split(".")[0], d = await c.generateSQL(i, e, a);
158
- return M(e, d);
158
+ const s = o.split(".")[0], l = await c.generateSQL(s, e, a);
159
+ return I(e, l);
159
160
  } catch (e) {
160
- return r.log.error(e, "SQL generation error"), t.status(500).send(u(
161
+ return t.log.error(e, "SQL generation error"), r.status(500).send(d(
161
162
  e instanceof Error ? e.message : "SQL generation failed",
162
163
  500
163
164
  ));
164
165
  }
165
- }), n.get(`${p}/sql`, {
166
+ }), i.get(`${m}/sql`, {
166
167
  schema: {
167
168
  querystring: {
168
169
  type: "object",
@@ -172,47 +173,47 @@ const N = function(n, O, E) {
172
173
  required: ["query"]
173
174
  }
174
175
  }
175
- }, async (r, t) => {
176
+ }, async (t, r) => {
176
177
  try {
177
- const { query: e } = r.query, a = JSON.parse(e), s = await y(r), o = c.validateQuery(a);
178
+ const { query: e } = t.query, a = JSON.parse(e), n = await p(t), o = c.validateQuery(a);
178
179
  if (!o.isValid)
179
- return t.status(400).send(u(
180
+ return r.status(400).send(d(
180
181
  `Query validation failed: ${o.errors.join(", ")}`,
181
182
  400
182
183
  ));
183
- const i = a.measures?.[0] || a.dimensions?.[0];
184
- if (!i)
185
- return t.status(400).send(u(
184
+ const s = a.measures?.[0] || a.dimensions?.[0];
185
+ if (!s)
186
+ return r.status(400).send(d(
186
187
  "No measures or dimensions specified",
187
188
  400
188
189
  ));
189
- const d = i.split(".")[0], x = await c.generateSQL(d, a, s);
190
- return M(a, x);
190
+ const l = s.split(".")[0], y = await c.generateSQL(l, a, n);
191
+ return I(a, y);
191
192
  } catch (e) {
192
- return r.log.error(e, "SQL generation error"), t.status(500).send(u(
193
+ return t.log.error(e, "SQL generation error"), r.status(500).send(d(
193
194
  e instanceof Error ? e.message : "SQL generation failed",
194
195
  500
195
196
  ));
196
197
  }
197
- }), n.post(`${p}/dry-run`, {
198
- bodyLimit: m,
198
+ }), i.post(`${m}/dry-run`, {
199
+ bodyLimit: g,
199
200
  schema: {
200
201
  body: {
201
202
  type: "object",
202
203
  additionalProperties: !0
203
204
  }
204
205
  }
205
- }, async (r, t) => {
206
+ }, async (t, r) => {
206
207
  try {
207
- const e = r.body, a = e.query || e, s = await y(r);
208
- return await I(a, s, c);
208
+ const e = t.body, a = e.query || e, n = await p(t);
209
+ return await M(a, n, c);
209
210
  } catch (e) {
210
- return r.log.error(e, "Dry-run error"), t.status(400).send({
211
+ return t.log.error(e, "Dry-run error"), r.status(400).send({
211
212
  error: e instanceof Error ? e.message : "Dry-run validation failed",
212
213
  valid: !1
213
214
  });
214
215
  }
215
- }), n.get(`${p}/dry-run`, {
216
+ }), i.get(`${m}/dry-run`, {
216
217
  schema: {
217
218
  querystring: {
218
219
  type: "object",
@@ -222,142 +223,200 @@ const N = function(n, O, E) {
222
223
  required: ["query"]
223
224
  }
224
225
  }
225
- }, async (r, t) => {
226
+ }, async (t, r) => {
226
227
  try {
227
- const { query: e } = r.query, a = JSON.parse(e), s = await y(r);
228
- return await I(a, s, c);
228
+ const { query: e } = t.query, a = JSON.parse(e), n = await p(t);
229
+ return await M(a, n, c);
229
230
  } catch (e) {
230
- return r.log.error(e, "Dry-run error"), t.status(400).send({
231
+ return t.log.error(e, "Dry-run error"), r.status(400).send({
231
232
  error: e instanceof Error ? e.message : "Dry-run validation failed",
232
233
  valid: !1
233
234
  });
234
235
  }
235
- }), n.post(`${p}/explain`, {
236
- bodyLimit: m,
236
+ }), i.post(`${m}/explain`, {
237
+ bodyLimit: g,
237
238
  schema: {
238
239
  body: {
239
240
  type: "object",
240
241
  additionalProperties: !0
241
242
  }
242
243
  }
243
- }, async (r, t) => {
244
+ }, async (t, r) => {
244
245
  try {
245
- const e = r.body, a = e.query || e, s = e.options || {}, o = await y(r), i = c.validateQuery(a);
246
- return i.isValid ? await c.explainQuery(a, o, s) : t.status(400).send({
247
- error: `Query validation failed: ${i.errors.join(", ")}`
246
+ const e = t.body, a = e.query || e, n = e.options || {}, o = await p(t), s = c.validateQuery(a);
247
+ return s.isValid ? await c.explainQuery(a, o, n) : r.status(400).send({
248
+ error: `Query validation failed: ${s.errors.join(", ")}`
248
249
  });
249
250
  } catch (e) {
250
- return r.log.error(e, "Explain error"), t.status(500).send({
251
+ return t.log.error(e, "Explain error"), r.status(500).send({
251
252
  error: e instanceof Error ? e.message : "Explain query failed"
252
253
  });
253
254
  }
254
- }), g.enabled !== !1) {
255
- const r = g.basePath ?? "/mcp";
256
- n.post(`${r}`, {
257
- bodyLimit: m,
255
+ }), f && i.post(`${m}/agent/chat`, {
256
+ bodyLimit: g,
257
+ schema: {
258
+ body: {
259
+ type: "object",
260
+ additionalProperties: !0
261
+ }
262
+ }
263
+ }, async (t, r) => {
264
+ try {
265
+ const { handleAgentChat: e } = await import("../handler-odjn7MIB.js"), a = t.body, { message: n, sessionId: o } = a;
266
+ if (!n || typeof n != "string")
267
+ return r.status(400).send({ error: "message is required and must be a string" });
268
+ let s = (f.apiKey || "").trim();
269
+ if (f.allowClientApiKey) {
270
+ const y = t.headers["x-agent-api-key"];
271
+ y && (s = y.trim());
272
+ }
273
+ if (!s)
274
+ return r.status(401).send({
275
+ error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."
276
+ });
277
+ const l = await p(t);
278
+ r.raw.writeHead(200, {
279
+ "Content-Type": "text/event-stream",
280
+ "Cache-Control": "no-cache",
281
+ Connection: "keep-alive"
282
+ });
283
+ try {
284
+ const y = e({
285
+ message: n,
286
+ sessionId: o,
287
+ semanticLayer: c,
288
+ securityContext: l,
289
+ agentConfig: f,
290
+ apiKey: s
291
+ });
292
+ for await (const u of y)
293
+ r.raw.write(`data: ${JSON.stringify(u)}
294
+
295
+ `);
296
+ } catch (y) {
297
+ const u = {
298
+ type: "error",
299
+ data: { message: y instanceof Error ? y.message : "Stream failed" }
300
+ };
301
+ r.raw.write(`data: ${JSON.stringify(u)}
302
+
303
+ `);
304
+ } finally {
305
+ r.raw.end();
306
+ }
307
+ } catch (e) {
308
+ if (t.log.error(e, "Agent chat error"), !r.raw.headersSent)
309
+ return r.status(500).send({
310
+ error: e instanceof Error ? e.message : "Agent chat failed"
311
+ });
312
+ }
313
+ }), b.enabled !== !1) {
314
+ const t = b.basePath ?? "/mcp";
315
+ i.post(`${t}`, {
316
+ bodyLimit: g,
258
317
  schema: {
259
318
  body: {
260
319
  type: "object",
261
320
  additionalProperties: !0
262
321
  }
263
322
  }
264
- }, async (t, e) => {
265
- const a = H(
266
- t.headers.origin,
267
- g.allowedOrigins ? { allowedOrigins: g.allowedOrigins } : {}
323
+ }, async (r, e) => {
324
+ const a = K(
325
+ r.headers.origin,
326
+ b.allowedOrigins ? { allowedOrigins: b.allowedOrigins } : {}
268
327
  );
269
328
  if (!a.valid)
270
- return e.status(403).send(C(null, -32600, a.reason));
271
- const s = t.headers.accept;
272
- if (!V(s))
273
- return e.status(400).send(C(null, -32600, "Accept header must include both application/json and text/event-stream"));
274
- const o = z(t.headers);
329
+ return e.status(403).send(x(null, -32600, a.reason));
330
+ const n = r.headers.accept;
331
+ if (!T(n))
332
+ return e.status(400).send(x(null, -32600, "Accept header must include both application/json and text/event-stream"));
333
+ const o = V(r.headers);
275
334
  if (!o.ok)
276
335
  return e.status(426).send({
277
336
  error: "Unsupported MCP protocol version",
278
337
  supported: o.supported
279
338
  });
280
- const i = T(t.body);
281
- if (!i)
282
- return e.status(400).send(C(null, -32600, "Invalid JSON-RPC 2.0 request"));
283
- const d = _(s), x = i.method === "initialize";
339
+ const s = z(r.body);
340
+ if (!s)
341
+ return e.status(400).send(x(null, -32600, "Invalid JSON-RPC 2.0 request"));
342
+ const l = _(n), y = s.method === "initialize";
284
343
  try {
285
- const l = await B(
286
- i.method,
287
- i.params,
344
+ const u = await B(
345
+ s.method,
346
+ s.params,
288
347
  {
289
348
  semanticLayer: c,
290
- extractSecurityContext: y,
291
- rawRequest: t,
349
+ extractSecurityContext: p,
350
+ rawRequest: r,
292
351
  rawResponse: e,
293
352
  negotiatedProtocol: o.negotiated
294
353
  }
295
354
  );
296
- if ($(i))
355
+ if (j(s))
297
356
  return e.status(202).send();
298
- const b = x && l && typeof l == "object" && "sessionId" in l ? l.sessionId : void 0;
299
- b && e.header(F, b);
300
- const v = U(i.id ?? null, l);
301
- if (d) {
302
- const f = q();
303
- e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${f}
357
+ const v = y && u && typeof u == "object" && "sessionId" in u ? u.sessionId : void 0;
358
+ v && e.header(F, v);
359
+ const C = U(s.id ?? null, u);
360
+ if (l) {
361
+ const w = E();
362
+ e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${w}
304
363
 
305
- ${R(v, f)}`);
364
+ ${P(C, w)}`);
306
365
  return;
307
366
  }
308
- return e.send(v);
309
- } catch (l) {
310
- if ($(i))
311
- return t.log.error(l, "MCP notification processing error"), e.status(202).send();
312
- t.log.error(l, "MCP RPC error");
313
- const b = l?.code ?? -32603, v = l?.data, f = l.message || "MCP request failed", S = C(i.id ?? null, b, f, v);
314
- if (d) {
315
- const P = q();
316
- e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${P}
367
+ return e.send(C);
368
+ } catch (u) {
369
+ if (j(s))
370
+ return r.log.error(u, "MCP notification processing error"), e.status(202).send();
371
+ r.log.error(u, "MCP RPC error");
372
+ const v = u?.code ?? -32603, C = u?.data, w = u.message || "MCP request failed", Q = x(s.id ?? null, v, w, C);
373
+ if (l) {
374
+ const $ = E();
375
+ e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${$}
317
376
 
318
- ${R(S, P)}`);
377
+ ${P(Q, $)}`);
319
378
  return;
320
379
  }
321
- return e.send(S);
380
+ return e.send(Q);
322
381
  }
323
- }), n.get(`${r}`, async (t, e) => {
324
- const a = q();
382
+ }), i.get(`${t}`, async (r, e) => {
383
+ const a = E();
325
384
  e.raw.writeHead(200, {
326
385
  "Content-Type": "text/event-stream",
327
386
  "Cache-Control": "no-cache",
328
387
  Connection: "keep-alive"
329
- }), e.raw.write(R({
388
+ }), e.raw.write(P({
330
389
  jsonrpc: "2.0",
331
390
  method: "mcp/ready",
332
391
  params: { protocol: "streamable-http" }
333
392
  }, a, 15e3));
334
- const s = setInterval(() => {
393
+ const n = setInterval(() => {
335
394
  e.raw.write(`: keep-alive
336
395
 
337
396
  `);
338
397
  }, 15e3);
339
- t.raw.on("close", () => {
340
- clearInterval(s);
398
+ r.raw.on("close", () => {
399
+ clearInterval(n);
341
400
  });
342
- }), n.delete(`${r}`, async (t, e) => e.status(405).send({ error: "Session termination not supported" }));
401
+ }), i.delete(`${t}`, async (r, e) => e.status(405).send({ error: "Session termination not supported" }));
343
402
  }
344
- n.setErrorHandler(async (r, t, e) => {
345
- t.log.error(r, "Fastify cube adapter error"), e.statusCode < 400 && e.status(500);
346
- const a = r instanceof Error ? r : String(r);
347
- return u(a, e.statusCode);
348
- }), E();
403
+ i.setErrorHandler(async (t, r, e) => {
404
+ r.log.error(t, "Fastify cube adapter error"), e.statusCode < 400 && e.status(500);
405
+ const a = t instanceof Error ? t : String(t);
406
+ return d(a, e.statusCode);
407
+ }), R();
349
408
  };
350
- async function Y(h, n) {
351
- await h.register(N, n);
409
+ async function Z(h, i) {
410
+ await h.register(N, i);
352
411
  }
353
- function Z(h) {
354
- const n = require("fastify")({
412
+ function ee(h) {
413
+ const i = require("fastify")({
355
414
  logger: !0
356
415
  });
357
- return n.register(N, h), n;
416
+ return i.register(N, h), i;
358
417
  }
359
418
  export {
360
- Z as createCubeApp,
419
+ ee as createCubeApp,
361
420
  N as cubePlugin,
362
- Y as registerCubeRoutes
421
+ Z as registerCubeRoutes
363
422
  };