drizzle-cube 0.4.19 → 0.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/adapters/anthropic-CTu9E801.js +126 -0
- package/dist/adapters/express/index.cjs +6 -6
- package/dist/adapters/express/index.js +73 -69
- package/dist/adapters/fastify/index.cjs +6 -6
- package/dist/adapters/fastify/index.js +133 -129
- package/dist/adapters/google-BAK9pnQf.cjs +2 -0
- package/dist/adapters/google-DficVAsJ.js +146 -0
- package/dist/adapters/{handler-BV4JuWNW.js → handler-9Rdn7zM2.js} +537 -457
- package/dist/adapters/handler-B-tEntiU.cjs +39 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +199 -195
- package/dist/adapters/index-BIMhF5KZ.cjs +23 -0
- package/dist/adapters/index-BgCeQBuN.cjs +2 -0
- package/dist/adapters/index-C45_meK_.js +719 -0
- package/dist/adapters/index-CFEJ62GJ.js +5337 -0
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +215 -211
- package/dist/adapters/openai-CUSRuKTk.js +131 -0
- package/dist/adapters/openai-mLo2MCat.cjs +1 -0
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +3 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +6 -0
- package/dist/client/hooks/useAgentChat.d.ts +6 -0
- package/dist/client/index.js +730 -697
- package/dist/client/index.js.map +1 -1
- package/dist/client/styles.css +1 -1
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/server/anthropic-CTu9E801.js +126 -0
- package/dist/server/google-BAK9pnQf.cjs +2 -0
- package/dist/server/google-DficVAsJ.js +146 -0
- package/dist/server/index-BIMhF5KZ.cjs +23 -0
- package/dist/server/index-BgCeQBuN.cjs +2 -0
- package/dist/server/index-C45_meK_.js +719 -0
- package/dist/server/index-CFEJ62GJ.js +5337 -0
- package/dist/server/index.cjs +51 -45
- package/dist/server/index.d.ts +49 -10
- package/dist/server/index.js +1978 -1898
- package/dist/server/openai-CUSRuKTk.js +131 -0
- package/dist/server/openai-mLo2MCat.cjs +1 -0
- package/package.json +12 -2
- package/dist/adapters/handler-D4MVKkVy.cjs +0 -33
|
@@ -1,261 +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:
|
|
39
|
+
cubes: x,
|
|
40
|
+
drizzle: d,
|
|
41
|
+
schema: M,
|
|
42
|
+
extractSecurityContext: m,
|
|
43
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:
|
|
54
|
+
const s = new K({
|
|
55
|
+
drizzle: d,
|
|
56
|
+
schema: M,
|
|
57
57
|
engineType: l,
|
|
58
|
-
cache:
|
|
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:
|
|
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
|
|
240
|
-
const R = `data: ${JSON.stringify(
|
|
243
|
+
for await (const v of w) {
|
|
244
|
+
const R = `data: ${JSON.stringify(v)}
|
|
241
245
|
|
|
242
246
|
`;
|
|
243
|
-
|
|
247
|
+
g.enqueue(y.encode(R));
|
|
244
248
|
}
|
|
245
|
-
} catch (
|
|
246
|
-
const
|
|
249
|
+
} catch (w) {
|
|
250
|
+
const v = {
|
|
247
251
|
type: "error",
|
|
248
|
-
data: { message:
|
|
252
|
+
data: { message: w instanceof Error ? w.message : "Stream failed" }
|
|
249
253
|
};
|
|
250
|
-
|
|
254
|
+
g.enqueue(y.encode(`data: ${JSON.stringify(v)}
|
|
251
255
|
|
|
252
256
|
`));
|
|
253
257
|
} finally {
|
|
254
|
-
|
|
258
|
+
g.close();
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
261
|
});
|
|
258
|
-
return new Response(
|
|
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 (
|
|
267
|
-
return console.error("Agent chat error:",
|
|
268
|
-
error:
|
|
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
|
-
}),
|
|
272
|
-
const
|
|
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
|
-
},
|
|
282
|
+
}, r = [...X(), e], n = G(), o = b.basePath ?? "/mcp";
|
|
279
283
|
a.post(`${o}`, async (t) => {
|
|
280
|
-
const c =
|
|
284
|
+
const c = V(
|
|
281
285
|
t.req.header("origin"),
|
|
282
|
-
|
|
286
|
+
b.allowedOrigins ? { allowedOrigins: b.allowedOrigins } : {}
|
|
283
287
|
);
|
|
284
288
|
if (!c.valid)
|
|
285
|
-
return t.json(
|
|
289
|
+
return t.json($(null, -32600, c.reason), 403);
|
|
286
290
|
const u = t.req.header("accept");
|
|
287
|
-
if (!
|
|
288
|
-
return t.json(
|
|
289
|
-
const
|
|
290
|
-
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)
|
|
291
295
|
return t.json({
|
|
292
296
|
error: "Unsupported MCP protocol version",
|
|
293
|
-
supported:
|
|
297
|
+
supported: q.supported
|
|
294
298
|
}, 426);
|
|
295
|
-
const
|
|
296
|
-
if (!
|
|
297
|
-
return t.json(
|
|
298
|
-
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";
|
|
299
303
|
try {
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
304
|
+
const y = await F(
|
|
305
|
+
f.method,
|
|
306
|
+
f.params,
|
|
303
307
|
{
|
|
304
308
|
semanticLayer: s,
|
|
305
|
-
extractSecurityContext:
|
|
309
|
+
extractSecurityContext: m,
|
|
306
310
|
rawRequest: t,
|
|
307
311
|
rawResponse: null,
|
|
308
|
-
negotiatedProtocol:
|
|
309
|
-
resources:
|
|
312
|
+
negotiatedProtocol: q.negotiated,
|
|
313
|
+
resources: r,
|
|
310
314
|
prompts: n
|
|
311
315
|
}
|
|
312
316
|
);
|
|
313
|
-
if (
|
|
317
|
+
if (I(f))
|
|
314
318
|
return t.body(null, 202);
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
317
|
-
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({
|
|
318
322
|
start(Q) {
|
|
319
|
-
Q.enqueue(
|
|
323
|
+
Q.enqueue(v.encode(`id: ${R}
|
|
320
324
|
|
|
321
|
-
`)), Q.enqueue(
|
|
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
|
-
...
|
|
334
|
+
...w
|
|
331
335
|
}
|
|
332
336
|
});
|
|
333
337
|
}
|
|
334
|
-
return t.json(
|
|
335
|
-
} catch (
|
|
336
|
-
if (
|
|
337
|
-
return console.error("MCP notification processing error:",
|
|
338
|
-
console.error("MCP RPC error:",
|
|
339
|
-
const
|
|
340
|
-
if (
|
|
341
|
-
const
|
|
342
|
-
start(
|
|
343
|
-
|
|
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
|
-
`)),
|
|
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(
|
|
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 =
|
|
361
|
-
let
|
|
362
|
-
const
|
|
363
|
-
start(
|
|
364
|
-
|
|
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))),
|
|
369
|
-
|
|
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(
|
|
379
|
+
clearInterval(q);
|
|
376
380
|
}
|
|
377
381
|
});
|
|
378
|
-
return new Response(
|
|
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(
|
|
391
|
-
const
|
|
392
|
-
return
|
|
394
|
+
function ne(j, x) {
|
|
395
|
+
const d = te(x);
|
|
396
|
+
return j.route("/", d), j;
|
|
393
397
|
}
|
|
394
|
-
function ie(
|
|
395
|
-
const
|
|
396
|
-
return ne(
|
|
398
|
+
function ie(j) {
|
|
399
|
+
const x = new L();
|
|
400
|
+
return ne(x, j);
|
|
397
401
|
}
|
|
398
402
|
export {
|
|
399
403
|
ie as createCubeApp,
|