drizzle-cube 0.4.19 → 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 +73 -69
- package/dist/adapters/fastify/index.cjs +6 -6
- package/dist/adapters/fastify/index.js +133 -129
- package/dist/adapters/google-BAK9pnQf.cjs +2 -0
- package/dist/adapters/google-DficVAsJ.js +146 -0
- package/dist/adapters/{handler-BV4JuWNW.js → handler-9Rdn7zM2.js} +537 -457
- package/dist/adapters/handler-B-tEntiU.cjs +39 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +199 -195
- 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 +215 -211
- 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 +51 -45
- package/dist/server/index.d.ts +49 -10
- package/dist/server/index.js +1978 -1898
- 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-D4MVKkVy.cjs +0 -33
|
@@ -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
|
|
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
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
|
|
@@ -30,44 +30,44 @@ function ue(n) {
|
|
|
30
30
|
}
|
|
31
31
|
function Z(n) {
|
|
32
32
|
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
33
|
-
return async function(o,
|
|
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
|
|
59
|
+
const l = await a(o, t), y = c.validateQuery(e);
|
|
60
60
|
if (!y.isValid)
|
|
61
|
-
return
|
|
61
|
+
return r.json(
|
|
62
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
|
|
@@ -81,14 +81,14 @@ function ee(n) {
|
|
|
81
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 }
|
|
@@ -98,50 +98,50 @@ function ee(n) {
|
|
|
98
98
|
}
|
|
99
99
|
function te(n) {
|
|
100
100
|
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
101
|
-
return async function(o,
|
|
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
|
|
127
|
+
const l = await a(o, t), y = c.validateQuery(e);
|
|
128
128
|
if (!y.isValid)
|
|
129
|
-
return
|
|
129
|
+
return r.json(
|
|
130
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 f =
|
|
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
|
|
@@ -153,38 +153,38 @@ function te(n) {
|
|
|
153
153
|
}
|
|
154
154
|
function re(n) {
|
|
155
155
|
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
156
|
-
return async function(o,
|
|
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
|
|
@@ -196,30 +196,30 @@ function re(n) {
|
|
|
196
196
|
}
|
|
197
197
|
function ne(n) {
|
|
198
198
|
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
199
|
-
return async function(o,
|
|
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 y = await a(o,
|
|
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
|
|
@@ -231,52 +231,52 @@ function ne(n) {
|
|
|
231
231
|
}
|
|
232
232
|
function se(n) {
|
|
233
233
|
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
234
|
-
return async function(o,
|
|
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(),
|
|
241
|
+
const e = await o.json(), l = e.query || e, y = e.options || {}, u = await a(o, t), f = c.validateQuery(l);
|
|
242
242
|
if (!f.isValid)
|
|
243
|
-
return
|
|
243
|
+
return r.json(
|
|
244
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,
|
|
249
|
+
u,
|
|
250
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
|
|
263
|
+
function ue(n) {
|
|
264
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 }
|
|
@@ -289,24 +289,24 @@ function fe(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 }
|
|
@@ -319,24 +319,24 @@ function ye(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 }
|
|
@@ -346,25 +346,25 @@ function ye(n) {
|
|
|
346
346
|
}
|
|
347
347
|
function he(n) {
|
|
348
348
|
const { extractSecurityContext: a, cors: s } = n, c = E(n);
|
|
349
|
-
return async function(o,
|
|
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
|
|
@@ -376,73 +376,73 @@ function he(n) {
|
|
|
376
376
|
}
|
|
377
377
|
function ae(n) {
|
|
378
378
|
const { extractSecurityContext: a, cors: s, mcp: c = { enabled: !0 } } = n, d = E(n);
|
|
379
|
-
return async function(
|
|
380
|
-
if (
|
|
381
|
-
return
|
|
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 h = new TextEncoder(),
|
|
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 y = Q(Object.fromEntries(
|
|
425
|
+
const y = Q(Object.fromEntries(t.headers.entries()));
|
|
426
426
|
if (!y.ok)
|
|
427
|
-
return
|
|
427
|
+
return r.json({
|
|
428
428
|
error: "Unsupported MCP protocol version",
|
|
429
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 f = V(
|
|
437
|
+
const f = V(u);
|
|
438
438
|
if (!f)
|
|
439
|
-
return
|
|
440
|
-
|
|
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
448
|
const h = await J(
|
|
@@ -450,60 +450,60 @@ function ae(n) {
|
|
|
450
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
458
|
if (M(f))
|
|
459
|
-
return new
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
464
|
-
const
|
|
465
|
-
start(
|
|
466
|
-
|
|
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
|
|
482
|
+
return S(b, 200, x);
|
|
483
483
|
} catch (h) {
|
|
484
484
|
if (M(f))
|
|
485
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js MCP notification processing error:", h), new
|
|
485
|
+
return process.env.NODE_ENV !== "test" && console.error("Next.js MCP notification processing error:", h), new r(null, { status: 202 });
|
|
486
486
|
process.env.NODE_ENV !== "test" && console.error("Next.js MCP RPC handler error:", h);
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
489
|
-
const
|
|
490
|
-
start(
|
|
491
|
-
|
|
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
|
}
|
|
@@ -512,72 +512,76 @@ function oe(n) {
|
|
|
512
512
|
if (!c)
|
|
513
513
|
throw new Error("agent config is required for createAgentChatHandler");
|
|
514
514
|
const d = E(n);
|
|
515
|
-
return async function(
|
|
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
|
|
542
|
-
message:
|
|
541
|
+
const g = l({
|
|
542
|
+
message: u,
|
|
543
543
|
sessionId: f,
|
|
544
|
-
history:
|
|
544
|
+
history: C,
|
|
545
545
|
semanticLayer: d,
|
|
546
|
-
securityContext:
|
|
546
|
+
securityContext: x,
|
|
547
547
|
agentConfig: c,
|
|
548
|
-
apiKey:
|
|
548
|
+
apiKey: j,
|
|
549
|
+
systemContext: b,
|
|
550
|
+
providerOverride: S,
|
|
551
|
+
modelOverride: h,
|
|
552
|
+
baseURLOverride: N
|
|
549
553
|
});
|
|
550
|
-
for await (const
|
|
551
|
-
const
|
|
554
|
+
for await (const v of g) {
|
|
555
|
+
const P = `data: ${JSON.stringify(v)}
|
|
552
556
|
|
|
553
557
|
`;
|
|
554
|
-
|
|
558
|
+
w.enqueue(p.encode(P));
|
|
555
559
|
}
|
|
556
|
-
} catch (
|
|
557
|
-
const
|
|
560
|
+
} catch (g) {
|
|
561
|
+
const v = {
|
|
558
562
|
type: "error",
|
|
559
|
-
data: { message:
|
|
563
|
+
data: { message: g instanceof Error ? g.message : "Stream failed" }
|
|
560
564
|
};
|
|
561
|
-
|
|
565
|
+
w.enqueue(p.encode(`data: ${JSON.stringify(v)}
|
|
562
566
|
|
|
563
567
|
`));
|
|
564
568
|
} finally {
|
|
565
|
-
|
|
569
|
+
w.close();
|
|
566
570
|
}
|
|
567
571
|
}
|
|
568
|
-
}),
|
|
572
|
+
}), H = new Headers({
|
|
569
573
|
"Content-Type": "text/event-stream",
|
|
570
574
|
"Cache-Control": "no-cache",
|
|
571
575
|
Connection: "keep-alive"
|
|
572
576
|
});
|
|
573
577
|
if (s) {
|
|
574
|
-
const
|
|
575
|
-
Object.entries(
|
|
578
|
+
const w = m(t, s);
|
|
579
|
+
Object.entries(w).forEach(([g, v]) => H.set(g, v));
|
|
576
580
|
}
|
|
577
|
-
return new Response(
|
|
578
|
-
} catch (
|
|
579
|
-
return process.env.NODE_ENV !== "test" && console.error("Next.js agent chat handler error:",
|
|
580
|
-
{ 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" },
|
|
581
585
|
{ status: 500 }
|
|
582
586
|
);
|
|
583
587
|
}
|
|
@@ -598,14 +602,14 @@ export {
|
|
|
598
602
|
oe as createAgentChatHandler,
|
|
599
603
|
ne as createBatchHandler,
|
|
600
604
|
me as createCubeHandlers,
|
|
601
|
-
|
|
605
|
+
ue as createDiscoverHandler,
|
|
602
606
|
re as createDryRunHandler,
|
|
603
607
|
se as createExplainHandler,
|
|
604
608
|
Z as createLoadHandler,
|
|
605
609
|
he as createMcpLoadHandler,
|
|
606
610
|
ae as createMcpRpcHandler,
|
|
607
611
|
ee as createMetaHandler,
|
|
608
|
-
|
|
612
|
+
le as createOptionsHandler,
|
|
609
613
|
te as createSqlHandler,
|
|
610
614
|
fe as createSuggestHandler,
|
|
611
615
|
ye as createValidateHandler
|