drizzle-cube 0.4.20 → 0.4.21
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/dist/adapters/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/adapters/anthropic-CTu9E801.js +126 -0
- package/dist/adapters/express/index.cjs +6 -6
- package/dist/adapters/express/index.js +119 -116
- package/dist/adapters/fastify/index.cjs +6 -6
- package/dist/adapters/fastify/index.js +113 -110
- package/dist/adapters/google-BAK9pnQf.cjs +2 -0
- package/dist/adapters/google-DficVAsJ.js +146 -0
- package/dist/adapters/{handler-CbDMdSY5.js → handler-9Rdn7zM2.js} +534 -461
- package/dist/adapters/handler-B-tEntiU.cjs +39 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +199 -196
- package/dist/adapters/index-BIMhF5KZ.cjs +23 -0
- package/dist/adapters/index-BgCeQBuN.cjs +2 -0
- package/dist/adapters/index-C45_meK_.js +719 -0
- package/dist/adapters/index-CFEJ62GJ.js +5337 -0
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +245 -242
- package/dist/adapters/openai-CUSRuKTk.js +131 -0
- package/dist/adapters/openai-mLo2MCat.cjs +1 -0
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +3 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +6 -0
- package/dist/client/hooks/useAgentChat.d.ts +6 -0
- package/dist/client/index.js +730 -697
- package/dist/client/index.js.map +1 -1
- package/dist/client/styles.css +1 -1
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/server/anthropic-CTu9E801.js +126 -0
- package/dist/server/google-BAK9pnQf.cjs +2 -0
- package/dist/server/google-DficVAsJ.js +146 -0
- package/dist/server/index-BIMhF5KZ.cjs +23 -0
- package/dist/server/index-BgCeQBuN.cjs +2 -0
- package/dist/server/index-C45_meK_.js +719 -0
- package/dist/server/index-CFEJ62GJ.js +5337 -0
- package/dist/server/index.cjs +48 -46
- package/dist/server/index.d.ts +37 -10
- package/dist/server/index.js +1974 -1901
- package/dist/server/openai-CUSRuKTk.js +131 -0
- package/dist/server/openai-mLo2MCat.cjs +1 -0
- package/package.json +12 -2
- package/dist/adapters/handler-DtdjM1Vx.cjs +0 -37
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { NextResponse as
|
|
2
|
-
import { e as T, s as A, v as D, b as
|
|
3
|
-
import { formatErrorResponse as i, formatCubeResponse as z, formatMetaResponse as
|
|
4
|
-
function
|
|
1
|
+
import { NextResponse as r } from "next/server";
|
|
2
|
+
import { e as T, s as A, v as D, b as R, a as _, n as Q, p as V, w as I, d as J, i as M, M as k, c as K, S as $ } from "../mcp-transport-m1X1GtwG.js";
|
|
3
|
+
import { formatErrorResponse as i, formatCubeResponse as z, formatMetaResponse as U, formatSqlResponse as G, handleDryRun as B, handleBatchRequest as F, handleDiscover as X, handleSuggest as q, handleValidate as W, handleLoad as Y } from "../utils.js";
|
|
4
|
+
function E(n) {
|
|
5
5
|
const { cubes: a, drizzle: s, schema: c, engineType: d, cache: o } = n;
|
|
6
6
|
if (!a || a.length === 0)
|
|
7
7
|
throw new Error("At least one cube must be provided in the cubes array");
|
|
8
|
-
const
|
|
8
|
+
const t = new $({
|
|
9
9
|
drizzle: s,
|
|
10
10
|
schema: c,
|
|
11
11
|
engineType: d,
|
|
12
12
|
cache: o
|
|
13
13
|
});
|
|
14
14
|
return a.forEach((e) => {
|
|
15
|
-
|
|
16
|
-
}),
|
|
15
|
+
t.registerCube(e);
|
|
16
|
+
}), t;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function m(n, a) {
|
|
19
19
|
const s = n.headers.get("origin"), c = {};
|
|
20
20
|
return a.origin && (typeof a.origin == "string" ? c["Access-Control-Allow-Origin"] = a.origin : Array.isArray(a.origin) ? s && a.origin.includes(s) && (c["Access-Control-Allow-Origin"] = s) : typeof a.origin == "function" && s && a.origin(s) && (c["Access-Control-Allow-Origin"] = s)), a.methods && (c["Access-Control-Allow-Methods"] = a.methods.join(", ")), a.allowedHeaders && (c["Access-Control-Allow-Headers"] = a.allowedHeaders.join(", ")), a.credentials && (c["Access-Control-Allow-Credentials"] = "true"), c;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function le(n) {
|
|
23
23
|
return async function(s) {
|
|
24
|
-
const c =
|
|
24
|
+
const c = m(s, n);
|
|
25
25
|
return new Response(null, {
|
|
26
26
|
status: 200,
|
|
27
27
|
headers: c
|
|
@@ -29,45 +29,45 @@ function ue(n) {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
function Z(n) {
|
|
32
|
-
const { extractSecurityContext: a, cors: s } = n, c =
|
|
33
|
-
return async function(o,
|
|
32
|
+
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
33
|
+
return async function(o, t) {
|
|
34
34
|
try {
|
|
35
35
|
let e;
|
|
36
36
|
if (o.method === "POST") {
|
|
37
|
-
const
|
|
38
|
-
e =
|
|
37
|
+
const j = await o.json();
|
|
38
|
+
e = j.query || j;
|
|
39
39
|
} else if (o.method === "GET") {
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
42
|
-
return
|
|
40
|
+
const j = o.nextUrl.searchParams.get("query");
|
|
41
|
+
if (!j)
|
|
42
|
+
return r.json(
|
|
43
43
|
i("Query parameter is required", 400),
|
|
44
44
|
{ status: 400 }
|
|
45
45
|
);
|
|
46
46
|
try {
|
|
47
|
-
e = JSON.parse(
|
|
47
|
+
e = JSON.parse(j);
|
|
48
48
|
} catch {
|
|
49
|
-
return
|
|
49
|
+
return r.json(
|
|
50
50
|
i("Invalid JSON in query parameter", 400),
|
|
51
51
|
{ status: 400 }
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
} else
|
|
55
|
-
return
|
|
55
|
+
return r.json(
|
|
56
56
|
i("Method not allowed", 405),
|
|
57
57
|
{ status: 405 }
|
|
58
58
|
);
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
61
|
-
return
|
|
62
|
-
i(`Query validation failed: ${
|
|
59
|
+
const l = await a(o, t), y = c.validateQuery(e);
|
|
60
|
+
if (!y.isValid)
|
|
61
|
+
return r.json(
|
|
62
|
+
i(`Query validation failed: ${y.errors.join(", ")}`, 400),
|
|
63
63
|
{ status: 400 }
|
|
64
64
|
);
|
|
65
|
-
const
|
|
66
|
-
return
|
|
67
|
-
headers: s ?
|
|
65
|
+
const u = o.headers.get("x-cache-control") === "no-cache", f = await c.executeMultiCubeQuery(e, l, { skipCache: u }), C = z(e, f, c);
|
|
66
|
+
return r.json(C, {
|
|
67
|
+
headers: s ? m(o, s) : {}
|
|
68
68
|
});
|
|
69
69
|
} catch (e) {
|
|
70
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js load handler error:", e),
|
|
70
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js load handler error:", e), r.json(
|
|
71
71
|
i(
|
|
72
72
|
e instanceof Error ? e.message : "Query execution failed",
|
|
73
73
|
500
|
|
@@ -78,17 +78,17 @@ function Z(n) {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
function ee(n) {
|
|
81
|
-
const { cors: a } = n, s =
|
|
81
|
+
const { cors: a } = n, s = E(n);
|
|
82
82
|
return async function(d, o) {
|
|
83
83
|
try {
|
|
84
|
-
const
|
|
85
|
-
return
|
|
86
|
-
headers: a ?
|
|
84
|
+
const t = s.getMetadata(), e = U(t);
|
|
85
|
+
return r.json(e, {
|
|
86
|
+
headers: a ? m(d, a) : {}
|
|
87
87
|
});
|
|
88
|
-
} catch (
|
|
89
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js meta handler error:",
|
|
88
|
+
} catch (t) {
|
|
89
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js meta handler error:", t), r.json(
|
|
90
90
|
i(
|
|
91
|
-
|
|
91
|
+
t instanceof Error ? t.message : "Failed to fetch metadata",
|
|
92
92
|
500
|
|
93
93
|
),
|
|
94
94
|
{ status: 500 }
|
|
@@ -97,51 +97,51 @@ function ee(n) {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
function te(n) {
|
|
100
|
-
const { extractSecurityContext: a, cors: s } = n, c =
|
|
101
|
-
return async function(o,
|
|
100
|
+
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
101
|
+
return async function(o, t) {
|
|
102
102
|
try {
|
|
103
103
|
let e;
|
|
104
104
|
if (o.method === "POST") {
|
|
105
|
-
const
|
|
106
|
-
e =
|
|
105
|
+
const S = await o.json();
|
|
106
|
+
e = S.query || S;
|
|
107
107
|
} else if (o.method === "GET") {
|
|
108
|
-
const
|
|
109
|
-
if (!
|
|
110
|
-
return
|
|
108
|
+
const S = o.nextUrl.searchParams.get("query");
|
|
109
|
+
if (!S)
|
|
110
|
+
return r.json(
|
|
111
111
|
i("Query parameter is required", 400),
|
|
112
112
|
{ status: 400 }
|
|
113
113
|
);
|
|
114
114
|
try {
|
|
115
|
-
e = JSON.parse(
|
|
115
|
+
e = JSON.parse(S);
|
|
116
116
|
} catch {
|
|
117
|
-
return
|
|
117
|
+
return r.json(
|
|
118
118
|
i("Invalid JSON in query parameter", 400),
|
|
119
119
|
{ status: 400 }
|
|
120
120
|
);
|
|
121
121
|
}
|
|
122
122
|
} else
|
|
123
|
-
return
|
|
123
|
+
return r.json(
|
|
124
124
|
i("Method not allowed", 405),
|
|
125
125
|
{ status: 405 }
|
|
126
126
|
);
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
return
|
|
130
|
-
i(`Query validation failed: ${
|
|
127
|
+
const l = await a(o, t), y = c.validateQuery(e);
|
|
128
|
+
if (!y.isValid)
|
|
129
|
+
return r.json(
|
|
130
|
+
i(`Query validation failed: ${y.errors.join(", ")}`, 400),
|
|
131
131
|
{ status: 400 }
|
|
132
132
|
);
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
135
|
-
return
|
|
133
|
+
const u = e.measures?.[0] || e.dimensions?.[0];
|
|
134
|
+
if (!u)
|
|
135
|
+
return r.json(
|
|
136
136
|
i("No measures or dimensions specified", 400),
|
|
137
137
|
{ status: 400 }
|
|
138
138
|
);
|
|
139
|
-
const
|
|
140
|
-
return
|
|
141
|
-
headers: s ?
|
|
139
|
+
const f = u.split(".")[0], C = await c.generateSQL(f, e, l), j = G(e, C);
|
|
140
|
+
return r.json(j, {
|
|
141
|
+
headers: s ? m(o, s) : {}
|
|
142
142
|
});
|
|
143
143
|
} catch (e) {
|
|
144
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js SQL handler error:", e),
|
|
144
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js SQL handler error:", e), r.json(
|
|
145
145
|
i(
|
|
146
146
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
147
147
|
500
|
|
@@ -152,39 +152,39 @@ function te(n) {
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
function re(n) {
|
|
155
|
-
const { extractSecurityContext: a, cors: s } = n, c =
|
|
156
|
-
return async function(o,
|
|
155
|
+
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
156
|
+
return async function(o, t) {
|
|
157
157
|
try {
|
|
158
158
|
let e;
|
|
159
159
|
if (o.method === "POST") {
|
|
160
|
-
const
|
|
161
|
-
e =
|
|
160
|
+
const u = await o.json();
|
|
161
|
+
e = u.query || u;
|
|
162
162
|
} else if (o.method === "GET") {
|
|
163
|
-
const
|
|
164
|
-
if (!
|
|
165
|
-
return
|
|
163
|
+
const u = o.nextUrl.searchParams.get("query");
|
|
164
|
+
if (!u)
|
|
165
|
+
return r.json(
|
|
166
166
|
{ error: "Query parameter is required", valid: !1 },
|
|
167
167
|
{ status: 400 }
|
|
168
168
|
);
|
|
169
169
|
try {
|
|
170
|
-
e = JSON.parse(
|
|
170
|
+
e = JSON.parse(u);
|
|
171
171
|
} catch {
|
|
172
|
-
return
|
|
172
|
+
return r.json(
|
|
173
173
|
{ error: "Invalid JSON in query parameter", valid: !1 },
|
|
174
174
|
{ status: 400 }
|
|
175
175
|
);
|
|
176
176
|
}
|
|
177
177
|
} else
|
|
178
|
-
return
|
|
178
|
+
return r.json(
|
|
179
179
|
{ error: "Method not allowed", valid: !1 },
|
|
180
180
|
{ status: 405 }
|
|
181
181
|
);
|
|
182
|
-
const
|
|
183
|
-
return
|
|
184
|
-
headers: s ?
|
|
182
|
+
const l = await a(o, t), y = await B(e, l, c);
|
|
183
|
+
return r.json(y, {
|
|
184
|
+
headers: s ? m(o, s) : {}
|
|
185
185
|
});
|
|
186
186
|
} catch (e) {
|
|
187
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js dry-run handler error:", e),
|
|
187
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js dry-run handler error:", e), r.json(
|
|
188
188
|
{
|
|
189
189
|
error: e instanceof Error ? e.message : "Dry-run validation failed",
|
|
190
190
|
valid: !1
|
|
@@ -195,31 +195,31 @@ function re(n) {
|
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
function ne(n) {
|
|
198
|
-
const { extractSecurityContext: a, cors: s } = n, c =
|
|
199
|
-
return async function(o,
|
|
198
|
+
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
199
|
+
return async function(o, t) {
|
|
200
200
|
try {
|
|
201
201
|
if (o.method !== "POST")
|
|
202
|
-
return
|
|
202
|
+
return r.json(
|
|
203
203
|
i("Method not allowed - use POST", 405),
|
|
204
204
|
{ status: 405 }
|
|
205
205
|
);
|
|
206
|
-
const e = await o.json(), { queries:
|
|
207
|
-
if (!
|
|
208
|
-
return
|
|
206
|
+
const e = await o.json(), { queries: l } = e;
|
|
207
|
+
if (!l || !Array.isArray(l))
|
|
208
|
+
return r.json(
|
|
209
209
|
i('Request body must contain a "queries" array', 400),
|
|
210
210
|
{ status: 400 }
|
|
211
211
|
);
|
|
212
|
-
if (
|
|
213
|
-
return
|
|
212
|
+
if (l.length === 0)
|
|
213
|
+
return r.json(
|
|
214
214
|
i("Queries array cannot be empty", 400),
|
|
215
215
|
{ status: 400 }
|
|
216
216
|
);
|
|
217
|
-
const
|
|
218
|
-
return
|
|
219
|
-
headers: s ?
|
|
217
|
+
const y = await a(o, t), u = o.headers.get("x-cache-control") === "no-cache", f = await F(l, y, c, { skipCache: u });
|
|
218
|
+
return r.json(f, {
|
|
219
|
+
headers: s ? m(o, s) : {}
|
|
220
220
|
});
|
|
221
221
|
} catch (e) {
|
|
222
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js batch handler error:", e),
|
|
222
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js batch handler error:", e), r.json(
|
|
223
223
|
i(
|
|
224
224
|
e instanceof Error ? e.message : "Batch execution failed",
|
|
225
225
|
500
|
|
@@ -230,53 +230,53 @@ function ne(n) {
|
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
232
|
function se(n) {
|
|
233
|
-
const { extractSecurityContext: a, cors: s } = n, c =
|
|
234
|
-
return async function(o,
|
|
233
|
+
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
234
|
+
return async function(o, t) {
|
|
235
235
|
try {
|
|
236
236
|
if (o.method !== "POST")
|
|
237
|
-
return
|
|
237
|
+
return r.json(
|
|
238
238
|
{ error: "Method not allowed" },
|
|
239
239
|
{ status: 405 }
|
|
240
240
|
);
|
|
241
|
-
const e = await o.json(),
|
|
242
|
-
if (!
|
|
243
|
-
return
|
|
244
|
-
{ error: `Query validation failed: ${
|
|
241
|
+
const e = await o.json(), l = e.query || e, y = e.options || {}, u = await a(o, t), f = c.validateQuery(l);
|
|
242
|
+
if (!f.isValid)
|
|
243
|
+
return r.json(
|
|
244
|
+
{ error: `Query validation failed: ${f.errors.join(", ")}` },
|
|
245
245
|
{ status: 400 }
|
|
246
246
|
);
|
|
247
|
-
const
|
|
248
|
-
u,
|
|
247
|
+
const C = await c.explainQuery(
|
|
249
248
|
l,
|
|
250
|
-
|
|
249
|
+
u,
|
|
250
|
+
y
|
|
251
251
|
);
|
|
252
|
-
return
|
|
253
|
-
headers: s ?
|
|
252
|
+
return r.json(C, {
|
|
253
|
+
headers: s ? m(o, s) : {}
|
|
254
254
|
});
|
|
255
255
|
} catch (e) {
|
|
256
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js explain handler error:", e),
|
|
256
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js explain handler error:", e), r.json(
|
|
257
257
|
{ error: e instanceof Error ? e.message : "Explain query failed" },
|
|
258
258
|
{ status: 500 }
|
|
259
259
|
);
|
|
260
260
|
}
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
|
-
function
|
|
264
|
-
const { cors: a } = n, s =
|
|
263
|
+
function ue(n) {
|
|
264
|
+
const { cors: a } = n, s = E(n);
|
|
265
265
|
return async function(d, o) {
|
|
266
266
|
try {
|
|
267
267
|
if (d.method !== "POST")
|
|
268
|
-
return
|
|
268
|
+
return r.json(
|
|
269
269
|
i("Method not allowed - use POST", 405),
|
|
270
270
|
{ status: 405 }
|
|
271
271
|
);
|
|
272
|
-
const
|
|
273
|
-
return
|
|
274
|
-
headers: a ?
|
|
272
|
+
const t = await d.json(), e = await X(s, t);
|
|
273
|
+
return r.json(e, {
|
|
274
|
+
headers: a ? m(d, a) : {}
|
|
275
275
|
});
|
|
276
|
-
} catch (
|
|
277
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js discover handler error:",
|
|
276
|
+
} catch (t) {
|
|
277
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js discover handler error:", t), r.json(
|
|
278
278
|
i(
|
|
279
|
-
|
|
279
|
+
t instanceof Error ? t.message : "Discovery failed",
|
|
280
280
|
500
|
|
281
281
|
),
|
|
282
282
|
{ status: 500 }
|
|
@@ -285,28 +285,28 @@ function le(n) {
|
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
287
|
function fe(n) {
|
|
288
|
-
const { cors: a } = n, s =
|
|
288
|
+
const { cors: a } = n, s = E(n);
|
|
289
289
|
return async function(d, o) {
|
|
290
290
|
try {
|
|
291
291
|
if (d.method !== "POST")
|
|
292
|
-
return
|
|
292
|
+
return r.json(
|
|
293
293
|
i("Method not allowed - use POST", 405),
|
|
294
294
|
{ status: 405 }
|
|
295
295
|
);
|
|
296
|
-
const
|
|
297
|
-
if (!
|
|
298
|
-
return
|
|
296
|
+
const t = await d.json();
|
|
297
|
+
if (!t.naturalLanguage)
|
|
298
|
+
return r.json(
|
|
299
299
|
i("naturalLanguage field is required", 400),
|
|
300
300
|
{ status: 400 }
|
|
301
301
|
);
|
|
302
|
-
const e = await
|
|
303
|
-
return
|
|
304
|
-
headers: a ?
|
|
302
|
+
const e = await q(s, t);
|
|
303
|
+
return r.json(e, {
|
|
304
|
+
headers: a ? m(d, a) : {}
|
|
305
305
|
});
|
|
306
|
-
} catch (
|
|
307
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js suggest handler error:",
|
|
306
|
+
} catch (t) {
|
|
307
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js suggest handler error:", t), r.json(
|
|
308
308
|
i(
|
|
309
|
-
|
|
309
|
+
t instanceof Error ? t.message : "Query suggestion failed",
|
|
310
310
|
500
|
|
311
311
|
),
|
|
312
312
|
{ status: 500 }
|
|
@@ -315,28 +315,28 @@ function fe(n) {
|
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
317
|
function ye(n) {
|
|
318
|
-
const { cors: a } = n, s =
|
|
318
|
+
const { cors: a } = n, s = E(n);
|
|
319
319
|
return async function(d, o) {
|
|
320
320
|
try {
|
|
321
321
|
if (d.method !== "POST")
|
|
322
|
-
return
|
|
322
|
+
return r.json(
|
|
323
323
|
i("Method not allowed - use POST", 405),
|
|
324
324
|
{ status: 405 }
|
|
325
325
|
);
|
|
326
|
-
const
|
|
327
|
-
if (!
|
|
328
|
-
return
|
|
326
|
+
const t = await d.json();
|
|
327
|
+
if (!t.query)
|
|
328
|
+
return r.json(
|
|
329
329
|
i("query field is required", 400),
|
|
330
330
|
{ status: 400 }
|
|
331
331
|
);
|
|
332
|
-
const e = await W(s,
|
|
333
|
-
return
|
|
334
|
-
headers: a ?
|
|
332
|
+
const e = await W(s, t);
|
|
333
|
+
return r.json(e, {
|
|
334
|
+
headers: a ? m(d, a) : {}
|
|
335
335
|
});
|
|
336
|
-
} catch (
|
|
337
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js validate handler error:",
|
|
336
|
+
} catch (t) {
|
|
337
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js validate handler error:", t), r.json(
|
|
338
338
|
i(
|
|
339
|
-
|
|
339
|
+
t instanceof Error ? t.message : "Query validation failed",
|
|
340
340
|
500
|
|
341
341
|
),
|
|
342
342
|
{ status: 500 }
|
|
@@ -345,26 +345,26 @@ function ye(n) {
|
|
|
345
345
|
};
|
|
346
346
|
}
|
|
347
347
|
function he(n) {
|
|
348
|
-
const { extractSecurityContext: a, cors: s } = n, c =
|
|
349
|
-
return async function(o,
|
|
348
|
+
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
349
|
+
return async function(o, t) {
|
|
350
350
|
try {
|
|
351
351
|
if (o.method !== "POST")
|
|
352
|
-
return
|
|
352
|
+
return r.json(
|
|
353
353
|
i("Method not allowed - use POST", 405),
|
|
354
354
|
{ status: 405 }
|
|
355
355
|
);
|
|
356
356
|
const e = await o.json();
|
|
357
357
|
if (!e.query)
|
|
358
|
-
return
|
|
358
|
+
return r.json(
|
|
359
359
|
i("query field is required", 400),
|
|
360
360
|
{ status: 400 }
|
|
361
361
|
);
|
|
362
|
-
const
|
|
363
|
-
return
|
|
364
|
-
headers: s ?
|
|
362
|
+
const l = await a(o, t), y = await Y(c, l, e);
|
|
363
|
+
return r.json(y, {
|
|
364
|
+
headers: s ? m(o, s) : {}
|
|
365
365
|
});
|
|
366
366
|
} catch (e) {
|
|
367
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js MCP load handler error:", e),
|
|
367
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js MCP load handler error:", e), r.json(
|
|
368
368
|
i(
|
|
369
369
|
e instanceof Error ? e.message : "Query execution failed",
|
|
370
370
|
500
|
|
@@ -375,135 +375,135 @@ function he(n) {
|
|
|
375
375
|
};
|
|
376
376
|
}
|
|
377
377
|
function ae(n) {
|
|
378
|
-
const { extractSecurityContext: a, cors: s, mcp: c = { enabled: !0 } } = n, d =
|
|
379
|
-
return async function(
|
|
380
|
-
if (
|
|
381
|
-
return
|
|
378
|
+
const { extractSecurityContext: a, cors: s, mcp: c = { enabled: !0 } } = n, d = E(n);
|
|
379
|
+
return async function(t) {
|
|
380
|
+
if (t.method === "DELETE")
|
|
381
|
+
return r.json(
|
|
382
382
|
{ error: "Session termination not supported" },
|
|
383
383
|
{ status: 405 }
|
|
384
384
|
);
|
|
385
|
-
if (
|
|
386
|
-
const
|
|
387
|
-
start(
|
|
388
|
-
|
|
385
|
+
if (t.method === "GET") {
|
|
386
|
+
const h = new TextEncoder(), N = T(), x = new ReadableStream({
|
|
387
|
+
start(p) {
|
|
388
|
+
p.enqueue(h.encode(A({
|
|
389
389
|
jsonrpc: "2.0",
|
|
390
390
|
method: "mcp/ready",
|
|
391
391
|
params: { protocol: "streamable-http" }
|
|
392
|
-
},
|
|
392
|
+
}, N, 15e3)));
|
|
393
393
|
}
|
|
394
|
-
}),
|
|
394
|
+
}), b = new Headers({
|
|
395
395
|
"Content-Type": "text/event-stream",
|
|
396
396
|
"Cache-Control": "no-cache",
|
|
397
397
|
Connection: "keep-alive"
|
|
398
398
|
});
|
|
399
399
|
if (s) {
|
|
400
|
-
const
|
|
401
|
-
Object.entries(
|
|
400
|
+
const p = m(t, s);
|
|
401
|
+
Object.entries(p).forEach(([O, H]) => b.set(O, H));
|
|
402
402
|
}
|
|
403
|
-
return new
|
|
403
|
+
return new r(x, { status: 200, headers: b });
|
|
404
404
|
}
|
|
405
|
-
if (
|
|
406
|
-
return
|
|
405
|
+
if (t.method !== "POST")
|
|
406
|
+
return r.json(
|
|
407
407
|
i("Method not allowed - use POST", 405),
|
|
408
408
|
{ status: 405 }
|
|
409
409
|
);
|
|
410
410
|
const e = D(
|
|
411
|
-
|
|
411
|
+
t.headers.get("origin"),
|
|
412
412
|
c.allowedOrigins ? { allowedOrigins: c.allowedOrigins } : {}
|
|
413
413
|
);
|
|
414
414
|
if (!e.valid)
|
|
415
|
-
return
|
|
416
|
-
|
|
415
|
+
return r.json(
|
|
416
|
+
R(null, -32600, e.reason),
|
|
417
417
|
{ status: 403 }
|
|
418
418
|
);
|
|
419
|
-
const
|
|
420
|
-
if (!_(
|
|
421
|
-
return
|
|
422
|
-
|
|
419
|
+
const l = t.headers.get("accept");
|
|
420
|
+
if (!_(l))
|
|
421
|
+
return r.json(
|
|
422
|
+
R(null, -32600, "Accept header must include both application/json and text/event-stream"),
|
|
423
423
|
{ status: 400 }
|
|
424
424
|
);
|
|
425
|
-
const
|
|
426
|
-
if (!
|
|
427
|
-
return
|
|
425
|
+
const y = Q(Object.fromEntries(t.headers.entries()));
|
|
426
|
+
if (!y.ok)
|
|
427
|
+
return r.json({
|
|
428
428
|
error: "Unsupported MCP protocol version",
|
|
429
|
-
supported:
|
|
429
|
+
supported: y.supported
|
|
430
430
|
}, { status: 426 });
|
|
431
|
-
let
|
|
431
|
+
let u;
|
|
432
432
|
try {
|
|
433
|
-
|
|
433
|
+
u = await t.json();
|
|
434
434
|
} catch {
|
|
435
|
-
|
|
435
|
+
u = null;
|
|
436
436
|
}
|
|
437
|
-
const
|
|
438
|
-
if (!
|
|
439
|
-
return
|
|
440
|
-
|
|
437
|
+
const f = V(u);
|
|
438
|
+
if (!f)
|
|
439
|
+
return r.json(
|
|
440
|
+
R(null, -32600, "Invalid JSON-RPC 2.0 request"),
|
|
441
441
|
{ status: 400 }
|
|
442
442
|
);
|
|
443
|
-
const
|
|
444
|
-
status:
|
|
445
|
-
headers: { ...s ?
|
|
443
|
+
const C = I(l), j = f.method === "initialize", S = (h, N = 200, x = {}) => r.json(h, {
|
|
444
|
+
status: N,
|
|
445
|
+
headers: { ...s ? m(t, s) : {}, ...x }
|
|
446
446
|
});
|
|
447
447
|
try {
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
448
|
+
const h = await J(
|
|
449
|
+
f.method,
|
|
450
|
+
f.params,
|
|
451
451
|
{
|
|
452
452
|
semanticLayer: d,
|
|
453
|
-
extractSecurityContext: (
|
|
454
|
-
rawRequest:
|
|
453
|
+
extractSecurityContext: (p) => a(p),
|
|
454
|
+
rawRequest: t,
|
|
455
455
|
rawResponse: null
|
|
456
456
|
}
|
|
457
457
|
);
|
|
458
|
-
if (M(
|
|
459
|
-
return new
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
464
|
-
const
|
|
465
|
-
start(
|
|
466
|
-
|
|
458
|
+
if (M(f))
|
|
459
|
+
return new r(null, { status: 202 });
|
|
460
|
+
const N = j && h && typeof h == "object" && "sessionId" in h ? h.sessionId : void 0, x = {};
|
|
461
|
+
N && (x[k] = N);
|
|
462
|
+
const b = K(f.id ?? null, h);
|
|
463
|
+
if (C) {
|
|
464
|
+
const p = new TextEncoder(), O = T(), H = new ReadableStream({
|
|
465
|
+
start(g) {
|
|
466
|
+
g.enqueue(p.encode(`id: ${O}
|
|
467
467
|
|
|
468
|
-
`)),
|
|
468
|
+
`)), g.enqueue(p.encode(A(b, O))), g.close();
|
|
469
469
|
}
|
|
470
|
-
}),
|
|
470
|
+
}), w = new Headers({
|
|
471
471
|
"Content-Type": "text/event-stream",
|
|
472
472
|
"Cache-Control": "no-cache",
|
|
473
473
|
Connection: "keep-alive",
|
|
474
|
-
...
|
|
474
|
+
...x
|
|
475
475
|
});
|
|
476
476
|
if (s) {
|
|
477
|
-
const
|
|
478
|
-
Object.entries(
|
|
477
|
+
const g = m(t, s);
|
|
478
|
+
Object.entries(g).forEach(([v, P]) => w.set(v, P));
|
|
479
479
|
}
|
|
480
|
-
return new
|
|
480
|
+
return new r(H, { status: 200, headers: w });
|
|
481
481
|
}
|
|
482
|
-
return
|
|
483
|
-
} catch (
|
|
484
|
-
if (M(
|
|
485
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js MCP notification processing error:",
|
|
486
|
-
process.env.NODE_ENV !== "test" && console.error("Next.js MCP RPC handler error:",
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
489
|
-
const
|
|
490
|
-
start(
|
|
491
|
-
|
|
482
|
+
return S(b, 200, x);
|
|
483
|
+
} catch (h) {
|
|
484
|
+
if (M(f))
|
|
485
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js MCP notification processing error:", h), new r(null, { status: 202 });
|
|
486
|
+
process.env.NODE_ENV !== "test" && console.error("Next.js MCP RPC handler error:", h);
|
|
487
|
+
const N = h?.code ?? -32603, x = h?.data, b = h.message || "MCP request failed", p = R(f.id ?? null, N, b, x);
|
|
488
|
+
if (C) {
|
|
489
|
+
const O = new TextEncoder(), H = T(), w = new ReadableStream({
|
|
490
|
+
start(v) {
|
|
491
|
+
v.enqueue(O.encode(`id: ${H}
|
|
492
492
|
|
|
493
|
-
`)),
|
|
493
|
+
`)), v.enqueue(O.encode(A(p, H))), v.close();
|
|
494
494
|
}
|
|
495
|
-
}),
|
|
495
|
+
}), g = new Headers({
|
|
496
496
|
"Content-Type": "text/event-stream",
|
|
497
497
|
"Cache-Control": "no-cache",
|
|
498
498
|
Connection: "keep-alive"
|
|
499
499
|
});
|
|
500
500
|
if (s) {
|
|
501
|
-
const
|
|
502
|
-
Object.entries(
|
|
501
|
+
const v = m(t, s);
|
|
502
|
+
Object.entries(v).forEach(([P, L]) => g.set(P, L));
|
|
503
503
|
}
|
|
504
|
-
return new
|
|
504
|
+
return new r(w, { status: 200, headers: g });
|
|
505
505
|
}
|
|
506
|
-
return
|
|
506
|
+
return S(p, 200);
|
|
507
507
|
}
|
|
508
508
|
};
|
|
509
509
|
}
|
|
@@ -511,74 +511,77 @@ function oe(n) {
|
|
|
511
511
|
const { extractSecurityContext: a, cors: s, agent: c } = n;
|
|
512
512
|
if (!c)
|
|
513
513
|
throw new Error("agent config is required for createAgentChatHandler");
|
|
514
|
-
const d =
|
|
515
|
-
return async function(
|
|
514
|
+
const d = E(n);
|
|
515
|
+
return async function(t, e) {
|
|
516
516
|
try {
|
|
517
|
-
if (
|
|
518
|
-
return
|
|
517
|
+
if (t.method !== "POST")
|
|
518
|
+
return r.json(
|
|
519
519
|
{ error: "Method not allowed - use POST" },
|
|
520
520
|
{ status: 405 }
|
|
521
521
|
);
|
|
522
|
-
const { handleAgentChat:
|
|
523
|
-
if (!
|
|
524
|
-
return
|
|
522
|
+
const { handleAgentChat: l } = await import("../handler-9Rdn7zM2.js"), y = await t.json(), { message: u, sessionId: f, history: C } = y;
|
|
523
|
+
if (!u || typeof u != "string")
|
|
524
|
+
return r.json(
|
|
525
525
|
{ error: "message is required and must be a string" },
|
|
526
526
|
{ status: 400 }
|
|
527
527
|
);
|
|
528
|
-
let
|
|
528
|
+
let j = (c.apiKey || "").trim();
|
|
529
529
|
if (c.allowClientApiKey) {
|
|
530
|
-
const
|
|
531
|
-
|
|
530
|
+
const w = t.headers.get("x-agent-api-key");
|
|
531
|
+
w && (j = w.trim());
|
|
532
532
|
}
|
|
533
|
-
if (!
|
|
534
|
-
return
|
|
533
|
+
if (!j)
|
|
534
|
+
return r.json(
|
|
535
535
|
{ error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header." },
|
|
536
536
|
{ status: 401 }
|
|
537
537
|
);
|
|
538
|
-
const
|
|
539
|
-
async start(
|
|
538
|
+
const S = c.allowClientApiKey && t.headers.get("x-agent-provider") || void 0, h = c.allowClientApiKey && t.headers.get("x-agent-model") || void 0, N = c.allowClientApiKey && t.headers.get("x-agent-provider-endpoint") || void 0, x = await a(t, e), b = c.buildSystemContext?.(x), p = new TextEncoder(), O = new ReadableStream({
|
|
539
|
+
async start(w) {
|
|
540
540
|
try {
|
|
541
|
-
const g =
|
|
542
|
-
message:
|
|
543
|
-
sessionId:
|
|
544
|
-
history:
|
|
541
|
+
const g = l({
|
|
542
|
+
message: u,
|
|
543
|
+
sessionId: f,
|
|
544
|
+
history: C,
|
|
545
545
|
semanticLayer: d,
|
|
546
|
-
securityContext:
|
|
546
|
+
securityContext: x,
|
|
547
547
|
agentConfig: c,
|
|
548
|
-
apiKey:
|
|
549
|
-
systemContext:
|
|
548
|
+
apiKey: j,
|
|
549
|
+
systemContext: b,
|
|
550
|
+
providerOverride: S,
|
|
551
|
+
modelOverride: h,
|
|
552
|
+
baseURLOverride: N
|
|
550
553
|
});
|
|
551
|
-
for await (const
|
|
552
|
-
const
|
|
554
|
+
for await (const v of g) {
|
|
555
|
+
const P = `data: ${JSON.stringify(v)}
|
|
553
556
|
|
|
554
557
|
`;
|
|
555
|
-
|
|
558
|
+
w.enqueue(p.encode(P));
|
|
556
559
|
}
|
|
557
560
|
} catch (g) {
|
|
558
|
-
const
|
|
561
|
+
const v = {
|
|
559
562
|
type: "error",
|
|
560
563
|
data: { message: g instanceof Error ? g.message : "Stream failed" }
|
|
561
564
|
};
|
|
562
|
-
|
|
565
|
+
w.enqueue(p.encode(`data: ${JSON.stringify(v)}
|
|
563
566
|
|
|
564
567
|
`));
|
|
565
568
|
} finally {
|
|
566
|
-
|
|
569
|
+
w.close();
|
|
567
570
|
}
|
|
568
571
|
}
|
|
569
|
-
}),
|
|
572
|
+
}), H = new Headers({
|
|
570
573
|
"Content-Type": "text/event-stream",
|
|
571
574
|
"Cache-Control": "no-cache",
|
|
572
575
|
Connection: "keep-alive"
|
|
573
576
|
});
|
|
574
577
|
if (s) {
|
|
575
|
-
const
|
|
576
|
-
Object.entries(
|
|
578
|
+
const w = m(t, s);
|
|
579
|
+
Object.entries(w).forEach(([g, v]) => H.set(g, v));
|
|
577
580
|
}
|
|
578
|
-
return new Response(
|
|
579
|
-
} catch (
|
|
580
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js agent chat handler error:",
|
|
581
|
-
{ error:
|
|
581
|
+
return new Response(O, { status: 200, headers: H });
|
|
582
|
+
} catch (l) {
|
|
583
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js agent chat handler error:", l), r.json(
|
|
584
|
+
{ error: l instanceof Error ? l.message : "Agent chat failed" },
|
|
582
585
|
{ status: 500 }
|
|
583
586
|
);
|
|
584
587
|
}
|
|
@@ -599,14 +602,14 @@ export {
|
|
|
599
602
|
oe as createAgentChatHandler,
|
|
600
603
|
ne as createBatchHandler,
|
|
601
604
|
me as createCubeHandlers,
|
|
602
|
-
|
|
605
|
+
ue as createDiscoverHandler,
|
|
603
606
|
re as createDryRunHandler,
|
|
604
607
|
se as createExplainHandler,
|
|
605
608
|
Z as createLoadHandler,
|
|
606
609
|
he as createMcpLoadHandler,
|
|
607
610
|
ae as createMcpRpcHandler,
|
|
608
611
|
ee as createMetaHandler,
|
|
609
|
-
|
|
612
|
+
le as createOptionsHandler,
|
|
610
613
|
te as createSqlHandler,
|
|
611
614
|
fe as createSuggestHandler,
|
|
612
615
|
ye as createValidateHandler
|