drizzle-cube 0.4.20 → 0.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/adapters/anthropic-CTu9E801.js +126 -0
- package/dist/adapters/express/index.cjs +6 -6
- package/dist/adapters/express/index.js +119 -116
- package/dist/adapters/fastify/index.cjs +6 -6
- package/dist/adapters/fastify/index.js +113 -110
- package/dist/adapters/google-BAK9pnQf.cjs +2 -0
- package/dist/adapters/google-DficVAsJ.js +146 -0
- package/dist/adapters/{handler-CbDMdSY5.js → handler-9Rdn7zM2.js} +534 -461
- package/dist/adapters/handler-B-tEntiU.cjs +39 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +199 -196
- package/dist/adapters/index-BIMhF5KZ.cjs +23 -0
- package/dist/adapters/index-BgCeQBuN.cjs +2 -0
- package/dist/adapters/index-C45_meK_.js +719 -0
- package/dist/adapters/index-CFEJ62GJ.js +5337 -0
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +245 -242
- package/dist/adapters/openai-CUSRuKTk.js +131 -0
- package/dist/adapters/openai-mLo2MCat.cjs +1 -0
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +3 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +6 -0
- package/dist/client/hooks/useAgentChat.d.ts +6 -0
- package/dist/client/index.js +730 -697
- package/dist/client/index.js.map +1 -1
- package/dist/client/styles.css +1 -1
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/server/anthropic-CTu9E801.js +126 -0
- package/dist/server/google-BAK9pnQf.cjs +2 -0
- package/dist/server/google-DficVAsJ.js +146 -0
- package/dist/server/index-BIMhF5KZ.cjs +23 -0
- package/dist/server/index-BgCeQBuN.cjs +2 -0
- package/dist/server/index-C45_meK_.js +719 -0
- package/dist/server/index-CFEJ62GJ.js +5337 -0
- package/dist/server/index.cjs +48 -46
- package/dist/server/index.d.ts +37 -10
- package/dist/server/index.js +1974 -1901
- package/dist/server/openai-CUSRuKTk.js +131 -0
- package/dist/server/openai-mLo2MCat.cjs +1 -0
- package/package.json +12 -2
- package/dist/adapters/handler-DtdjM1Vx.cjs +0 -37
|
@@ -1,262 +1,265 @@
|
|
|
1
1
|
import { Hono as L } from "hono";
|
|
2
|
-
import { S as
|
|
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 = (
|
|
5
|
-
const
|
|
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
|
-
...
|
|
13
|
-
},
|
|
14
|
-
return async function(i,
|
|
15
|
-
function
|
|
16
|
-
i.res.headers.set(
|
|
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
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
let a =
|
|
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 && (
|
|
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
|
|
34
|
+
await h(), d.origin !== "*" && i.header("Vary", "Origin", { append: !0 });
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
function te(
|
|
37
|
+
function te(j) {
|
|
38
38
|
const {
|
|
39
|
-
cubes:
|
|
40
|
-
drizzle:
|
|
41
|
-
schema:
|
|
42
|
-
extractSecurityContext:
|
|
43
|
-
engineType:
|
|
39
|
+
cubes: x,
|
|
40
|
+
drizzle: d,
|
|
41
|
+
schema: M,
|
|
42
|
+
extractSecurityContext: m,
|
|
43
|
+
engineType: l,
|
|
44
44
|
cors: i,
|
|
45
|
-
basePath:
|
|
46
|
-
cache:
|
|
47
|
-
mcp:
|
|
48
|
-
agent:
|
|
49
|
-
} =
|
|
50
|
-
if (!
|
|
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
|
|
55
|
-
drizzle:
|
|
56
|
-
schema:
|
|
57
|
-
engineType:
|
|
58
|
-
cache:
|
|
54
|
+
const s = new K({
|
|
55
|
+
drizzle: d,
|
|
56
|
+
schema: M,
|
|
57
|
+
engineType: l,
|
|
58
|
+
cache: C
|
|
59
59
|
});
|
|
60
|
-
if (
|
|
61
|
-
s.registerCube(
|
|
62
|
-
}), a.post(`${
|
|
60
|
+
if (x.forEach((e) => {
|
|
61
|
+
s.registerCube(e);
|
|
62
|
+
}), a.post(`${h}/load`, async (e) => {
|
|
63
63
|
try {
|
|
64
|
-
const
|
|
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
|
|
66
|
+
return e.json({
|
|
67
67
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
68
68
|
}, 400);
|
|
69
|
-
const c =
|
|
70
|
-
return
|
|
71
|
-
} catch (
|
|
72
|
-
return console.error("Query execution error:",
|
|
73
|
-
error:
|
|
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(`${
|
|
76
|
+
}), a.get(`${h}/load`, async (e) => {
|
|
77
77
|
try {
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
return
|
|
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(
|
|
85
|
+
n = JSON.parse(r);
|
|
86
86
|
} catch {
|
|
87
|
-
return
|
|
87
|
+
return e.json({
|
|
88
88
|
error: "Invalid JSON in query parameter"
|
|
89
89
|
}, 400);
|
|
90
90
|
}
|
|
91
|
-
const o = await
|
|
91
|
+
const o = await m(e), t = s.validateQuery(n);
|
|
92
92
|
if (!t.isValid)
|
|
93
|
-
return
|
|
93
|
+
return e.json({
|
|
94
94
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
95
95
|
}, 400);
|
|
96
|
-
const c =
|
|
97
|
-
return
|
|
98
|
-
} catch (
|
|
99
|
-
return console.error("Query execution error:",
|
|
100
|
-
error:
|
|
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(`${
|
|
103
|
+
}), a.post(`${h}/batch`, async (e) => {
|
|
104
104
|
try {
|
|
105
|
-
const
|
|
105
|
+
const r = await e.req.json(), { queries: n } = r;
|
|
106
106
|
if (!n || !Array.isArray(n))
|
|
107
|
-
return
|
|
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
|
|
111
|
+
return e.json({
|
|
112
112
|
error: "Queries array cannot be empty"
|
|
113
113
|
}, 400);
|
|
114
|
-
const o = await
|
|
115
|
-
return
|
|
116
|
-
} catch (
|
|
117
|
-
return console.error("Batch execution error:",
|
|
118
|
-
error:
|
|
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(`${
|
|
121
|
+
}), a.get(`${h}/meta`, (e) => {
|
|
122
122
|
try {
|
|
123
|
-
const
|
|
124
|
-
return
|
|
125
|
-
} catch (
|
|
126
|
-
return console.error("Metadata error:",
|
|
127
|
-
error:
|
|
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(`${
|
|
130
|
+
}), a.post(`${h}/sql`, async (e) => {
|
|
131
131
|
try {
|
|
132
|
-
const
|
|
132
|
+
const r = await e.req.json(), n = await m(e), o = s.validateQuery(r);
|
|
133
133
|
if (!o.isValid)
|
|
134
|
-
return
|
|
134
|
+
return e.json({
|
|
135
135
|
error: `Query validation failed: ${o.errors.join(", ")}`
|
|
136
136
|
}, 400);
|
|
137
|
-
const t =
|
|
137
|
+
const t = r.measures?.[0] || r.dimensions?.[0];
|
|
138
138
|
if (!t)
|
|
139
|
-
return
|
|
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,
|
|
143
|
-
return
|
|
144
|
-
} catch (
|
|
145
|
-
return console.error("SQL generation error:",
|
|
146
|
-
error:
|
|
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(`${
|
|
149
|
+
}), a.get(`${h}/sql`, async (e) => {
|
|
150
150
|
try {
|
|
151
|
-
const
|
|
152
|
-
if (!
|
|
153
|
-
return
|
|
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(
|
|
156
|
+
const n = JSON.parse(r), o = await m(e), t = s.validateQuery(n);
|
|
157
157
|
if (!t.isValid)
|
|
158
|
-
return
|
|
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
|
|
163
|
+
return e.json({
|
|
164
164
|
error: "No measures or dimensions specified"
|
|
165
165
|
}, 400);
|
|
166
|
-
const u = c.split(".")[0],
|
|
167
|
-
return
|
|
168
|
-
} catch (
|
|
169
|
-
return console.error("SQL generation error:",
|
|
170
|
-
error:
|
|
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(`${
|
|
173
|
+
}), a.post(`${h}/dry-run`, async (e) => {
|
|
174
174
|
try {
|
|
175
|
-
const
|
|
176
|
-
return
|
|
177
|
-
} catch (
|
|
178
|
-
return console.error("Dry-run error:",
|
|
179
|
-
error:
|
|
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(`${
|
|
183
|
+
}), a.get(`${h}/dry-run`, async (e) => {
|
|
184
184
|
try {
|
|
185
|
-
const
|
|
186
|
-
if (!
|
|
187
|
-
return
|
|
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(
|
|
192
|
-
return
|
|
193
|
-
} catch (
|
|
194
|
-
return console.error("Dry-run error:",
|
|
195
|
-
error:
|
|
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(`${
|
|
199
|
+
}), a.post(`${h}/explain`, async (e) => {
|
|
200
200
|
try {
|
|
201
|
-
const
|
|
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
|
|
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
|
|
208
|
-
} catch (
|
|
209
|
-
return console.error("Explain error:",
|
|
210
|
-
error:
|
|
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
|
-
}),
|
|
213
|
+
}), p && a.post(`${h}/agent/chat`, async (e) => {
|
|
214
214
|
try {
|
|
215
|
-
const { handleAgentChat:
|
|
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
|
|
218
|
-
let u = (
|
|
219
|
-
if (
|
|
220
|
-
const
|
|
221
|
-
|
|
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
|
|
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
|
|
228
|
-
async start(
|
|
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
|
|
230
|
+
const w = r({
|
|
231
231
|
message: o,
|
|
232
232
|
sessionId: t,
|
|
233
233
|
history: c,
|
|
234
234
|
semanticLayer: s,
|
|
235
|
-
securityContext:
|
|
236
|
-
agentConfig:
|
|
235
|
+
securityContext: E,
|
|
236
|
+
agentConfig: p,
|
|
237
237
|
apiKey: u,
|
|
238
|
-
systemContext:
|
|
238
|
+
systemContext: O,
|
|
239
|
+
providerOverride: q,
|
|
240
|
+
modelOverride: A,
|
|
241
|
+
baseURLOverride: f
|
|
239
242
|
});
|
|
240
|
-
for await (const v of
|
|
241
|
-
const
|
|
243
|
+
for await (const v of w) {
|
|
244
|
+
const R = `data: ${JSON.stringify(v)}
|
|
242
245
|
|
|
243
246
|
`;
|
|
244
|
-
|
|
247
|
+
g.enqueue(y.encode(R));
|
|
245
248
|
}
|
|
246
|
-
} catch (
|
|
249
|
+
} catch (w) {
|
|
247
250
|
const v = {
|
|
248
251
|
type: "error",
|
|
249
|
-
data: { message:
|
|
252
|
+
data: { message: w instanceof Error ? w.message : "Stream failed" }
|
|
250
253
|
};
|
|
251
|
-
|
|
254
|
+
g.enqueue(y.encode(`data: ${JSON.stringify(v)}
|
|
252
255
|
|
|
253
256
|
`));
|
|
254
257
|
} finally {
|
|
255
|
-
|
|
258
|
+
g.close();
|
|
256
259
|
}
|
|
257
260
|
}
|
|
258
261
|
});
|
|
259
|
-
return new Response(
|
|
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 (
|
|
268
|
-
return console.error("Agent chat error:",
|
|
269
|
-
error:
|
|
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
|
-
}),
|
|
273
|
-
const
|
|
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
|
-
},
|
|
282
|
+
}, r = [...X(), e], n = G(), o = b.basePath ?? "/mcp";
|
|
280
283
|
a.post(`${o}`, async (t) => {
|
|
281
|
-
const c =
|
|
284
|
+
const c = V(
|
|
282
285
|
t.req.header("origin"),
|
|
283
|
-
|
|
286
|
+
b.allowedOrigins ? { allowedOrigins: b.allowedOrigins } : {}
|
|
284
287
|
);
|
|
285
288
|
if (!c.valid)
|
|
286
|
-
return t.json(
|
|
289
|
+
return t.json($(null, -32600, c.reason), 403);
|
|
287
290
|
const u = t.req.header("accept");
|
|
288
|
-
if (!
|
|
289
|
-
return t.json(
|
|
290
|
-
const
|
|
291
|
-
if (!
|
|
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:
|
|
297
|
+
supported: q.supported
|
|
295
298
|
}, 426);
|
|
296
|
-
const
|
|
297
|
-
if (!
|
|
298
|
-
return t.json(
|
|
299
|
-
const
|
|
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
|
|
302
|
-
|
|
303
|
-
|
|
304
|
+
const y = await F(
|
|
305
|
+
f.method,
|
|
306
|
+
f.params,
|
|
304
307
|
{
|
|
305
308
|
semanticLayer: s,
|
|
306
|
-
extractSecurityContext:
|
|
309
|
+
extractSecurityContext: m,
|
|
307
310
|
rawRequest: t,
|
|
308
311
|
rawResponse: null,
|
|
309
|
-
negotiatedProtocol:
|
|
310
|
-
resources:
|
|
312
|
+
negotiatedProtocol: q.negotiated,
|
|
313
|
+
resources: r,
|
|
311
314
|
prompts: n
|
|
312
315
|
}
|
|
313
316
|
);
|
|
314
|
-
if (
|
|
317
|
+
if (I(f))
|
|
315
318
|
return t.body(null, 202);
|
|
316
|
-
const
|
|
317
|
-
if (
|
|
318
|
-
const
|
|
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(
|
|
323
|
+
Q.enqueue(v.encode(`id: ${R}
|
|
321
324
|
|
|
322
|
-
`)), Q.enqueue(
|
|
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
|
-
...
|
|
334
|
+
...w
|
|
332
335
|
}
|
|
333
336
|
});
|
|
334
337
|
}
|
|
335
|
-
return t.json(
|
|
336
|
-
} catch (
|
|
337
|
-
if (
|
|
338
|
-
return console.error("MCP notification processing error:",
|
|
339
|
-
console.error("MCP RPC error:",
|
|
340
|
-
const
|
|
341
|
-
if (
|
|
342
|
-
const
|
|
343
|
-
start(
|
|
344
|
-
|
|
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
|
-
`)),
|
|
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(
|
|
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 =
|
|
362
|
-
let
|
|
363
|
-
const
|
|
364
|
-
start(
|
|
365
|
-
|
|
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))),
|
|
370
|
-
|
|
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(
|
|
379
|
+
clearInterval(q);
|
|
377
380
|
}
|
|
378
381
|
});
|
|
379
|
-
return new Response(
|
|
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(
|
|
392
|
-
const
|
|
393
|
-
return
|
|
394
|
+
function ne(j, x) {
|
|
395
|
+
const d = te(x);
|
|
396
|
+
return j.route("/", d), j;
|
|
394
397
|
}
|
|
395
|
-
function ie(
|
|
396
|
-
const
|
|
397
|
-
return ne(
|
|
398
|
+
function ie(j) {
|
|
399
|
+
const x = new L();
|
|
400
|
+
return ne(x, j);
|
|
398
401
|
}
|
|
399
402
|
export {
|
|
400
403
|
ie as createCubeApp,
|