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,261 +1,265 @@
1
1
  import { Hono as L } from "hono";
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";
2
+ import { S as K, v as V, b as $, a as B, n as z, p as _, w as U, d as F, g as G, f as X, i as I, c as W, M as Y, e as N, s as T } 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 = (C) => {
5
- const y = {
4
+ var re = (j) => {
5
+ const d = {
6
6
  ...{
7
7
  origin: "*",
8
8
  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
9
9
  allowHeaders: [],
10
10
  exposeHeaders: []
11
11
  },
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);
12
+ ...j
13
+ }, M = /* @__PURE__ */ ((l) => typeof l == "string" ? l === "*" ? () => l : (i) => l === i ? i : null : typeof l == "function" ? l : (i) => l.includes(i) ? i : null)(d.origin), m = ((l) => typeof l == "function" ? l : Array.isArray(l) ? () => l : () => [])(d.allowMethods);
14
+ return async function(i, h) {
15
+ function C(p, a) {
16
+ i.res.headers.set(p, a);
17
17
  }
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
- y.origin !== "*" && g("Vary", "Origin"), y.maxAge != null && g("Access-Control-Max-Age", y.maxAge.toString());
21
- const q = await f(i.req.header("origin") || "", i);
22
- q.length && g("Access-Control-Allow-Methods", q.join(","));
23
- let a = y.allowHeaders;
18
+ const b = await M(i.req.header("origin") || "", i);
19
+ if (b && C("Access-Control-Allow-Origin", b), d.credentials && C("Access-Control-Allow-Credentials", "true"), d.exposeHeaders?.length && C("Access-Control-Expose-Headers", d.exposeHeaders.join(",")), i.req.method === "OPTIONS") {
20
+ d.origin !== "*" && C("Vary", "Origin"), d.maxAge != null && C("Access-Control-Max-Age", d.maxAge.toString());
21
+ const p = await m(i.req.header("origin") || "", i);
22
+ p.length && C("Access-Control-Allow-Methods", p.join(","));
23
+ let a = d.allowHeaders;
24
24
  if (!a?.length) {
25
25
  const s = i.req.header("Access-Control-Request-Headers");
26
26
  s && (a = s.split(/\s*,\s*/));
27
27
  }
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, {
28
+ return a?.length && (C("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
29
  headers: i.res.headers,
30
30
  status: 204,
31
31
  statusText: "No Content"
32
32
  });
33
33
  }
34
- await m(), y.origin !== "*" && i.header("Vary", "Origin", { append: !0 });
34
+ await h(), d.origin !== "*" && i.header("Vary", "Origin", { append: !0 });
35
35
  };
36
36
  };
37
- function te(C) {
37
+ function te(j) {
38
38
  const {
39
- cubes: j,
40
- drizzle: y,
41
- schema: H,
42
- extractSecurityContext: f,
39
+ cubes: x,
40
+ drizzle: d,
41
+ schema: M,
42
+ extractSecurityContext: m,
43
43
  engineType: l,
44
44
  cors: i,
45
- basePath: m = "/cubejs-api/v1",
46
- cache: g,
47
- mcp: v = { enabled: !0 },
48
- agent: q
49
- } = C;
50
- if (!j || j.length === 0)
45
+ basePath: h = "/cubejs-api/v1",
46
+ cache: C,
47
+ mcp: b = { enabled: !0 },
48
+ agent: p
49
+ } = j;
50
+ if (!x || x.length === 0)
51
51
  throw new Error("At least one cube must be provided in the cubes array");
52
52
  const a = new L();
53
53
  i && a.use("/*", re(i));
54
- const s = new V({
55
- drizzle: y,
56
- schema: H,
54
+ const s = new K({
55
+ drizzle: d,
56
+ schema: M,
57
57
  engineType: l,
58
- cache: g
58
+ cache: C
59
59
  });
60
- if (j.forEach((r) => {
61
- s.registerCube(r);
62
- }), a.post(`${m}/load`, async (r) => {
60
+ if (x.forEach((e) => {
61
+ s.registerCube(e);
62
+ }), a.post(`${h}/load`, async (e) => {
63
63
  try {
64
- const e = await r.req.json(), n = e.query || e, o = await f(r), t = s.validateQuery(n);
64
+ const r = await e.req.json(), n = r.query || r, o = await m(e), t = s.validateQuery(n);
65
65
  if (!t.isValid)
66
- return r.json({
66
+ return e.json({
67
67
  error: `Query validation failed: ${t.errors.join(", ")}`
68
68
  }, 400);
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
- } catch (e) {
72
- return console.error("Query execution error:", e), r.json({
73
- error: e instanceof Error ? e.message : "Query execution failed"
69
+ const c = e.req.header("x-cache-control") === "no-cache", u = await s.executeMultiCubeQuery(n, o, { skipCache: c });
70
+ return e.json(k(n, u, s));
71
+ } catch (r) {
72
+ return console.error("Query execution error:", r), e.json({
73
+ error: r instanceof Error ? r.message : "Query execution failed"
74
74
  }, 500);
75
75
  }
76
- }), a.get(`${m}/load`, async (r) => {
76
+ }), a.get(`${h}/load`, async (e) => {
77
77
  try {
78
- const e = r.req.query("query");
79
- if (!e)
80
- return r.json({
78
+ const r = e.req.query("query");
79
+ if (!r)
80
+ return e.json({
81
81
  error: "Query parameter is required"
82
82
  }, 400);
83
83
  let n;
84
84
  try {
85
- n = JSON.parse(e);
85
+ n = JSON.parse(r);
86
86
  } catch {
87
- return r.json({
87
+ return e.json({
88
88
  error: "Invalid JSON in query parameter"
89
89
  }, 400);
90
90
  }
91
- const o = await f(r), t = s.validateQuery(n);
91
+ const o = await m(e), t = s.validateQuery(n);
92
92
  if (!t.isValid)
93
- return r.json({
93
+ return e.json({
94
94
  error: `Query validation failed: ${t.errors.join(", ")}`
95
95
  }, 400);
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
- } catch (e) {
99
- return console.error("Query execution error:", e), r.json({
100
- error: e instanceof Error ? e.message : "Query execution failed"
96
+ const c = e.req.header("x-cache-control") === "no-cache", u = await s.executeMultiCubeQuery(n, o, { skipCache: c });
97
+ return e.json(k(n, u, s));
98
+ } catch (r) {
99
+ return console.error("Query execution error:", r), e.json({
100
+ error: r instanceof Error ? r.message : "Query execution failed"
101
101
  }, 500);
102
102
  }
103
- }), a.post(`${m}/batch`, async (r) => {
103
+ }), a.post(`${h}/batch`, async (e) => {
104
104
  try {
105
- const e = await r.req.json(), { queries: n } = e;
105
+ const r = await e.req.json(), { queries: n } = r;
106
106
  if (!n || !Array.isArray(n))
107
- return r.json({
107
+ return e.json({
108
108
  error: 'Request body must contain a "queries" array'
109
109
  }, 400);
110
110
  if (n.length === 0)
111
- return r.json({
111
+ return e.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", c = await Z(n, o, s, { skipCache: t });
115
- return r.json(c);
116
- } catch (e) {
117
- return console.error("Batch execution error:", e), r.json({
118
- error: e instanceof Error ? e.message : "Batch execution failed"
114
+ const o = await m(e), t = e.req.header("x-cache-control") === "no-cache", c = await Z(n, o, s, { skipCache: t });
115
+ return e.json(c);
116
+ } catch (r) {
117
+ return console.error("Batch execution error:", r), e.json({
118
+ error: r instanceof Error ? r.message : "Batch execution failed"
119
119
  }, 500);
120
120
  }
121
- }), a.get(`${m}/meta`, (r) => {
121
+ }), a.get(`${h}/meta`, (e) => {
122
122
  try {
123
- const e = s.getMetadata();
124
- return r.json(ee(e));
125
- } catch (e) {
126
- return console.error("Metadata error:", e), r.json({
127
- error: e instanceof Error ? e.message : "Failed to fetch metadata"
123
+ const r = s.getMetadata();
124
+ return e.json(ee(r));
125
+ } catch (r) {
126
+ return console.error("Metadata error:", r), e.json({
127
+ error: r instanceof Error ? r.message : "Failed to fetch metadata"
128
128
  }, 500);
129
129
  }
130
- }), a.post(`${m}/sql`, async (r) => {
130
+ }), a.post(`${h}/sql`, async (e) => {
131
131
  try {
132
- const e = await r.req.json(), n = await f(r), o = s.validateQuery(e);
132
+ const r = await e.req.json(), n = await m(e), o = s.validateQuery(r);
133
133
  if (!o.isValid)
134
- return r.json({
134
+ return e.json({
135
135
  error: `Query validation failed: ${o.errors.join(", ")}`
136
136
  }, 400);
137
- const t = e.measures?.[0] || e.dimensions?.[0];
137
+ const t = r.measures?.[0] || r.dimensions?.[0];
138
138
  if (!t)
139
- return r.json({
139
+ return e.json({
140
140
  error: "No measures or dimensions specified"
141
141
  }, 400);
142
- const c = t.split(".")[0], u = await s.generateSQL(c, e, n);
143
- return r.json(D(e, u));
144
- } catch (e) {
145
- return console.error("SQL generation error:", e), r.json({
146
- error: e instanceof Error ? e.message : "SQL generation failed"
142
+ const c = t.split(".")[0], u = await s.generateSQL(c, r, n);
143
+ return e.json(D(r, u));
144
+ } catch (r) {
145
+ return console.error("SQL generation error:", r), e.json({
146
+ error: r instanceof Error ? r.message : "SQL generation failed"
147
147
  }, 500);
148
148
  }
149
- }), a.get(`${m}/sql`, async (r) => {
149
+ }), a.get(`${h}/sql`, async (e) => {
150
150
  try {
151
- const e = r.req.query("query");
152
- if (!e)
153
- return r.json({
151
+ const r = e.req.query("query");
152
+ if (!r)
153
+ return e.json({
154
154
  error: "Query parameter is required"
155
155
  }, 400);
156
- const n = JSON.parse(e), o = await f(r), t = s.validateQuery(n);
156
+ const n = JSON.parse(r), o = await m(e), t = s.validateQuery(n);
157
157
  if (!t.isValid)
158
- return r.json({
158
+ return e.json({
159
159
  error: `Query validation failed: ${t.errors.join(", ")}`
160
160
  }, 400);
161
161
  const c = n.measures?.[0] || n.dimensions?.[0];
162
162
  if (!c)
163
- return r.json({
163
+ return e.json({
164
164
  error: "No measures or dimensions specified"
165
165
  }, 400);
166
- const u = c.split(".")[0], h = await s.generateSQL(u, n, o);
167
- return r.json(D(n, h));
168
- } catch (e) {
169
- return console.error("SQL generation error:", e), r.json({
170
- error: e instanceof Error ? e.message : "SQL generation failed"
166
+ const u = c.split(".")[0], q = await s.generateSQL(u, n, o);
167
+ return e.json(D(n, q));
168
+ } catch (r) {
169
+ return console.error("SQL generation error:", r), e.json({
170
+ error: r instanceof Error ? r.message : "SQL generation failed"
171
171
  }, 500);
172
172
  }
173
- }), a.post(`${m}/dry-run`, async (r) => {
173
+ }), a.post(`${h}/dry-run`, async (e) => {
174
174
  try {
175
- const e = await r.req.json(), n = e.query || e, o = await f(r), t = await J(n, o, s);
176
- return r.json(t);
177
- } catch (e) {
178
- return console.error("Dry-run error:", e), r.json({
179
- error: e instanceof Error ? e.message : "Dry-run validation failed",
175
+ const r = await e.req.json(), n = r.query || r, o = await m(e), t = await J(n, o, s);
176
+ return e.json(t);
177
+ } catch (r) {
178
+ return console.error("Dry-run error:", r), e.json({
179
+ error: r instanceof Error ? r.message : "Dry-run validation failed",
180
180
  valid: !1
181
181
  }, 400);
182
182
  }
183
- }), a.get(`${m}/dry-run`, async (r) => {
183
+ }), a.get(`${h}/dry-run`, async (e) => {
184
184
  try {
185
- const e = r.req.query("query");
186
- if (!e)
187
- return r.json({
185
+ const r = e.req.query("query");
186
+ if (!r)
187
+ return e.json({
188
188
  error: "Query parameter is required",
189
189
  valid: !1
190
190
  }, 400);
191
- const n = JSON.parse(e), o = await f(r), t = await J(n, o, s);
192
- return r.json(t);
193
- } catch (e) {
194
- return console.error("Dry-run error:", e), r.json({
195
- error: e instanceof Error ? e.message : "Dry-run validation failed",
191
+ const n = JSON.parse(r), o = await m(e), t = await J(n, o, s);
192
+ return e.json(t);
193
+ } catch (r) {
194
+ return console.error("Dry-run error:", r), e.json({
195
+ error: r instanceof Error ? r.message : "Dry-run validation failed",
196
196
  valid: !1
197
197
  }, 400);
198
198
  }
199
- }), a.post(`${m}/explain`, async (r) => {
199
+ }), a.post(`${h}/explain`, async (e) => {
200
200
  try {
201
- const e = await r.req.json(), n = e.query || e, o = e.options || {}, t = await f(r), c = s.validateQuery(n);
201
+ const r = await e.req.json(), n = r.query || r, o = r.options || {}, t = await m(e), c = s.validateQuery(n);
202
202
  if (!c.isValid)
203
- return r.json({
203
+ return e.json({
204
204
  error: `Query validation failed: ${c.errors.join(", ")}`
205
205
  }, 400);
206
206
  const u = await s.explainQuery(n, t, o);
207
- return r.json(u);
208
- } catch (e) {
209
- return console.error("Explain error:", e), r.json({
210
- error: e instanceof Error ? e.message : "Explain query failed"
207
+ return e.json(u);
208
+ } catch (r) {
209
+ return console.error("Explain error:", r), e.json({
210
+ error: r instanceof Error ? r.message : "Explain query failed"
211
211
  }, 500);
212
212
  }
213
- }), q && a.post(`${m}/agent/chat`, async (r) => {
213
+ }), p && a.post(`${h}/agent/chat`, async (e) => {
214
214
  try {
215
- const { handleAgentChat: e } = await import("../handler-BV4JuWNW.js"), n = await r.req.json(), { message: o, sessionId: t, history: c } = n;
215
+ const { handleAgentChat: r } = await import("../handler-9Rdn7zM2.js"), n = await e.req.json(), { message: o, sessionId: t, history: c } = n;
216
216
  if (!o || typeof o != "string")
217
- return r.json({ error: "message is required and must be a string" }, 400);
218
- let u = (q.apiKey || "").trim();
219
- if (q.allowClientApiKey) {
220
- const w = r.req.header("x-agent-api-key");
221
- w && (u = w.trim());
217
+ return e.json({ error: "message is required and must be a string" }, 400);
218
+ let u = (p.apiKey || "").trim();
219
+ if (p.allowClientApiKey) {
220
+ const g = e.req.header("x-agent-api-key");
221
+ g && (u = g.trim());
222
222
  }
223
223
  if (!u)
224
- return r.json({
224
+ return e.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 h = await f(r), x = new TextEncoder(), p = new ReadableStream({
228
- async start(w) {
227
+ const q = p.allowClientApiKey ? e.req.header("x-agent-provider") : void 0, A = p.allowClientApiKey ? e.req.header("x-agent-model") : void 0, f = p.allowClientApiKey ? e.req.header("x-agent-provider-endpoint") : void 0, E = await m(e), O = p.buildSystemContext?.(E), y = new TextEncoder(), S = new ReadableStream({
228
+ async start(g) {
229
229
  try {
230
- const b = e({
230
+ const w = r({
231
231
  message: o,
232
232
  sessionId: t,
233
233
  history: c,
234
234
  semanticLayer: s,
235
- securityContext: h,
236
- agentConfig: q,
237
- apiKey: u
235
+ securityContext: E,
236
+ agentConfig: p,
237
+ apiKey: u,
238
+ systemContext: O,
239
+ providerOverride: q,
240
+ modelOverride: A,
241
+ baseURLOverride: f
238
242
  });
239
- for await (const d of b) {
240
- const R = `data: ${JSON.stringify(d)}
243
+ for await (const v of w) {
244
+ const R = `data: ${JSON.stringify(v)}
241
245
 
242
246
  `;
243
- w.enqueue(x.encode(R));
247
+ g.enqueue(y.encode(R));
244
248
  }
245
- } catch (b) {
246
- const d = {
249
+ } catch (w) {
250
+ const v = {
247
251
  type: "error",
248
- data: { message: b instanceof Error ? b.message : "Stream failed" }
252
+ data: { message: w instanceof Error ? w.message : "Stream failed" }
249
253
  };
250
- w.enqueue(x.encode(`data: ${JSON.stringify(d)}
254
+ g.enqueue(y.encode(`data: ${JSON.stringify(v)}
251
255
 
252
256
  `));
253
257
  } finally {
254
- w.close();
258
+ g.close();
255
259
  }
256
260
  }
257
261
  });
258
- return new Response(p, {
262
+ return new Response(S, {
259
263
  status: 200,
260
264
  headers: {
261
265
  "Content-Type": "text/event-stream",
@@ -263,86 +267,86 @@ function te(C) {
263
267
  Connection: "keep-alive"
264
268
  }
265
269
  });
266
- } catch (e) {
267
- return console.error("Agent chat error:", e), r.json({
268
- error: e instanceof Error ? e.message : "Agent chat failed"
270
+ } catch (r) {
271
+ return console.error("Agent chat error:", r), e.json({
272
+ error: r instanceof Error ? r.message : "Agent chat failed"
269
273
  }, 500);
270
274
  }
271
- }), v.enabled !== !1) {
272
- const r = {
275
+ }), b.enabled !== !1) {
276
+ const e = {
273
277
  uri: "drizzle-cube://schema",
274
278
  name: "Cube Schema",
275
279
  description: "Current cube metadata as JSON",
276
280
  mimeType: "application/json",
277
281
  text: JSON.stringify(s.getMetadata(), null, 2)
278
- }, e = [...X(), r], n = G(), o = v.basePath ?? "/mcp";
282
+ }, r = [...X(), e], n = G(), o = b.basePath ?? "/mcp";
279
283
  a.post(`${o}`, async (t) => {
280
- const c = B(
284
+ const c = V(
281
285
  t.req.header("origin"),
282
- v.allowedOrigins ? { allowedOrigins: v.allowedOrigins } : {}
286
+ b.allowedOrigins ? { allowedOrigins: b.allowedOrigins } : {}
283
287
  );
284
288
  if (!c.valid)
285
- return t.json(M(null, -32600, c.reason), 403);
289
+ return t.json($(null, -32600, c.reason), 403);
286
290
  const u = t.req.header("accept");
287
- if (!z(u))
288
- return t.json(M(null, -32600, "Accept header must include both application/json and text/event-stream"), 400);
289
- const h = K(t.req.header());
290
- if (!h.ok)
291
+ if (!B(u))
292
+ return t.json($(null, -32600, "Accept header must include both application/json and text/event-stream"), 400);
293
+ const q = z(t.req.header());
294
+ if (!q.ok)
291
295
  return t.json({
292
296
  error: "Unsupported MCP protocol version",
293
- supported: h.supported
297
+ supported: q.supported
294
298
  }, 426);
295
- const x = await t.req.json().catch(() => null), p = _(x);
296
- if (!p)
297
- return t.json(M(null, -32600, "Invalid JSON-RPC 2.0 request"), 400);
298
- const w = U(u), b = p.method === "initialize";
299
+ const A = await t.req.json().catch(() => null), f = _(A);
300
+ if (!f)
301
+ return t.json($(null, -32600, "Invalid JSON-RPC 2.0 request"), 400);
302
+ const E = U(u), O = f.method === "initialize";
299
303
  try {
300
- const d = await F(
301
- p.method,
302
- p.params,
304
+ const y = await F(
305
+ f.method,
306
+ f.params,
303
307
  {
304
308
  semanticLayer: s,
305
- extractSecurityContext: f,
309
+ extractSecurityContext: m,
306
310
  rawRequest: t,
307
311
  rawResponse: null,
308
- negotiatedProtocol: h.negotiated,
309
- resources: e,
312
+ negotiatedProtocol: q.negotiated,
313
+ resources: r,
310
314
  prompts: n
311
315
  }
312
316
  );
313
- if (O(p))
317
+ if (I(f))
314
318
  return t.body(null, 202);
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({
319
+ const S = W(f.id ?? null, y), g = O && y && typeof y == "object" && "sessionId" in y ? y.sessionId : void 0, w = {};
320
+ if (g && (w[Y] = g), E) {
321
+ const v = new TextEncoder(), R = N(), P = new ReadableStream({
318
322
  start(Q) {
319
- Q.enqueue(E.encode(`id: ${A}
323
+ Q.enqueue(v.encode(`id: ${R}
320
324
 
321
- `)), Q.enqueue(E.encode(I(R, A))), Q.close();
325
+ `)), Q.enqueue(v.encode(T(S, R))), Q.close();
322
326
  }
323
327
  });
324
- return new Response($, {
328
+ return new Response(P, {
325
329
  status: 200,
326
330
  headers: {
327
331
  "Content-Type": "text/event-stream",
328
332
  "Cache-Control": "no-cache",
329
333
  Connection: "keep-alive",
330
- ...S
334
+ ...w
331
335
  }
332
336
  });
333
337
  }
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({
342
- start(N) {
343
- N.enqueue(A.encode(`id: ${$}
338
+ return t.json(S, 200, w);
339
+ } catch (y) {
340
+ if (I(f))
341
+ return console.error("MCP notification processing error:", y), t.body(null, 202);
342
+ console.error("MCP RPC error:", y);
343
+ const S = y?.code ?? -32603, g = y?.data, w = y.message || "MCP request failed", v = $(f.id ?? null, S, w, g);
344
+ if (E) {
345
+ const R = new TextEncoder(), P = N(), Q = new ReadableStream({
346
+ start(H) {
347
+ H.enqueue(R.encode(`id: ${P}
344
348
 
345
- `)), N.enqueue(A.encode(I(E, $))), N.close();
349
+ `)), H.enqueue(R.encode(T(v, P))), H.close();
346
350
  }
347
351
  });
348
352
  return new Response(Q, {
@@ -354,28 +358,28 @@ function te(C) {
354
358
  }
355
359
  });
356
360
  }
357
- return t.json(E, 200);
361
+ return t.json(v, 200);
358
362
  }
359
363
  }), a.delete(`${o}`, (t) => t.json({ error: "Session termination not supported" }, 405)), a.get(`${o}`, (t) => {
360
- const c = new TextEncoder(), u = T();
361
- let h;
362
- const x = new ReadableStream({
363
- start(p) {
364
- p.enqueue(c.encode(I({
364
+ const c = new TextEncoder(), u = N();
365
+ let q;
366
+ const A = new ReadableStream({
367
+ start(f) {
368
+ f.enqueue(c.encode(T({
365
369
  jsonrpc: "2.0",
366
370
  method: "mcp/ready",
367
371
  params: { protocol: "streamable-http" }
368
- }, u, 15e3))), h = setInterval(() => {
369
- p.enqueue(c.encode(`: keep-alive
372
+ }, u, 15e3))), q = setInterval(() => {
373
+ f.enqueue(c.encode(`: keep-alive
370
374
 
371
375
  `));
372
376
  }, 15e3);
373
377
  },
374
378
  cancel() {
375
- clearInterval(h);
379
+ clearInterval(q);
376
380
  }
377
381
  });
378
- return new Response(x, {
382
+ return new Response(A, {
379
383
  status: 200,
380
384
  headers: {
381
385
  "Content-Type": "text/event-stream",
@@ -387,13 +391,13 @@ function te(C) {
387
391
  }
388
392
  return a;
389
393
  }
390
- function ne(C, j) {
391
- const y = te(j);
392
- return C.route("/", y), C;
394
+ function ne(j, x) {
395
+ const d = te(x);
396
+ return j.route("/", d), j;
393
397
  }
394
- function ie(C) {
395
- const j = new L();
396
- return ne(j, C);
398
+ function ie(j) {
399
+ const x = new L();
400
+ return ne(x, j);
397
401
  }
398
402
  export {
399
403
  ie as createCubeApp,