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.
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 +119 -116
  5. package/dist/adapters/fastify/index.cjs +6 -6
  6. package/dist/adapters/fastify/index.js +113 -110
  7. package/dist/adapters/google-BAK9pnQf.cjs +2 -0
  8. package/dist/adapters/google-DficVAsJ.js +146 -0
  9. package/dist/adapters/{handler-CbDMdSY5.js → handler-9Rdn7zM2.js} +534 -461
  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 -196
  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 +245 -242
  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 +48 -46
  37. package/dist/server/index.d.ts +37 -10
  38. package/dist/server/index.js +1974 -1901
  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-DtdjM1Vx.cjs +0 -37
@@ -1,262 +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 = (w) => {
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
- ...w
13
- }, H = /* @__PURE__ */ ((d) => typeof d == "string" ? d === "*" ? () => d : (i) => d === i ? i : null : typeof d == "function" ? d : (i) => d.includes(i) ? i : null)(y.origin), f = ((d) => typeof d == "function" ? d : Array.isArray(d) ? () => d : () => [])(y.allowMethods);
14
- return async function(i, m) {
15
- function q(g, a) {
16
- i.res.headers.set(g, 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 x = await H(i.req.header("origin") || "", i);
19
- if (x && q("Access-Control-Allow-Origin", x), y.credentials && q("Access-Control-Allow-Credentials", "true"), y.exposeHeaders?.length && q("Access-Control-Expose-Headers", y.exposeHeaders.join(",")), i.req.method === "OPTIONS") {
20
- y.origin !== "*" && q("Vary", "Origin"), y.maxAge != null && q("Access-Control-Max-Age", y.maxAge.toString());
21
- const g = await f(i.req.header("origin") || "", i);
22
- g.length && q("Access-Control-Allow-Methods", g.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 && (q("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(w) {
37
+ function te(j) {
38
38
  const {
39
- cubes: C,
40
- drizzle: y,
41
- schema: H,
42
- extractSecurityContext: f,
43
- engineType: d,
39
+ cubes: x,
40
+ drizzle: d,
41
+ schema: M,
42
+ extractSecurityContext: m,
43
+ engineType: l,
44
44
  cors: i,
45
- basePath: m = "/cubejs-api/v1",
46
- cache: q,
47
- mcp: x = { enabled: !0 },
48
- agent: g
49
- } = w;
50
- if (!C || C.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,
57
- engineType: d,
58
- cache: q
54
+ const s = new K({
55
+ drizzle: d,
56
+ schema: M,
57
+ engineType: l,
58
+ cache: C
59
59
  });
60
- if (C.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
- }), g && 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-CbDMdSY5.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 = (g.apiKey || "").trim();
219
- if (g.allowClientApiKey) {
220
- const j = r.req.header("x-agent-api-key");
221
- j && (u = j.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), R = g.buildSystemContext?.(h), p = new TextEncoder(), P = new ReadableStream({
228
- async start(j) {
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 l = 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: g,
235
+ securityContext: E,
236
+ agentConfig: p,
237
237
  apiKey: u,
238
- systemContext: R
238
+ systemContext: O,
239
+ providerOverride: q,
240
+ modelOverride: A,
241
+ baseURLOverride: f
239
242
  });
240
- for await (const v of l) {
241
- const b = `data: ${JSON.stringify(v)}
243
+ for await (const v of w) {
244
+ const R = `data: ${JSON.stringify(v)}
242
245
 
243
246
  `;
244
- j.enqueue(p.encode(b));
247
+ g.enqueue(y.encode(R));
245
248
  }
246
- } catch (l) {
249
+ } catch (w) {
247
250
  const v = {
248
251
  type: "error",
249
- data: { message: l instanceof Error ? l.message : "Stream failed" }
252
+ data: { message: w instanceof Error ? w.message : "Stream failed" }
250
253
  };
251
- j.enqueue(p.encode(`data: ${JSON.stringify(v)}
254
+ g.enqueue(y.encode(`data: ${JSON.stringify(v)}
252
255
 
253
256
  `));
254
257
  } finally {
255
- j.close();
258
+ g.close();
256
259
  }
257
260
  }
258
261
  });
259
- return new Response(P, {
262
+ return new Response(S, {
260
263
  status: 200,
261
264
  headers: {
262
265
  "Content-Type": "text/event-stream",
@@ -264,86 +267,86 @@ function te(w) {
264
267
  Connection: "keep-alive"
265
268
  }
266
269
  });
267
- } catch (e) {
268
- return console.error("Agent chat error:", e), r.json({
269
- 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"
270
273
  }, 500);
271
274
  }
272
- }), x.enabled !== !1) {
273
- const r = {
275
+ }), b.enabled !== !1) {
276
+ const e = {
274
277
  uri: "drizzle-cube://schema",
275
278
  name: "Cube Schema",
276
279
  description: "Current cube metadata as JSON",
277
280
  mimeType: "application/json",
278
281
  text: JSON.stringify(s.getMetadata(), null, 2)
279
- }, e = [...X(), r], n = G(), o = x.basePath ?? "/mcp";
282
+ }, r = [...X(), e], n = G(), o = b.basePath ?? "/mcp";
280
283
  a.post(`${o}`, async (t) => {
281
- const c = B(
284
+ const c = V(
282
285
  t.req.header("origin"),
283
- x.allowedOrigins ? { allowedOrigins: x.allowedOrigins } : {}
286
+ b.allowedOrigins ? { allowedOrigins: b.allowedOrigins } : {}
284
287
  );
285
288
  if (!c.valid)
286
- return t.json(M(null, -32600, c.reason), 403);
289
+ return t.json($(null, -32600, c.reason), 403);
287
290
  const u = t.req.header("accept");
288
- if (!z(u))
289
- return t.json(M(null, -32600, "Accept header must include both application/json and text/event-stream"), 400);
290
- const h = K(t.req.header());
291
- 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)
292
295
  return t.json({
293
296
  error: "Unsupported MCP protocol version",
294
- supported: h.supported
297
+ supported: q.supported
295
298
  }, 426);
296
- const R = await t.req.json().catch(() => null), p = _(R);
297
- if (!p)
298
- return t.json(M(null, -32600, "Invalid JSON-RPC 2.0 request"), 400);
299
- const P = U(u), j = 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";
300
303
  try {
301
- const l = await F(
302
- p.method,
303
- p.params,
304
+ const y = await F(
305
+ f.method,
306
+ f.params,
304
307
  {
305
308
  semanticLayer: s,
306
- extractSecurityContext: f,
309
+ extractSecurityContext: m,
307
310
  rawRequest: t,
308
311
  rawResponse: null,
309
- negotiatedProtocol: h.negotiated,
310
- resources: e,
312
+ negotiatedProtocol: q.negotiated,
313
+ resources: r,
311
314
  prompts: n
312
315
  }
313
316
  );
314
- if (O(p))
317
+ if (I(f))
315
318
  return t.body(null, 202);
316
- const v = W(p.id ?? null, l), b = j && l && typeof l == "object" && "sessionId" in l ? l.sessionId : void 0, S = {};
317
- if (b && (S[Y] = b), P) {
318
- 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({
319
322
  start(Q) {
320
- Q.enqueue(E.encode(`id: ${A}
323
+ Q.enqueue(v.encode(`id: ${R}
321
324
 
322
- `)), Q.enqueue(E.encode(I(v, A))), Q.close();
325
+ `)), Q.enqueue(v.encode(T(S, R))), Q.close();
323
326
  }
324
327
  });
325
- return new Response($, {
328
+ return new Response(P, {
326
329
  status: 200,
327
330
  headers: {
328
331
  "Content-Type": "text/event-stream",
329
332
  "Cache-Control": "no-cache",
330
333
  Connection: "keep-alive",
331
- ...S
334
+ ...w
332
335
  }
333
336
  });
334
337
  }
335
- return t.json(v, 200, S);
336
- } catch (l) {
337
- if (O(p))
338
- return console.error("MCP notification processing error:", l), t.body(null, 202);
339
- console.error("MCP RPC error:", l);
340
- const v = l?.code ?? -32603, b = l?.data, S = l.message || "MCP request failed", E = M(p.id ?? null, v, S, b);
341
- if (P) {
342
- const A = new TextEncoder(), $ = T(), Q = new ReadableStream({
343
- start(N) {
344
- 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}
345
348
 
346
- `)), N.enqueue(A.encode(I(E, $))), N.close();
349
+ `)), H.enqueue(R.encode(T(v, P))), H.close();
347
350
  }
348
351
  });
349
352
  return new Response(Q, {
@@ -355,28 +358,28 @@ function te(w) {
355
358
  }
356
359
  });
357
360
  }
358
- return t.json(E, 200);
361
+ return t.json(v, 200);
359
362
  }
360
363
  }), a.delete(`${o}`, (t) => t.json({ error: "Session termination not supported" }, 405)), a.get(`${o}`, (t) => {
361
- const c = new TextEncoder(), u = T();
362
- let h;
363
- const R = new ReadableStream({
364
- start(p) {
365
- 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({
366
369
  jsonrpc: "2.0",
367
370
  method: "mcp/ready",
368
371
  params: { protocol: "streamable-http" }
369
- }, u, 15e3))), h = setInterval(() => {
370
- p.enqueue(c.encode(`: keep-alive
372
+ }, u, 15e3))), q = setInterval(() => {
373
+ f.enqueue(c.encode(`: keep-alive
371
374
 
372
375
  `));
373
376
  }, 15e3);
374
377
  },
375
378
  cancel() {
376
- clearInterval(h);
379
+ clearInterval(q);
377
380
  }
378
381
  });
379
- return new Response(R, {
382
+ return new Response(A, {
380
383
  status: 200,
381
384
  headers: {
382
385
  "Content-Type": "text/event-stream",
@@ -388,13 +391,13 @@ function te(w) {
388
391
  }
389
392
  return a;
390
393
  }
391
- function ne(w, C) {
392
- const y = te(C);
393
- return w.route("/", y), w;
394
+ function ne(j, x) {
395
+ const d = te(x);
396
+ return j.route("/", d), j;
394
397
  }
395
- function ie(w) {
396
- const C = new L();
397
- return ne(C, w);
398
+ function ie(j) {
399
+ const x = new L();
400
+ return ne(x, j);
398
401
  }
399
402
  export {
400
403
  ie as createCubeApp,