drizzle-cube 0.4.13 → 0.4.14
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.
- package/README.md +1 -0
- package/dist/adapters/express/index.cjs +6 -6
- package/dist/adapters/express/index.js +73 -72
- package/dist/adapters/fastify/index.cjs +5 -5
- package/dist/adapters/fastify/index.js +110 -109
- package/dist/adapters/{handler-CQkIwtxp.js → handler-DZnCbydH.js} +719 -272
- package/dist/adapters/handler-ZDYlokiM.cjs +25 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +121 -120
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +92 -91
- package/dist/client/charts.js +67 -59
- package/dist/client/charts.js.map +1 -1
- package/dist/client/chunks/{RetentionCombinedChart-CEI8KQ3t.js → RetentionCombinedChart-CLq89aOJ.js} +2 -2
- package/dist/client/chunks/{RetentionCombinedChart-CEI8KQ3t.js.map → RetentionCombinedChart-CLq89aOJ.js.map} +1 -1
- package/dist/client/chunks/{analysis-builder-BMmWeFPr.js → analysis-builder-C5e52Z3p.js} +419 -411
- package/dist/client/chunks/analysis-builder-C5e52Z3p.js.map +1 -0
- package/dist/client/chunks/{analysis-builder-shared-D56zYeV0.js → analysis-builder-shared-EnM-8plh.js} +2 -2
- package/dist/client/chunks/{analysis-builder-shared-D56zYeV0.js.map → analysis-builder-shared-EnM-8plh.js.map} +1 -1
- package/dist/client/chunks/{chart-activity-grid-CE7xGFQo.js → chart-activity-grid-CPGcTSuh.js} +2 -2
- package/dist/client/chunks/{chart-activity-grid-CE7xGFQo.js.map → chart-activity-grid-CPGcTSuh.js.map} +1 -1
- package/dist/client/chunks/{chart-area-BJAgusst.js → chart-area-ByJQ7NZd.js} +3 -3
- package/dist/client/chunks/{chart-area-BJAgusst.js.map → chart-area-ByJQ7NZd.js.map} +1 -1
- package/dist/client/chunks/{chart-bar-Blypx8O4.js → chart-bar-dj14frMt.js} +2 -2
- package/dist/client/chunks/{chart-bar-Blypx8O4.js.map → chart-bar-dj14frMt.js.map} +1 -1
- package/dist/client/chunks/chart-box-plot-ZatBpatq.js +322 -0
- package/dist/client/chunks/chart-box-plot-ZatBpatq.js.map +1 -0
- package/dist/client/chunks/{chart-bubble-Bf42A1-B.js → chart-bubble-CemotLx-.js} +2 -2
- package/dist/client/chunks/{chart-bubble-Bf42A1-B.js.map → chart-bubble-CemotLx-.js.map} +1 -1
- package/dist/client/chunks/chart-candlestick-BIR4uGGt.js +269 -0
- package/dist/client/chunks/chart-candlestick-BIR4uGGt.js.map +1 -0
- package/dist/client/chunks/chart-config-box-plot-D_E_SSc2.js +38 -0
- package/dist/client/chunks/chart-config-box-plot-D_E_SSc2.js.map +1 -0
- package/dist/client/chunks/chart-config-candlestick-CRCpD43-.js +70 -0
- package/dist/client/chunks/chart-config-candlestick-CRCpD43-.js.map +1 -0
- package/dist/client/chunks/chart-config-gauge-CQx9w3d4.js +64 -0
- package/dist/client/chunks/chart-config-gauge-CQx9w3d4.js.map +1 -0
- package/dist/client/chunks/chart-config-measure-profile-ZYaMrtws.js +70 -0
- package/dist/client/chunks/chart-config-measure-profile-ZYaMrtws.js.map +1 -0
- package/dist/client/chunks/chart-config-waterfall-DTyXV_fo.js +60 -0
- package/dist/client/chunks/chart-config-waterfall-DTyXV_fo.js.map +1 -0
- package/dist/client/chunks/{chart-data-table-Ba_6tuJw.js → chart-data-table-D5G8nMnb.js} +2 -2
- package/dist/client/chunks/{chart-data-table-Ba_6tuJw.js.map → chart-data-table-D5G8nMnb.js.map} +1 -1
- package/dist/client/chunks/{chart-funnel-C9kenCpp.js → chart-funnel-dofnhD24.js} +2 -2
- package/dist/client/chunks/{chart-funnel-C9kenCpp.js.map → chart-funnel-dofnhD24.js.map} +1 -1
- package/dist/client/chunks/chart-gauge-CKJJ8m3b.js +374 -0
- package/dist/client/chunks/chart-gauge-CKJJ8m3b.js.map +1 -0
- package/dist/client/chunks/{chart-heat-map-CYGemyPB.js → chart-heat-map-BVuPUKHT.js} +2 -2
- package/dist/client/chunks/{chart-heat-map-CYGemyPB.js.map → chart-heat-map-BVuPUKHT.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-delta-D9XJoKuA.js → chart-kpi-delta-Dgg2eYRl.js} +3 -3
- package/dist/client/chunks/{chart-kpi-delta-D9XJoKuA.js.map → chart-kpi-delta-Dgg2eYRl.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-number-C29Vj2g8.js → chart-kpi-number-DkoO99c1.js} +2 -2
- package/dist/client/chunks/{chart-kpi-number-C29Vj2g8.js.map → chart-kpi-number-DkoO99c1.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-text-CgjjrurK.js → chart-kpi-text-1O6_lmz7.js} +3 -3
- package/dist/client/chunks/{chart-kpi-text-CgjjrurK.js.map → chart-kpi-text-1O6_lmz7.js.map} +1 -1
- package/dist/client/chunks/{chart-line-zi6olZet.js → chart-line-DzyZkugh.js} +3 -3
- package/dist/client/chunks/{chart-line-zi6olZet.js.map → chart-line-DzyZkugh.js.map} +1 -1
- package/dist/client/chunks/chart-measure-profile-C2IkBG3V.js +114 -0
- package/dist/client/chunks/chart-measure-profile-C2IkBG3V.js.map +1 -0
- package/dist/client/chunks/{chart-pie-C4SuxKSN.js → chart-pie-akbfRfb9.js} +2 -2
- package/dist/client/chunks/{chart-pie-C4SuxKSN.js.map → chart-pie-akbfRfb9.js.map} +1 -1
- package/dist/client/chunks/{chart-radar-BW3Z_-Ly.js → chart-radar-BaN-Kjww.js} +2 -2
- package/dist/client/chunks/{chart-radar-BW3Z_-Ly.js.map → chart-radar-BaN-Kjww.js.map} +1 -1
- package/dist/client/chunks/{chart-radial-bar-0Fa3aeP5.js → chart-radial-bar-DpptEL3s.js} +2 -2
- package/dist/client/chunks/{chart-radial-bar-0Fa3aeP5.js.map → chart-radial-bar-DpptEL3s.js.map} +1 -1
- package/dist/client/chunks/{chart-sankey-DBghfbg1.js → chart-sankey-CG-3hHmX.js} +2 -2
- package/dist/client/chunks/{chart-sankey-DBghfbg1.js.map → chart-sankey-CG-3hHmX.js.map} +1 -1
- package/dist/client/chunks/{chart-scatter-DOVu1TNq.js → chart-scatter-l_yTVxF3.js} +2 -2
- package/dist/client/chunks/{chart-scatter-DOVu1TNq.js.map → chart-scatter-l_yTVxF3.js.map} +1 -1
- package/dist/client/chunks/{chart-sunburst-LfNthFlZ.js → chart-sunburst-KhDcKhmZ.js} +2 -2
- package/dist/client/chunks/{chart-sunburst-LfNthFlZ.js.map → chart-sunburst-KhDcKhmZ.js.map} +1 -1
- package/dist/client/chunks/{chart-tree-map-DZtQPyWX.js → chart-tree-map-CBbiaBXV.js} +2 -2
- package/dist/client/chunks/{chart-tree-map-DZtQPyWX.js.map → chart-tree-map-CBbiaBXV.js.map} +1 -1
- package/dist/client/chunks/chart-waterfall-CX3vx_lI.js +191 -0
- package/dist/client/chunks/chart-waterfall-CX3vx_lI.js.map +1 -0
- package/dist/client/chunks/{charts-core-DmGfleFz.js → charts-core-CU9u_HtL.js} +2 -1
- package/dist/client/chunks/charts-core-CU9u_HtL.js.map +1 -0
- package/dist/client/chunks/{charts-loader-CH0_S06T.js → charts-loader-AW3T1nv5.js} +58 -42
- package/dist/client/chunks/charts-loader-AW3T1nv5.js.map +1 -0
- package/dist/client/chunks/{components-ClQziOcT.js → components-BkeSy9xv.js} +4 -4
- package/dist/client/chunks/components-BkeSy9xv.js.map +1 -0
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +10 -0
- package/dist/client/components/AgenticNotebook/ChatMessage.d.ts +2 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +11 -1
- package/dist/client/components/LoadingIndicator.d.ts +2 -2
- package/dist/client/components/charts/BoxPlotChart.config.d.ts +1 -7
- package/dist/client/components/charts/CandlestickChart.config.d.ts +5 -0
- package/dist/client/components/charts/CandlestickChart.d.ts +4 -0
- package/dist/client/components/charts/GaugeChart.config.d.ts +5 -0
- package/dist/client/components/charts/GaugeChart.d.ts +4 -0
- package/dist/client/components/charts/MeasureProfileChart.config.d.ts +5 -0
- package/dist/client/components/charts/MeasureProfileChart.d.ts +4 -0
- package/dist/client/components/charts/WaterfallChart.config.d.ts +5 -0
- package/dist/client/components/charts/WaterfallChart.d.ts +4 -0
- package/dist/client/components/charts/index.d.ts +4 -0
- package/dist/client/components.js +1 -1
- package/dist/client/hooks/useAgentChat.d.ts +20 -2
- package/dist/client/index.js +583 -522
- package/dist/client/index.js.map +1 -1
- package/dist/client/styles.css +1 -1
- package/dist/client/types.d.ts +19 -1
- package/dist/client/utils.js +4 -4
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/index.cjs +47 -45
- package/dist/server/index.d.ts +37 -0
- package/dist/server/index.js +1745 -1298
- package/package.json +4 -1
- package/dist/adapters/handler-dnkqpznh.cjs +0 -23
- package/dist/client/chunks/analysis-builder-BMmWeFPr.js.map +0 -1
- package/dist/client/chunks/chart-box-plot-Dja4LS3O.js +0 -313
- package/dist/client/chunks/chart-box-plot-Dja4LS3O.js.map +0 -1
- package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js +0 -85
- package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js.map +0 -1
- package/dist/client/chunks/charts-core-DmGfleFz.js.map +0 -1
- package/dist/client/chunks/charts-loader-CH0_S06T.js.map +0 -1
- package/dist/client/chunks/components-ClQziOcT.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hono as L } from "hono";
|
|
2
2
|
import { S as V, v as B, b as M, a as z, n as K, p as _, w as U, d as F, g as G, f as X, i as O, c as W, M as Y, e as T, s as I } from "../mcp-transport-m1X1GtwG.js";
|
|
3
3
|
import { formatCubeResponse as k, handleBatchRequest as Z, formatMetaResponse as ee, formatSqlResponse as D, handleDryRun as J } from "../utils.js";
|
|
4
|
-
var re = (
|
|
4
|
+
var re = (C) => {
|
|
5
5
|
const y = {
|
|
6
6
|
...{
|
|
7
7
|
origin: "*",
|
|
@@ -9,71 +9,71 @@ var re = (w) => {
|
|
|
9
9
|
allowHeaders: [],
|
|
10
10
|
exposeHeaders: []
|
|
11
11
|
},
|
|
12
|
-
...
|
|
13
|
-
}, H = /* @__PURE__ */ ((
|
|
14
|
-
return async function(
|
|
15
|
-
function g(q,
|
|
16
|
-
|
|
12
|
+
...C
|
|
13
|
+
}, H = /* @__PURE__ */ ((l) => typeof l == "string" ? l === "*" ? () => l : (i) => l === i ? i : null : typeof l == "function" ? l : (i) => l.includes(i) ? i : null)(y.origin), f = ((l) => typeof l == "function" ? l : Array.isArray(l) ? () => l : () => [])(y.allowMethods);
|
|
14
|
+
return async function(i, m) {
|
|
15
|
+
function g(q, a) {
|
|
16
|
+
i.res.headers.set(q, a);
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
18
|
+
const v = await H(i.req.header("origin") || "", i);
|
|
19
|
+
if (v && g("Access-Control-Allow-Origin", v), y.credentials && g("Access-Control-Allow-Credentials", "true"), y.exposeHeaders?.length && g("Access-Control-Expose-Headers", y.exposeHeaders.join(",")), i.req.method === "OPTIONS") {
|
|
20
20
|
y.origin !== "*" && g("Vary", "Origin"), y.maxAge != null && g("Access-Control-Max-Age", y.maxAge.toString());
|
|
21
|
-
const q = await f(
|
|
21
|
+
const q = await f(i.req.header("origin") || "", i);
|
|
22
22
|
q.length && g("Access-Control-Allow-Methods", q.join(","));
|
|
23
|
-
let
|
|
24
|
-
if (!
|
|
25
|
-
const s =
|
|
26
|
-
s && (
|
|
23
|
+
let a = y.allowHeaders;
|
|
24
|
+
if (!a?.length) {
|
|
25
|
+
const s = i.req.header("Access-Control-Request-Headers");
|
|
26
|
+
s && (a = s.split(/\s*,\s*/));
|
|
27
27
|
}
|
|
28
|
-
return
|
|
29
|
-
headers:
|
|
28
|
+
return a?.length && (g("Access-Control-Allow-Headers", a.join(",")), i.res.headers.append("Vary", "Access-Control-Request-Headers")), i.res.headers.delete("Content-Length"), i.res.headers.delete("Content-Type"), new Response(null, {
|
|
29
|
+
headers: i.res.headers,
|
|
30
30
|
status: 204,
|
|
31
31
|
statusText: "No Content"
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
await m(), y.origin !== "*" &&
|
|
34
|
+
await m(), y.origin !== "*" && i.header("Vary", "Origin", { append: !0 });
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
function te(
|
|
37
|
+
function te(C) {
|
|
38
38
|
const {
|
|
39
|
-
cubes:
|
|
39
|
+
cubes: j,
|
|
40
40
|
drizzle: y,
|
|
41
41
|
schema: H,
|
|
42
42
|
extractSecurityContext: f,
|
|
43
|
-
engineType:
|
|
44
|
-
cors:
|
|
43
|
+
engineType: l,
|
|
44
|
+
cors: i,
|
|
45
45
|
basePath: m = "/cubejs-api/v1",
|
|
46
46
|
cache: g,
|
|
47
|
-
mcp:
|
|
47
|
+
mcp: v = { enabled: !0 },
|
|
48
48
|
agent: q
|
|
49
|
-
} =
|
|
50
|
-
if (!
|
|
49
|
+
} = C;
|
|
50
|
+
if (!j || j.length === 0)
|
|
51
51
|
throw new Error("At least one cube must be provided in the cubes array");
|
|
52
|
-
const
|
|
53
|
-
|
|
52
|
+
const a = new L();
|
|
53
|
+
i && a.use("/*", re(i));
|
|
54
54
|
const s = new V({
|
|
55
55
|
drizzle: y,
|
|
56
56
|
schema: H,
|
|
57
|
-
engineType:
|
|
57
|
+
engineType: l,
|
|
58
58
|
cache: g
|
|
59
59
|
});
|
|
60
|
-
if (
|
|
60
|
+
if (j.forEach((r) => {
|
|
61
61
|
s.registerCube(r);
|
|
62
|
-
}),
|
|
62
|
+
}), a.post(`${m}/load`, async (r) => {
|
|
63
63
|
try {
|
|
64
64
|
const e = await r.req.json(), n = e.query || e, o = await f(r), t = s.validateQuery(n);
|
|
65
65
|
if (!t.isValid)
|
|
66
66
|
return r.json({
|
|
67
67
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
68
68
|
}, 400);
|
|
69
|
-
const
|
|
70
|
-
return r.json(k(n,
|
|
69
|
+
const c = r.req.header("x-cache-control") === "no-cache", u = await s.executeMultiCubeQuery(n, o, { skipCache: c });
|
|
70
|
+
return r.json(k(n, u, s));
|
|
71
71
|
} catch (e) {
|
|
72
72
|
return console.error("Query execution error:", e), r.json({
|
|
73
73
|
error: e instanceof Error ? e.message : "Query execution failed"
|
|
74
74
|
}, 500);
|
|
75
75
|
}
|
|
76
|
-
}),
|
|
76
|
+
}), a.get(`${m}/load`, async (r) => {
|
|
77
77
|
try {
|
|
78
78
|
const e = r.req.query("query");
|
|
79
79
|
if (!e)
|
|
@@ -93,14 +93,14 @@ function te(w) {
|
|
|
93
93
|
return r.json({
|
|
94
94
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
95
95
|
}, 400);
|
|
96
|
-
const
|
|
97
|
-
return r.json(k(n,
|
|
96
|
+
const c = r.req.header("x-cache-control") === "no-cache", u = await s.executeMultiCubeQuery(n, o, { skipCache: c });
|
|
97
|
+
return r.json(k(n, u, s));
|
|
98
98
|
} catch (e) {
|
|
99
99
|
return console.error("Query execution error:", e), r.json({
|
|
100
100
|
error: e instanceof Error ? e.message : "Query execution failed"
|
|
101
101
|
}, 500);
|
|
102
102
|
}
|
|
103
|
-
}),
|
|
103
|
+
}), a.post(`${m}/batch`, async (r) => {
|
|
104
104
|
try {
|
|
105
105
|
const e = await r.req.json(), { queries: n } = e;
|
|
106
106
|
if (!n || !Array.isArray(n))
|
|
@@ -111,14 +111,14 @@ function te(w) {
|
|
|
111
111
|
return r.json({
|
|
112
112
|
error: "Queries array cannot be empty"
|
|
113
113
|
}, 400);
|
|
114
|
-
const o = await f(r), t = r.req.header("x-cache-control") === "no-cache",
|
|
115
|
-
return r.json(
|
|
114
|
+
const o = await f(r), t = r.req.header("x-cache-control") === "no-cache", c = await Z(n, o, s, { skipCache: t });
|
|
115
|
+
return r.json(c);
|
|
116
116
|
} catch (e) {
|
|
117
117
|
return console.error("Batch execution error:", e), r.json({
|
|
118
118
|
error: e instanceof Error ? e.message : "Batch execution failed"
|
|
119
119
|
}, 500);
|
|
120
120
|
}
|
|
121
|
-
}),
|
|
121
|
+
}), a.get(`${m}/meta`, (r) => {
|
|
122
122
|
try {
|
|
123
123
|
const e = s.getMetadata();
|
|
124
124
|
return r.json(ee(e));
|
|
@@ -127,7 +127,7 @@ function te(w) {
|
|
|
127
127
|
error: e instanceof Error ? e.message : "Failed to fetch metadata"
|
|
128
128
|
}, 500);
|
|
129
129
|
}
|
|
130
|
-
}),
|
|
130
|
+
}), a.post(`${m}/sql`, async (r) => {
|
|
131
131
|
try {
|
|
132
132
|
const e = await r.req.json(), n = await f(r), o = s.validateQuery(e);
|
|
133
133
|
if (!o.isValid)
|
|
@@ -139,14 +139,14 @@ function te(w) {
|
|
|
139
139
|
return r.json({
|
|
140
140
|
error: "No measures or dimensions specified"
|
|
141
141
|
}, 400);
|
|
142
|
-
const
|
|
143
|
-
return r.json(D(e,
|
|
142
|
+
const c = t.split(".")[0], u = await s.generateSQL(c, e, n);
|
|
143
|
+
return r.json(D(e, u));
|
|
144
144
|
} catch (e) {
|
|
145
145
|
return console.error("SQL generation error:", e), r.json({
|
|
146
146
|
error: e instanceof Error ? e.message : "SQL generation failed"
|
|
147
147
|
}, 500);
|
|
148
148
|
}
|
|
149
|
-
}),
|
|
149
|
+
}), a.get(`${m}/sql`, async (r) => {
|
|
150
150
|
try {
|
|
151
151
|
const e = r.req.query("query");
|
|
152
152
|
if (!e)
|
|
@@ -158,19 +158,19 @@ function te(w) {
|
|
|
158
158
|
return r.json({
|
|
159
159
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
160
160
|
}, 400);
|
|
161
|
-
const
|
|
162
|
-
if (!
|
|
161
|
+
const c = n.measures?.[0] || n.dimensions?.[0];
|
|
162
|
+
if (!c)
|
|
163
163
|
return r.json({
|
|
164
164
|
error: "No measures or dimensions specified"
|
|
165
165
|
}, 400);
|
|
166
|
-
const
|
|
166
|
+
const u = c.split(".")[0], h = await s.generateSQL(u, n, o);
|
|
167
167
|
return r.json(D(n, h));
|
|
168
168
|
} catch (e) {
|
|
169
169
|
return console.error("SQL generation error:", e), r.json({
|
|
170
170
|
error: e instanceof Error ? e.message : "SQL generation failed"
|
|
171
171
|
}, 500);
|
|
172
172
|
}
|
|
173
|
-
}),
|
|
173
|
+
}), a.post(`${m}/dry-run`, async (r) => {
|
|
174
174
|
try {
|
|
175
175
|
const e = await r.req.json(), n = e.query || e, o = await f(r), t = await J(n, o, s);
|
|
176
176
|
return r.json(t);
|
|
@@ -180,7 +180,7 @@ function te(w) {
|
|
|
180
180
|
valid: !1
|
|
181
181
|
}, 400);
|
|
182
182
|
}
|
|
183
|
-
}),
|
|
183
|
+
}), a.get(`${m}/dry-run`, async (r) => {
|
|
184
184
|
try {
|
|
185
185
|
const e = r.req.query("query");
|
|
186
186
|
if (!e)
|
|
@@ -196,65 +196,66 @@ function te(w) {
|
|
|
196
196
|
valid: !1
|
|
197
197
|
}, 400);
|
|
198
198
|
}
|
|
199
|
-
}),
|
|
199
|
+
}), a.post(`${m}/explain`, async (r) => {
|
|
200
200
|
try {
|
|
201
|
-
const e = await r.req.json(), n = e.query || e, o = e.options || {}, t = await f(r),
|
|
202
|
-
if (!
|
|
201
|
+
const e = await r.req.json(), n = e.query || e, o = e.options || {}, t = await f(r), c = s.validateQuery(n);
|
|
202
|
+
if (!c.isValid)
|
|
203
203
|
return r.json({
|
|
204
|
-
error: `Query validation failed: ${
|
|
204
|
+
error: `Query validation failed: ${c.errors.join(", ")}`
|
|
205
205
|
}, 400);
|
|
206
|
-
const
|
|
207
|
-
return r.json(
|
|
206
|
+
const u = await s.explainQuery(n, t, o);
|
|
207
|
+
return r.json(u);
|
|
208
208
|
} catch (e) {
|
|
209
209
|
return console.error("Explain error:", e), r.json({
|
|
210
210
|
error: e instanceof Error ? e.message : "Explain query failed"
|
|
211
211
|
}, 500);
|
|
212
212
|
}
|
|
213
|
-
}), q &&
|
|
213
|
+
}), q && a.post(`${m}/agent/chat`, async (r) => {
|
|
214
214
|
try {
|
|
215
|
-
const { handleAgentChat: e } = await import("../handler-
|
|
215
|
+
const { handleAgentChat: e } = await import("../handler-DZnCbydH.js"), n = await r.req.json(), { message: o, sessionId: t, history: c } = n;
|
|
216
216
|
if (!o || typeof o != "string")
|
|
217
217
|
return r.json({ error: "message is required and must be a string" }, 400);
|
|
218
|
-
let
|
|
218
|
+
let u = (q.apiKey || "").trim();
|
|
219
219
|
if (q.allowClientApiKey) {
|
|
220
|
-
const
|
|
221
|
-
|
|
220
|
+
const w = r.req.header("x-agent-api-key");
|
|
221
|
+
w && (u = w.trim());
|
|
222
222
|
}
|
|
223
|
-
if (!
|
|
223
|
+
if (!u)
|
|
224
224
|
return r.json({
|
|
225
225
|
error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."
|
|
226
226
|
}, 401);
|
|
227
|
-
const
|
|
228
|
-
async start(
|
|
227
|
+
const h = await f(r), x = new TextEncoder(), p = new ReadableStream({
|
|
228
|
+
async start(w) {
|
|
229
229
|
try {
|
|
230
|
-
const
|
|
230
|
+
const b = e({
|
|
231
231
|
message: o,
|
|
232
232
|
sessionId: t,
|
|
233
|
+
history: c,
|
|
233
234
|
semanticLayer: s,
|
|
234
|
-
securityContext:
|
|
235
|
+
securityContext: h,
|
|
235
236
|
agentConfig: q,
|
|
236
|
-
apiKey:
|
|
237
|
+
apiKey: u
|
|
237
238
|
});
|
|
238
|
-
for await (const
|
|
239
|
-
const
|
|
239
|
+
for await (const d of b) {
|
|
240
|
+
const R = `data: ${JSON.stringify(d)}
|
|
240
241
|
|
|
241
242
|
`;
|
|
242
|
-
|
|
243
|
+
w.enqueue(x.encode(R));
|
|
243
244
|
}
|
|
244
|
-
} catch (
|
|
245
|
-
const
|
|
245
|
+
} catch (b) {
|
|
246
|
+
const d = {
|
|
246
247
|
type: "error",
|
|
247
|
-
data: { message:
|
|
248
|
+
data: { message: b instanceof Error ? b.message : "Stream failed" }
|
|
248
249
|
};
|
|
249
|
-
|
|
250
|
+
w.enqueue(x.encode(`data: ${JSON.stringify(d)}
|
|
250
251
|
|
|
251
252
|
`));
|
|
252
253
|
} finally {
|
|
253
|
-
|
|
254
|
+
w.close();
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
});
|
|
257
|
-
return new Response(
|
|
258
|
+
return new Response(p, {
|
|
258
259
|
status: 200,
|
|
259
260
|
headers: {
|
|
260
261
|
"Content-Type": "text/event-stream",
|
|
@@ -267,23 +268,23 @@ function te(w) {
|
|
|
267
268
|
error: e instanceof Error ? e.message : "Agent chat failed"
|
|
268
269
|
}, 500);
|
|
269
270
|
}
|
|
270
|
-
}),
|
|
271
|
+
}), v.enabled !== !1) {
|
|
271
272
|
const r = {
|
|
272
273
|
uri: "drizzle-cube://schema",
|
|
273
274
|
name: "Cube Schema",
|
|
274
275
|
description: "Current cube metadata as JSON",
|
|
275
276
|
mimeType: "application/json",
|
|
276
277
|
text: JSON.stringify(s.getMetadata(), null, 2)
|
|
277
|
-
}, e = [...X(), r], n = G(), o =
|
|
278
|
-
|
|
279
|
-
const
|
|
278
|
+
}, e = [...X(), r], n = G(), o = v.basePath ?? "/mcp";
|
|
279
|
+
a.post(`${o}`, async (t) => {
|
|
280
|
+
const c = B(
|
|
280
281
|
t.req.header("origin"),
|
|
281
|
-
|
|
282
|
+
v.allowedOrigins ? { allowedOrigins: v.allowedOrigins } : {}
|
|
282
283
|
);
|
|
283
|
-
if (!
|
|
284
|
-
return t.json(M(null, -32600,
|
|
285
|
-
const
|
|
286
|
-
if (!z(
|
|
284
|
+
if (!c.valid)
|
|
285
|
+
return t.json(M(null, -32600, c.reason), 403);
|
|
286
|
+
const u = t.req.header("accept");
|
|
287
|
+
if (!z(u))
|
|
287
288
|
return t.json(M(null, -32600, "Accept header must include both application/json and text/event-stream"), 400);
|
|
288
289
|
const h = K(t.req.header());
|
|
289
290
|
if (!h.ok)
|
|
@@ -291,14 +292,14 @@ function te(w) {
|
|
|
291
292
|
error: "Unsupported MCP protocol version",
|
|
292
293
|
supported: h.supported
|
|
293
294
|
}, 426);
|
|
294
|
-
const x = await t.req.json().catch(() => null),
|
|
295
|
-
if (!
|
|
295
|
+
const x = await t.req.json().catch(() => null), p = _(x);
|
|
296
|
+
if (!p)
|
|
296
297
|
return t.json(M(null, -32600, "Invalid JSON-RPC 2.0 request"), 400);
|
|
297
|
-
const
|
|
298
|
+
const w = U(u), b = p.method === "initialize";
|
|
298
299
|
try {
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
const d = await F(
|
|
301
|
+
p.method,
|
|
302
|
+
p.params,
|
|
302
303
|
{
|
|
303
304
|
semanticLayer: s,
|
|
304
305
|
extractSecurityContext: f,
|
|
@@ -309,15 +310,15 @@ function te(w) {
|
|
|
309
310
|
prompts: n
|
|
310
311
|
}
|
|
311
312
|
);
|
|
312
|
-
if (O(
|
|
313
|
+
if (O(p))
|
|
313
314
|
return t.body(null, 202);
|
|
314
|
-
const
|
|
315
|
-
if (P && (
|
|
316
|
-
const
|
|
317
|
-
start(
|
|
318
|
-
|
|
315
|
+
const R = W(p.id ?? null, d), P = b && d && typeof d == "object" && "sessionId" in d ? d.sessionId : void 0, S = {};
|
|
316
|
+
if (P && (S[Y] = P), w) {
|
|
317
|
+
const E = new TextEncoder(), A = T(), $ = new ReadableStream({
|
|
318
|
+
start(Q) {
|
|
319
|
+
Q.enqueue(E.encode(`id: ${A}
|
|
319
320
|
|
|
320
|
-
`)),
|
|
321
|
+
`)), Q.enqueue(E.encode(I(R, A))), Q.close();
|
|
321
322
|
}
|
|
322
323
|
});
|
|
323
324
|
return new Response($, {
|
|
@@ -326,25 +327,25 @@ function te(w) {
|
|
|
326
327
|
"Content-Type": "text/event-stream",
|
|
327
328
|
"Cache-Control": "no-cache",
|
|
328
329
|
Connection: "keep-alive",
|
|
329
|
-
...
|
|
330
|
+
...S
|
|
330
331
|
}
|
|
331
332
|
});
|
|
332
333
|
}
|
|
333
|
-
return t.json(
|
|
334
|
-
} catch (
|
|
335
|
-
if (O(
|
|
336
|
-
return console.error("MCP notification processing error:",
|
|
337
|
-
console.error("MCP RPC error:",
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
334
|
+
return t.json(R, 200, S);
|
|
335
|
+
} catch (d) {
|
|
336
|
+
if (O(p))
|
|
337
|
+
return console.error("MCP notification processing error:", d), t.body(null, 202);
|
|
338
|
+
console.error("MCP RPC error:", d);
|
|
339
|
+
const R = d?.code ?? -32603, P = d?.data, S = d.message || "MCP request failed", E = M(p.id ?? null, R, S, P);
|
|
340
|
+
if (w) {
|
|
341
|
+
const A = new TextEncoder(), $ = T(), Q = new ReadableStream({
|
|
341
342
|
start(N) {
|
|
342
|
-
N.enqueue(
|
|
343
|
+
N.enqueue(A.encode(`id: ${$}
|
|
343
344
|
|
|
344
|
-
`)), N.enqueue(
|
|
345
|
+
`)), N.enqueue(A.encode(I(E, $))), N.close();
|
|
345
346
|
}
|
|
346
347
|
});
|
|
347
|
-
return new Response(
|
|
348
|
+
return new Response(Q, {
|
|
348
349
|
status: 200,
|
|
349
350
|
headers: {
|
|
350
351
|
"Content-Type": "text/event-stream",
|
|
@@ -353,19 +354,19 @@ function te(w) {
|
|
|
353
354
|
}
|
|
354
355
|
});
|
|
355
356
|
}
|
|
356
|
-
return t.json(
|
|
357
|
+
return t.json(E, 200);
|
|
357
358
|
}
|
|
358
|
-
}),
|
|
359
|
-
const
|
|
359
|
+
}), a.delete(`${o}`, (t) => t.json({ error: "Session termination not supported" }, 405)), a.get(`${o}`, (t) => {
|
|
360
|
+
const c = new TextEncoder(), u = T();
|
|
360
361
|
let h;
|
|
361
362
|
const x = new ReadableStream({
|
|
362
|
-
start(
|
|
363
|
-
|
|
363
|
+
start(p) {
|
|
364
|
+
p.enqueue(c.encode(I({
|
|
364
365
|
jsonrpc: "2.0",
|
|
365
366
|
method: "mcp/ready",
|
|
366
367
|
params: { protocol: "streamable-http" }
|
|
367
|
-
},
|
|
368
|
-
|
|
368
|
+
}, u, 15e3))), h = setInterval(() => {
|
|
369
|
+
p.enqueue(c.encode(`: keep-alive
|
|
369
370
|
|
|
370
371
|
`));
|
|
371
372
|
}, 15e3);
|
|
@@ -384,15 +385,15 @@ function te(w) {
|
|
|
384
385
|
});
|
|
385
386
|
});
|
|
386
387
|
}
|
|
387
|
-
return
|
|
388
|
+
return a;
|
|
388
389
|
}
|
|
389
|
-
function ne(
|
|
390
|
-
const y = te(
|
|
391
|
-
return
|
|
390
|
+
function ne(C, j) {
|
|
391
|
+
const y = te(j);
|
|
392
|
+
return C.route("/", y), C;
|
|
392
393
|
}
|
|
393
|
-
function ie(
|
|
394
|
-
const
|
|
395
|
-
return ne(
|
|
394
|
+
function ie(C) {
|
|
395
|
+
const j = new L();
|
|
396
|
+
return ne(j, C);
|
|
396
397
|
}
|
|
397
398
|
export {
|
|
398
399
|
ie as createCubeApp,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("next/server"),f=require("../mcp-transport-8u9G5oNa.cjs"),i=require("../utils.cjs");function g(n){const{cubes:o,drizzle:s,schema:c,engineType:d,cache:a}=n;if(!o||o.length===0)throw new Error("At least one cube must be provided in the cubes array");const t=new f.SemanticLayerCompiler({drizzle:s,schema:c,engineType:d,cache:a});return o.forEach(e=>{t.registerCube(e)}),t}function R(n,o){const s=n.headers.get("origin"),c={};return o.origin&&(typeof o.origin=="string"?c["Access-Control-Allow-Origin"]=o.origin:Array.isArray(o.origin)?s&&o.origin.includes(s)&&(c["Access-Control-Allow-Origin"]=s):typeof o.origin=="function"&&s&&o.origin(s)&&(c["Access-Control-Allow-Origin"]=s)),o.methods&&(c["Access-Control-Allow-Methods"]=o.methods.join(", ")),o.allowedHeaders&&(c["Access-Control-Allow-Headers"]=o.allowedHeaders.join(", ")),o.credentials&&(c["Access-Control-Allow-Credentials"]="true"),c}function J(n){return async function(s){const c=R(s,n);return new Response(null,{status:200,headers:c})}}function T(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{let e;if(a.method==="POST"){const j=await a.json();e=j.query||j}else if(a.method==="GET"){const j=a.nextUrl.searchParams.get("query");if(!j)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(j)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=a.headers.get("x-cache-control")==="no-cache",p=await c.executeMultiCubeQuery(e,l,{skipCache:u}),E=i.formatCubeResponse(e,p,c);return r.NextResponse.json(E,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function M(n){const{cors:o}=n,s=g(n);return async function(d,a){try{const t=s.getMetadata(),e=i.formatMetaResponse(t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js meta handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Failed to fetch metadata",500),{status:500})}}}function A(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{let e;if(a.method==="POST"){const w=await a.json();e=w.query||w}else if(a.method==="GET"){const w=a.nextUrl.searchParams.get("query");if(!w)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(w)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=e.measures?.[0]||e.dimensions?.[0];if(!u)return r.NextResponse.json(i.formatErrorResponse("No measures or dimensions specified",400),{status:400});const p=u.split(".")[0],E=await c.generateSQL(p,e,l),j=i.formatSqlResponse(e,E);return r.NextResponse.json(j,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js SQL handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500),{status:500})}}}function L(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{let e;if(a.method==="POST"){const u=await a.json();e=u.query||u}else if(a.method==="GET"){const u=a.nextUrl.searchParams.get("query");if(!u)return r.NextResponse.json({error:"Query parameter is required",valid:!1},{status:400});try{e=JSON.parse(u)}catch{return r.NextResponse.json({error:"Invalid JSON in query parameter",valid:!1},{status:400})}}else return r.NextResponse.json({error:"Method not allowed",valid:!1},{status:405});const l=await o(a,t),y=await i.handleDryRun(e,l,c);return r.NextResponse.json(y,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js dry-run handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},{status:400})}}}function D(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json(),{queries:l}=e;if(!l||!Array.isArray(l))return r.NextResponse.json(i.formatErrorResponse('Request body must contain a "queries" array',400),{status:400});if(l.length===0)return r.NextResponse.json(i.formatErrorResponse("Queries array cannot be empty",400),{status:400});const y=await o(a,t),u=a.headers.get("x-cache-control")==="no-cache",p=await i.handleBatchRequest(l,y,c,{skipCache:u});return r.NextResponse.json(p,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js batch handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500),{status:500})}}}function V(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json({error:"Method not allowed"},{status:405});const e=await a.json(),l=e.query||e,y=e.options||{},u=await o(a,t),p=c.validateQuery(l);if(!p.isValid)return r.NextResponse.json({error:`Query validation failed: ${p.errors.join(", ")}`},{status:400});const E=await c.explainQuery(l,u,y);return r.NextResponse.json(E,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js explain handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Explain query failed"},{status:500})}}}function k(n){const{cors:o}=n,s=g(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json(),e=await i.handleDiscover(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js discover handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Discovery failed",500),{status:500})}}}function q(n){const{cors:o}=n,s=g(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.naturalLanguage)return r.NextResponse.json(i.formatErrorResponse("naturalLanguage field is required",400),{status:400});const e=await i.handleSuggest(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js suggest handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query suggestion failed",500),{status:500})}}}function z(n){const{cors:o}=n,s=g(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const e=await i.handleValidate(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js validate handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query validation failed",500),{status:500})}}}function $(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json();if(!e.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const l=await o(a,t),y=await i.handleLoad(c,l,e);return r.NextResponse.json(y,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function _(n){const{extractSecurityContext:o,cors:s,mcp:c={enabled:!0}}=n,d=g(n);return async function(t){if(t.method==="DELETE")return r.NextResponse.json({error:"Session termination not supported"},{status:405});if(t.method==="GET"){const h=new TextEncoder,v=f.primeEventId(),m=new ReadableStream({start(x){x.enqueue(h.encode(f.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},v,15e3)))}}),N=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const x=R(t,s);Object.entries(x).forEach(([C,b])=>N.set(C,b))}return new r.NextResponse(m,{status:200,headers:N})}if(t.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=f.validateOriginHeader(t.headers.get("origin"),c.allowedOrigins?{allowedOrigins:c.allowedOrigins}:{});if(!e.valid)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,e.reason),{status:403});const l=t.headers.get("accept");if(!f.validateAcceptHeader(l))return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),{status:400});const y=f.negotiateProtocol(Object.fromEntries(t.headers.entries()));if(!y.ok)return r.NextResponse.json({error:"Unsupported MCP protocol version",supported:y.supported},{status:426});let u;try{u=await t.json()}catch{u=null}const p=f.parseJsonRpc(u);if(!p)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),{status:400});const E=f.wantsEventStream(l),j=p.method==="initialize",w=(h,v=200,m={})=>r.NextResponse.json(h,{status:v,headers:{...s?R(t,s):{},...m}});try{const h=await f.dispatchMcpMethod(p.method,p.params,{semanticLayer:d,extractSecurityContext:x=>o(x),rawRequest:t,rawResponse:null});if(f.isNotification(p))return new r.NextResponse(null,{status:202});const v=j&&h&&typeof h=="object"&&"sessionId"in h?h.sessionId:void 0,m={};v&&(m[f.MCP_SESSION_ID_HEADER]=v);const N=f.buildJsonRpcResult(p.id??null,h);if(E){const x=new TextEncoder,C=f.primeEventId(),b=new ReadableStream({start(S){S.enqueue(x.encode(`id: ${C}
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("next/server"),f=require("../mcp-transport-8u9G5oNa.cjs"),i=require("../utils.cjs");function j(n){const{cubes:o,drizzle:s,schema:c,engineType:d,cache:a}=n;if(!o||o.length===0)throw new Error("At least one cube must be provided in the cubes array");const t=new f.SemanticLayerCompiler({drizzle:s,schema:c,engineType:d,cache:a});return o.forEach(e=>{t.registerCube(e)}),t}function R(n,o){const s=n.headers.get("origin"),c={};return o.origin&&(typeof o.origin=="string"?c["Access-Control-Allow-Origin"]=o.origin:Array.isArray(o.origin)?s&&o.origin.includes(s)&&(c["Access-Control-Allow-Origin"]=s):typeof o.origin=="function"&&s&&o.origin(s)&&(c["Access-Control-Allow-Origin"]=s)),o.methods&&(c["Access-Control-Allow-Methods"]=o.methods.join(", ")),o.allowedHeaders&&(c["Access-Control-Allow-Headers"]=o.allowedHeaders.join(", ")),o.credentials&&(c["Access-Control-Allow-Credentials"]="true"),c}function J(n){return async function(s){const c=R(s,n);return new Response(null,{status:200,headers:c})}}function T(n){const{extractSecurityContext:o,cors:s}=n,c=j(n);return async function(a,t){try{let e;if(a.method==="POST"){const N=await a.json();e=N.query||N}else if(a.method==="GET"){const N=a.nextUrl.searchParams.get("query");if(!N)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(N)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=a.headers.get("x-cache-control")==="no-cache",p=await c.executeMultiCubeQuery(e,l,{skipCache:u}),w=i.formatCubeResponse(e,p,c);return r.NextResponse.json(w,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function M(n){const{cors:o}=n,s=j(n);return async function(d,a){try{const t=s.getMetadata(),e=i.formatMetaResponse(t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js meta handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Failed to fetch metadata",500),{status:500})}}}function A(n){const{extractSecurityContext:o,cors:s}=n,c=j(n);return async function(a,t){try{let e;if(a.method==="POST"){const v=await a.json();e=v.query||v}else if(a.method==="GET"){const v=a.nextUrl.searchParams.get("query");if(!v)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(v)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=e.measures?.[0]||e.dimensions?.[0];if(!u)return r.NextResponse.json(i.formatErrorResponse("No measures or dimensions specified",400),{status:400});const p=u.split(".")[0],w=await c.generateSQL(p,e,l),N=i.formatSqlResponse(e,w);return r.NextResponse.json(N,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js SQL handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500),{status:500})}}}function L(n){const{extractSecurityContext:o,cors:s}=n,c=j(n);return async function(a,t){try{let e;if(a.method==="POST"){const u=await a.json();e=u.query||u}else if(a.method==="GET"){const u=a.nextUrl.searchParams.get("query");if(!u)return r.NextResponse.json({error:"Query parameter is required",valid:!1},{status:400});try{e=JSON.parse(u)}catch{return r.NextResponse.json({error:"Invalid JSON in query parameter",valid:!1},{status:400})}}else return r.NextResponse.json({error:"Method not allowed",valid:!1},{status:405});const l=await o(a,t),y=await i.handleDryRun(e,l,c);return r.NextResponse.json(y,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js dry-run handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},{status:400})}}}function D(n){const{extractSecurityContext:o,cors:s}=n,c=j(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json(),{queries:l}=e;if(!l||!Array.isArray(l))return r.NextResponse.json(i.formatErrorResponse('Request body must contain a "queries" array',400),{status:400});if(l.length===0)return r.NextResponse.json(i.formatErrorResponse("Queries array cannot be empty",400),{status:400});const y=await o(a,t),u=a.headers.get("x-cache-control")==="no-cache",p=await i.handleBatchRequest(l,y,c,{skipCache:u});return r.NextResponse.json(p,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js batch handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500),{status:500})}}}function V(n){const{extractSecurityContext:o,cors:s}=n,c=j(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json({error:"Method not allowed"},{status:405});const e=await a.json(),l=e.query||e,y=e.options||{},u=await o(a,t),p=c.validateQuery(l);if(!p.isValid)return r.NextResponse.json({error:`Query validation failed: ${p.errors.join(", ")}`},{status:400});const w=await c.explainQuery(l,u,y);return r.NextResponse.json(w,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js explain handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Explain query failed"},{status:500})}}}function k(n){const{cors:o}=n,s=j(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json(),e=await i.handleDiscover(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js discover handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Discovery failed",500),{status:500})}}}function q(n){const{cors:o}=n,s=j(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.naturalLanguage)return r.NextResponse.json(i.formatErrorResponse("naturalLanguage field is required",400),{status:400});const e=await i.handleSuggest(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js suggest handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query suggestion failed",500),{status:500})}}}function z(n){const{cors:o}=n,s=j(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const e=await i.handleValidate(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js validate handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query validation failed",500),{status:500})}}}function $(n){const{extractSecurityContext:o,cors:s}=n,c=j(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json();if(!e.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const l=await o(a,t),y=await i.handleLoad(c,l,e);return r.NextResponse.json(y,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function _(n){const{extractSecurityContext:o,cors:s,mcp:c={enabled:!0}}=n,d=j(n);return async function(t){if(t.method==="DELETE")return r.NextResponse.json({error:"Session termination not supported"},{status:405});if(t.method==="GET"){const m=new TextEncoder,C=f.primeEventId(),g=new ReadableStream({start(h){h.enqueue(m.encode(f.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},C,15e3)))}}),x=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const h=R(t,s);Object.entries(h).forEach(([E,S])=>x.set(E,S))}return new r.NextResponse(g,{status:200,headers:x})}if(t.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=f.validateOriginHeader(t.headers.get("origin"),c.allowedOrigins?{allowedOrigins:c.allowedOrigins}:{});if(!e.valid)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,e.reason),{status:403});const l=t.headers.get("accept");if(!f.validateAcceptHeader(l))return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),{status:400});const y=f.negotiateProtocol(Object.fromEntries(t.headers.entries()));if(!y.ok)return r.NextResponse.json({error:"Unsupported MCP protocol version",supported:y.supported},{status:426});let u;try{u=await t.json()}catch{u=null}const p=f.parseJsonRpc(u);if(!p)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),{status:400});const w=f.wantsEventStream(l),N=p.method==="initialize",v=(m,C=200,g={})=>r.NextResponse.json(m,{status:C,headers:{...s?R(t,s):{},...g}});try{const m=await f.dispatchMcpMethod(p.method,p.params,{semanticLayer:d,extractSecurityContext:h=>o(h),rawRequest:t,rawResponse:null});if(f.isNotification(p))return new r.NextResponse(null,{status:202});const C=N&&m&&typeof m=="object"&&"sessionId"in m?m.sessionId:void 0,g={};C&&(g[f.MCP_SESSION_ID_HEADER]=C);const x=f.buildJsonRpcResult(p.id??null,m);if(w){const h=new TextEncoder,E=f.primeEventId(),S=new ReadableStream({start(H){H.enqueue(h.encode(`id: ${E}
|
|
2
2
|
|
|
3
|
-
`)),
|
|
3
|
+
`)),H.enqueue(h.encode(f.serializeSseEvent(x,E))),H.close()}}),O=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive",...g});if(s){const H=R(t,s);Object.entries(H).forEach(([b,P])=>O.set(b,P))}return new r.NextResponse(S,{status:200,headers:O})}return v(x,200,g)}catch(m){if(f.isNotification(p))return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP notification processing error:",m),new r.NextResponse(null,{status:202});process.env.NODE_ENV!=="test"&&console.error("Next.js MCP RPC handler error:",m);const C=m?.code??-32603,g=m?.data,x=m.message||"MCP request failed",h=f.buildJsonRpcError(p.id??null,C,x,g);if(w){const E=new TextEncoder,S=f.primeEventId(),O=new ReadableStream({start(b){b.enqueue(E.encode(`id: ${S}
|
|
4
4
|
|
|
5
|
-
`)),
|
|
5
|
+
`)),b.enqueue(E.encode(f.serializeSseEvent(h,S))),b.close()}}),H=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const b=R(t,s);Object.entries(b).forEach(([P,I])=>H.set(P,I))}return new r.NextResponse(O,{status:200,headers:H})}return v(h,200)}}}function Q(n){const{extractSecurityContext:o,cors:s,agent:c}=n;if(!c)throw new Error("agent config is required for createAgentChatHandler");const d=j(n);return async function(t,e){try{if(t.method!=="POST")return r.NextResponse.json({error:"Method not allowed - use POST"},{status:405});const{handleAgentChat:l}=await Promise.resolve().then(()=>require("../handler-ZDYlokiM.cjs")),y=await t.json(),{message:u,sessionId:p,history:w}=y;if(!u||typeof u!="string")return r.NextResponse.json({error:"message is required and must be a string"},{status:400});let N=(c.apiKey||"").trim();if(c.allowClientApiKey){const x=t.headers.get("x-agent-api-key");x&&(N=x.trim())}if(!N)return r.NextResponse.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},{status:401});const v=await o(t,e),m=new TextEncoder,C=new ReadableStream({async start(x){try{const h=l({message:u,sessionId:p,history:w,semanticLayer:d,securityContext:v,agentConfig:c,apiKey:N});for await(const E of h){const S=`data: ${JSON.stringify(E)}
|
|
6
6
|
|
|
7
|
-
`;
|
|
7
|
+
`;x.enqueue(m.encode(S))}}catch(h){const E={type:"error",data:{message:h instanceof Error?h.message:"Stream failed"}};x.enqueue(m.encode(`data: ${JSON.stringify(E)}
|
|
8
8
|
|
|
9
|
-
`))}finally{
|
|
9
|
+
`))}finally{x.close()}}}),g=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const x=R(t,s);Object.entries(x).forEach(([h,E])=>g.set(h,E))}return new Response(C,{status:200,headers:g})}catch(l){return process.env.NODE_ENV!=="test"&&console.error("Next.js agent chat handler error:",l),r.NextResponse.json({error:l instanceof Error?l.message:"Agent chat failed"},{status:500})}}}function K(n){const{mcp:o={enabled:!0}}=n,s={load:T(n),meta:M(n),sql:A(n),dryRun:L(n),batch:D(n),explain:V(n)};return o.enabled!==!1&&(s.mcpRpc=_(n)),n.agent&&(s.agentChat=Q(n)),s}exports.createAgentChatHandler=Q;exports.createBatchHandler=D;exports.createCubeHandlers=K;exports.createDiscoverHandler=k;exports.createDryRunHandler=L;exports.createExplainHandler=V;exports.createLoadHandler=T;exports.createMcpLoadHandler=$;exports.createMcpRpcHandler=_;exports.createMetaHandler=M;exports.createOptionsHandler=J;exports.createSqlHandler=A;exports.createSuggestHandler=q;exports.createValidateHandler=z;
|