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.
Files changed (42) hide show
  1. package/dist/adapters/anthropic-BTkjgFpT.cjs +1 -0
  2. package/dist/adapters/anthropic-CTu9E801.js +126 -0
  3. package/dist/adapters/express/index.cjs +6 -6
  4. package/dist/adapters/express/index.js +73 -69
  5. package/dist/adapters/fastify/index.cjs +6 -6
  6. package/dist/adapters/fastify/index.js +133 -129
  7. package/dist/adapters/google-BAK9pnQf.cjs +2 -0
  8. package/dist/adapters/google-DficVAsJ.js +146 -0
  9. package/dist/adapters/{handler-BV4JuWNW.js → handler-9Rdn7zM2.js} +537 -457
  10. package/dist/adapters/handler-B-tEntiU.cjs +39 -0
  11. package/dist/adapters/hono/index.cjs +6 -6
  12. package/dist/adapters/hono/index.js +199 -195
  13. package/dist/adapters/index-BIMhF5KZ.cjs +23 -0
  14. package/dist/adapters/index-BgCeQBuN.cjs +2 -0
  15. package/dist/adapters/index-C45_meK_.js +719 -0
  16. package/dist/adapters/index-CFEJ62GJ.js +5337 -0
  17. package/dist/adapters/nextjs/index.cjs +5 -5
  18. package/dist/adapters/nextjs/index.js +215 -211
  19. package/dist/adapters/openai-CUSRuKTk.js +131 -0
  20. package/dist/adapters/openai-mLo2MCat.cjs +1 -0
  21. package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +3 -0
  22. package/dist/client/components/AgenticNotebook/index.d.ts +6 -0
  23. package/dist/client/hooks/useAgentChat.d.ts +6 -0
  24. package/dist/client/index.js +730 -697
  25. package/dist/client/index.js.map +1 -1
  26. package/dist/client/styles.css +1 -1
  27. package/dist/client-bundle-stats.html +1 -1
  28. package/dist/server/anthropic-BTkjgFpT.cjs +1 -0
  29. package/dist/server/anthropic-CTu9E801.js +126 -0
  30. package/dist/server/google-BAK9pnQf.cjs +2 -0
  31. package/dist/server/google-DficVAsJ.js +146 -0
  32. package/dist/server/index-BIMhF5KZ.cjs +23 -0
  33. package/dist/server/index-BgCeQBuN.cjs +2 -0
  34. package/dist/server/index-C45_meK_.js +719 -0
  35. package/dist/server/index-CFEJ62GJ.js +5337 -0
  36. package/dist/server/index.cjs +51 -45
  37. package/dist/server/index.d.ts +49 -10
  38. package/dist/server/index.js +1978 -1898
  39. package/dist/server/openai-CUSRuKTk.js +131 -0
  40. package/dist/server/openai-mLo2MCat.cjs +1 -0
  41. package/package.json +12 -2
  42. package/dist/adapters/handler-D4MVKkVy.cjs +0 -33
@@ -1,27 +1,27 @@
1
- import { NextResponse as t } from "next/server";
2
- import { e as T, s as A, v as D, b as P, a as _, n as Q, p as V, w as I, d as J, i as M, M as k, c as $, S as K } from "../mcp-transport-m1X1GtwG.js";
3
- import { formatErrorResponse as i, formatCubeResponse as z, formatMetaResponse as G, formatSqlResponse as U, handleDryRun as q, handleBatchRequest as B, handleDiscover as F, handleSuggest as X, handleValidate as W, handleLoad as Y } from "../utils.js";
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 r = new K({
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
- r.registerCube(e);
16
- }), r;
15
+ t.registerCube(e);
16
+ }), t;
17
17
  }
18
- function g(n, a) {
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 ue(n) {
22
+ function le(n) {
23
23
  return async function(s) {
24
- const c = g(s, n);
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, r) {
33
+ return async function(o, t) {
34
34
  try {
35
35
  let e;
36
36
  if (o.method === "POST") {
37
- const p = await o.json();
38
- e = p.query || p;
37
+ const j = await o.json();
38
+ e = j.query || j;
39
39
  } else if (o.method === "GET") {
40
- const p = o.nextUrl.searchParams.get("query");
41
- if (!p)
42
- return t.json(
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(p);
47
+ e = JSON.parse(j);
48
48
  } catch {
49
- return t.json(
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 t.json(
55
+ return r.json(
56
56
  i("Method not allowed", 405),
57
57
  { status: 405 }
58
58
  );
59
- const u = await a(o, r), y = c.validateQuery(e);
59
+ const l = await a(o, t), y = c.validateQuery(e);
60
60
  if (!y.isValid)
61
- return t.json(
61
+ return r.json(
62
62
  i(`Query validation failed: ${y.errors.join(", ")}`, 400),
63
63
  { status: 400 }
64
64
  );
65
- const l = o.headers.get("x-cache-control") === "no-cache", f = await c.executeMultiCubeQuery(e, u, { skipCache: l }), v = z(e, f, c);
66
- return t.json(v, {
67
- headers: s ? g(o, 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), t.json(
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 r = s.getMetadata(), e = G(r);
85
- return t.json(e, {
86
- headers: a ? g(d, a) : {}
84
+ const t = s.getMetadata(), e = U(t);
85
+ return r.json(e, {
86
+ headers: a ? m(d, a) : {}
87
87
  });
88
- } catch (r) {
89
- return process.env.NODE_ENV !== "test" && console.error("Next.js meta handler error:", r), t.json(
88
+ } catch (t) {
89
+ return process.env.NODE_ENV !== "test" && console.error("Next.js meta handler error:", t), r.json(
90
90
  i(
91
- r instanceof Error ? r.message : "Failed to fetch metadata",
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, r) {
101
+ return async function(o, t) {
102
102
  try {
103
103
  let e;
104
104
  if (o.method === "POST") {
105
- const C = await o.json();
106
- e = C.query || C;
105
+ const S = await o.json();
106
+ e = S.query || S;
107
107
  } else if (o.method === "GET") {
108
- const C = o.nextUrl.searchParams.get("query");
109
- if (!C)
110
- return t.json(
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(C);
115
+ e = JSON.parse(S);
116
116
  } catch {
117
- return t.json(
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 t.json(
123
+ return r.json(
124
124
  i("Method not allowed", 405),
125
125
  { status: 405 }
126
126
  );
127
- const u = await a(o, r), y = c.validateQuery(e);
127
+ const l = await a(o, t), y = c.validateQuery(e);
128
128
  if (!y.isValid)
129
- return t.json(
129
+ return r.json(
130
130
  i(`Query validation failed: ${y.errors.join(", ")}`, 400),
131
131
  { status: 400 }
132
132
  );
133
- const l = e.measures?.[0] || e.dimensions?.[0];
134
- if (!l)
135
- return t.json(
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 = l.split(".")[0], v = await c.generateSQL(f, e, u), p = U(e, v);
140
- return t.json(p, {
141
- headers: s ? g(o, 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), t.json(
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, r) {
156
+ return async function(o, t) {
157
157
  try {
158
158
  let e;
159
159
  if (o.method === "POST") {
160
- const l = await o.json();
161
- e = l.query || l;
160
+ const u = await o.json();
161
+ e = u.query || u;
162
162
  } else if (o.method === "GET") {
163
- const l = o.nextUrl.searchParams.get("query");
164
- if (!l)
165
- return t.json(
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(l);
170
+ e = JSON.parse(u);
171
171
  } catch {
172
- return t.json(
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 t.json(
178
+ return r.json(
179
179
  { error: "Method not allowed", valid: !1 },
180
180
  { status: 405 }
181
181
  );
182
- const u = await a(o, r), y = await q(e, u, c);
183
- return t.json(y, {
184
- headers: s ? g(o, 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), t.json(
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, r) {
199
+ return async function(o, t) {
200
200
  try {
201
201
  if (o.method !== "POST")
202
- return t.json(
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: u } = e;
207
- if (!u || !Array.isArray(u))
208
- return t.json(
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 (u.length === 0)
213
- return t.json(
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, r), l = o.headers.get("x-cache-control") === "no-cache", f = await B(u, y, c, { skipCache: l });
218
- return t.json(f, {
219
- headers: s ? g(o, 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), t.json(
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, r) {
234
+ return async function(o, t) {
235
235
  try {
236
236
  if (o.method !== "POST")
237
- return t.json(
237
+ return r.json(
238
238
  { error: "Method not allowed" },
239
239
  { status: 405 }
240
240
  );
241
- const e = await o.json(), u = e.query || e, y = e.options || {}, l = await a(o, r), f = c.validateQuery(u);
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 t.json(
243
+ return r.json(
244
244
  { error: `Query validation failed: ${f.errors.join(", ")}` },
245
245
  { status: 400 }
246
246
  );
247
- const v = await c.explainQuery(
248
- u,
247
+ const C = await c.explainQuery(
249
248
  l,
249
+ u,
250
250
  y
251
251
  );
252
- return t.json(v, {
253
- headers: s ? g(o, 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), t.json(
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 le(n) {
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 t.json(
268
+ return r.json(
269
269
  i("Method not allowed - use POST", 405),
270
270
  { status: 405 }
271
271
  );
272
- const r = await d.json(), e = await F(s, r);
273
- return t.json(e, {
274
- headers: a ? g(d, 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 (r) {
277
- return process.env.NODE_ENV !== "test" && console.error("Next.js discover handler error:", r), t.json(
276
+ } catch (t) {
277
+ return process.env.NODE_ENV !== "test" && console.error("Next.js discover handler error:", t), r.json(
278
278
  i(
279
- r instanceof Error ? r.message : "Discovery failed",
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 t.json(
292
+ return r.json(
293
293
  i("Method not allowed - use POST", 405),
294
294
  { status: 405 }
295
295
  );
296
- const r = await d.json();
297
- if (!r.naturalLanguage)
298
- return t.json(
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 X(s, r);
303
- return t.json(e, {
304
- headers: a ? g(d, a) : {}
302
+ const e = await q(s, t);
303
+ return r.json(e, {
304
+ headers: a ? m(d, a) : {}
305
305
  });
306
- } catch (r) {
307
- return process.env.NODE_ENV !== "test" && console.error("Next.js suggest handler error:", r), t.json(
306
+ } catch (t) {
307
+ return process.env.NODE_ENV !== "test" && console.error("Next.js suggest handler error:", t), r.json(
308
308
  i(
309
- r instanceof Error ? r.message : "Query suggestion failed",
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 t.json(
322
+ return r.json(
323
323
  i("Method not allowed - use POST", 405),
324
324
  { status: 405 }
325
325
  );
326
- const r = await d.json();
327
- if (!r.query)
328
- return t.json(
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, r);
333
- return t.json(e, {
334
- headers: a ? g(d, a) : {}
332
+ const e = await W(s, t);
333
+ return r.json(e, {
334
+ headers: a ? m(d, a) : {}
335
335
  });
336
- } catch (r) {
337
- return process.env.NODE_ENV !== "test" && console.error("Next.js validate handler error:", r), t.json(
336
+ } catch (t) {
337
+ return process.env.NODE_ENV !== "test" && console.error("Next.js validate handler error:", t), r.json(
338
338
  i(
339
- r instanceof Error ? r.message : "Query validation failed",
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, r) {
349
+ return async function(o, t) {
350
350
  try {
351
351
  if (o.method !== "POST")
352
- return t.json(
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 t.json(
358
+ return r.json(
359
359
  i("query field is required", 400),
360
360
  { status: 400 }
361
361
  );
362
- const u = await a(o, r), y = await Y(c, u, e);
363
- return t.json(y, {
364
- headers: s ? g(o, 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), t.json(
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(r) {
380
- if (r.method === "DELETE")
381
- return t.json(
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 (r.method === "GET") {
386
- const h = new TextEncoder(), S = T(), x = new ReadableStream({
387
- start(m) {
388
- m.enqueue(h.encode(A({
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
- }, S, 15e3)));
392
+ }, N, 15e3)));
393
393
  }
394
- }), j = new Headers({
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 m = g(r, s);
401
- Object.entries(m).forEach(([w, N]) => j.set(w, N));
400
+ const p = m(t, s);
401
+ Object.entries(p).forEach(([O, H]) => b.set(O, H));
402
402
  }
403
- return new t(x, { status: 200, headers: j });
403
+ return new r(x, { status: 200, headers: b });
404
404
  }
405
- if (r.method !== "POST")
406
- return t.json(
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
- r.headers.get("origin"),
411
+ t.headers.get("origin"),
412
412
  c.allowedOrigins ? { allowedOrigins: c.allowedOrigins } : {}
413
413
  );
414
414
  if (!e.valid)
415
- return t.json(
416
- P(null, -32600, e.reason),
415
+ return r.json(
416
+ R(null, -32600, e.reason),
417
417
  { status: 403 }
418
418
  );
419
- const u = r.headers.get("accept");
420
- if (!_(u))
421
- return t.json(
422
- P(null, -32600, "Accept header must include both application/json and text/event-stream"),
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(r.headers.entries()));
425
+ const y = Q(Object.fromEntries(t.headers.entries()));
426
426
  if (!y.ok)
427
- return t.json({
427
+ return r.json({
428
428
  error: "Unsupported MCP protocol version",
429
429
  supported: y.supported
430
430
  }, { status: 426 });
431
- let l;
431
+ let u;
432
432
  try {
433
- l = await r.json();
433
+ u = await t.json();
434
434
  } catch {
435
- l = null;
435
+ u = null;
436
436
  }
437
- const f = V(l);
437
+ const f = V(u);
438
438
  if (!f)
439
- return t.json(
440
- P(null, -32600, "Invalid JSON-RPC 2.0 request"),
439
+ return r.json(
440
+ R(null, -32600, "Invalid JSON-RPC 2.0 request"),
441
441
  { status: 400 }
442
442
  );
443
- const v = I(u), p = f.method === "initialize", C = (h, S = 200, x = {}) => t.json(h, {
444
- status: S,
445
- headers: { ...s ? g(r, s) : {}, ...x }
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: (m) => a(m),
454
- rawRequest: r,
453
+ extractSecurityContext: (p) => a(p),
454
+ rawRequest: t,
455
455
  rawResponse: null
456
456
  }
457
457
  );
458
458
  if (M(f))
459
- return new t(null, { status: 202 });
460
- const S = p && h && typeof h == "object" && "sessionId" in h ? h.sessionId : void 0, x = {};
461
- S && (x[k] = S);
462
- const j = $(f.id ?? null, h);
463
- if (v) {
464
- const m = new TextEncoder(), w = T(), N = new ReadableStream({
465
- start(b) {
466
- b.enqueue(m.encode(`id: ${w}
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
- `)), b.enqueue(m.encode(A(j, w))), b.close();
468
+ `)), g.enqueue(p.encode(A(b, O))), g.close();
469
469
  }
470
- }), O = new Headers({
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 b = g(r, s);
478
- Object.entries(b).forEach(([H, R]) => O.set(H, R));
477
+ const g = m(t, s);
478
+ Object.entries(g).forEach(([v, P]) => w.set(v, P));
479
479
  }
480
- return new t(N, { status: 200, headers: O });
480
+ return new r(H, { status: 200, headers: w });
481
481
  }
482
- return C(j, 200, x);
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 t(null, { status: 202 });
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 S = h?.code ?? -32603, x = h?.data, j = h.message || "MCP request failed", m = P(f.id ?? null, S, j, x);
488
- if (v) {
489
- const w = new TextEncoder(), N = T(), O = new ReadableStream({
490
- start(H) {
491
- H.enqueue(w.encode(`id: ${N}
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
- `)), H.enqueue(w.encode(A(m, N))), H.close();
493
+ `)), v.enqueue(O.encode(A(p, H))), v.close();
494
494
  }
495
- }), b = new Headers({
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 H = g(r, s);
502
- Object.entries(H).forEach(([R, L]) => b.set(R, L));
501
+ const v = m(t, s);
502
+ Object.entries(v).forEach(([P, L]) => g.set(P, L));
503
503
  }
504
- return new t(O, { status: 200, headers: b });
504
+ return new r(w, { status: 200, headers: g });
505
505
  }
506
- return C(m, 200);
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(r, e) {
515
+ return async function(t, e) {
516
516
  try {
517
- if (r.method !== "POST")
518
- return t.json(
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: u } = await import("../handler-BV4JuWNW.js"), y = await r.json(), { message: l, sessionId: f, history: v } = y;
523
- if (!l || typeof l != "string")
524
- return t.json(
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 p = (c.apiKey || "").trim();
528
+ let j = (c.apiKey || "").trim();
529
529
  if (c.allowClientApiKey) {
530
- const j = r.headers.get("x-agent-api-key");
531
- j && (p = j.trim());
530
+ const w = t.headers.get("x-agent-api-key");
531
+ w && (j = w.trim());
532
532
  }
533
- if (!p)
534
- return t.json(
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 C = await a(r, e), h = new TextEncoder(), S = new ReadableStream({
539
- async start(j) {
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 m = u({
542
- message: l,
541
+ const g = l({
542
+ message: u,
543
543
  sessionId: f,
544
- history: v,
544
+ history: C,
545
545
  semanticLayer: d,
546
- securityContext: C,
546
+ securityContext: x,
547
547
  agentConfig: c,
548
- apiKey: p
548
+ apiKey: j,
549
+ systemContext: b,
550
+ providerOverride: S,
551
+ modelOverride: h,
552
+ baseURLOverride: N
549
553
  });
550
- for await (const w of m) {
551
- const N = `data: ${JSON.stringify(w)}
554
+ for await (const v of g) {
555
+ const P = `data: ${JSON.stringify(v)}
552
556
 
553
557
  `;
554
- j.enqueue(h.encode(N));
558
+ w.enqueue(p.encode(P));
555
559
  }
556
- } catch (m) {
557
- const w = {
560
+ } catch (g) {
561
+ const v = {
558
562
  type: "error",
559
- data: { message: m instanceof Error ? m.message : "Stream failed" }
563
+ data: { message: g instanceof Error ? g.message : "Stream failed" }
560
564
  };
561
- j.enqueue(h.encode(`data: ${JSON.stringify(w)}
565
+ w.enqueue(p.encode(`data: ${JSON.stringify(v)}
562
566
 
563
567
  `));
564
568
  } finally {
565
- j.close();
569
+ w.close();
566
570
  }
567
571
  }
568
- }), x = new Headers({
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 j = g(r, s);
575
- Object.entries(j).forEach(([m, w]) => x.set(m, w));
578
+ const w = m(t, s);
579
+ Object.entries(w).forEach(([g, v]) => H.set(g, v));
576
580
  }
577
- return new Response(S, { status: 200, headers: x });
578
- } catch (u) {
579
- return process.env.NODE_ENV !== "test" && console.error("Next.js agent chat handler error:", u), t.json(
580
- { error: u instanceof Error ? u.message : "Agent chat failed" },
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
- le as createDiscoverHandler,
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
- ue as createOptionsHandler,
612
+ le as createOptionsHandler,
609
613
  te as createSqlHandler,
610
614
  fe as createSuggestHandler,
611
615
  ye as createValidateHandler