drizzle-cube 0.4.19 → 0.4.20
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/express/index.cjs +6 -6
- package/dist/adapters/express/index.js +75 -74
- package/dist/adapters/fastify/index.cjs +5 -5
- package/dist/adapters/fastify/index.js +91 -90
- package/dist/adapters/{handler-BV4JuWNW.js → handler-CbDMdSY5.js} +49 -42
- package/dist/adapters/{handler-D4MVKkVy.cjs → handler-DtdjM1Vx.cjs} +17 -13
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +66 -65
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +116 -115
- package/dist/server/index.cjs +5 -1
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.js +8 -1
- package/package.json +1 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { S as D, v as K, b as x, a as T, n as V, p as z, w as _, d as B, i as j, M as F, c as U, e as E, s as P } from "../mcp-transport-m1X1GtwG.js";
|
|
2
|
-
import { formatErrorResponse as
|
|
2
|
+
import { formatErrorResponse as d, formatCubeResponse as A, handleBatchRequest as X, formatMetaResponse as G, formatSqlResponse as I, handleDryRun as M } from "../utils.js";
|
|
3
3
|
const N = function(i, k, R) {
|
|
4
4
|
const {
|
|
5
5
|
cubes: S,
|
|
6
6
|
drizzle: O,
|
|
7
7
|
schema: J,
|
|
8
|
-
extractSecurityContext:
|
|
8
|
+
extractSecurityContext: p,
|
|
9
9
|
engineType: L,
|
|
10
10
|
cors: q,
|
|
11
|
-
basePath:
|
|
12
|
-
bodyLimit:
|
|
11
|
+
basePath: m = "/cubejs-api/v1",
|
|
12
|
+
bodyLimit: g = 10485760,
|
|
13
13
|
// 10MB
|
|
14
14
|
cache: H,
|
|
15
|
-
mcp:
|
|
16
|
-
agent:
|
|
15
|
+
mcp: C = { enabled: !0 },
|
|
16
|
+
agent: f
|
|
17
17
|
} = k;
|
|
18
18
|
if (!S || S.length === 0)
|
|
19
19
|
return R(new Error("At least one cube must be provided in the cubes array"));
|
|
@@ -28,8 +28,8 @@ const N = function(i, k, R) {
|
|
|
28
28
|
});
|
|
29
29
|
if (S.forEach((t) => {
|
|
30
30
|
c.registerCube(t);
|
|
31
|
-
}), i.post(`${
|
|
32
|
-
bodyLimit:
|
|
31
|
+
}), i.post(`${m}/load`, {
|
|
32
|
+
bodyLimit: g,
|
|
33
33
|
schema: {
|
|
34
34
|
body: {
|
|
35
35
|
type: "object",
|
|
@@ -38,21 +38,21 @@ const N = function(i, k, R) {
|
|
|
38
38
|
}
|
|
39
39
|
}, async (t, r) => {
|
|
40
40
|
try {
|
|
41
|
-
const e = t.body, a = e.query || e, n = await
|
|
41
|
+
const e = t.body, a = e.query || e, n = await p(t), s = c.validateQuery(a);
|
|
42
42
|
if (!s.isValid)
|
|
43
|
-
return r.status(400).send(
|
|
43
|
+
return r.status(400).send(d(
|
|
44
44
|
`Query validation failed: ${s.errors.join(", ")}`,
|
|
45
45
|
400
|
|
46
46
|
));
|
|
47
|
-
const o = t.headers["x-cache-control"] === "no-cache",
|
|
48
|
-
return A(a,
|
|
47
|
+
const o = t.headers["x-cache-control"] === "no-cache", u = await c.executeMultiCubeQuery(a, n, { skipCache: o });
|
|
48
|
+
return A(a, u, c);
|
|
49
49
|
} catch (e) {
|
|
50
|
-
return t.log.error(e, "Query execution error"), r.status(500).send(
|
|
50
|
+
return t.log.error(e, "Query execution error"), r.status(500).send(d(
|
|
51
51
|
e instanceof Error ? e.message : "Query execution failed",
|
|
52
52
|
500
|
|
53
53
|
));
|
|
54
54
|
}
|
|
55
|
-
}), i.get(`${
|
|
55
|
+
}), i.get(`${m}/load`, {
|
|
56
56
|
schema: {
|
|
57
57
|
querystring: {
|
|
58
58
|
type: "object",
|
|
@@ -69,27 +69,27 @@ const N = function(i, k, R) {
|
|
|
69
69
|
try {
|
|
70
70
|
a = JSON.parse(e);
|
|
71
71
|
} catch {
|
|
72
|
-
return r.status(400).send(
|
|
72
|
+
return r.status(400).send(d(
|
|
73
73
|
"Invalid JSON in query parameter",
|
|
74
74
|
400
|
|
75
75
|
));
|
|
76
76
|
}
|
|
77
|
-
const n = await
|
|
77
|
+
const n = await p(t), s = c.validateQuery(a);
|
|
78
78
|
if (!s.isValid)
|
|
79
|
-
return r.status(400).send(
|
|
79
|
+
return r.status(400).send(d(
|
|
80
80
|
`Query validation failed: ${s.errors.join(", ")}`,
|
|
81
81
|
400
|
|
82
82
|
));
|
|
83
|
-
const o = t.headers["x-cache-control"] === "no-cache",
|
|
84
|
-
return A(a,
|
|
83
|
+
const o = t.headers["x-cache-control"] === "no-cache", u = await c.executeMultiCubeQuery(a, n, { skipCache: o });
|
|
84
|
+
return A(a, u, c);
|
|
85
85
|
} catch (e) {
|
|
86
|
-
return t.log.error(e, "Query execution error"), r.status(500).send(
|
|
86
|
+
return t.log.error(e, "Query execution error"), r.status(500).send(d(
|
|
87
87
|
e instanceof Error ? e.message : "Query execution failed",
|
|
88
88
|
500
|
|
89
89
|
));
|
|
90
90
|
}
|
|
91
|
-
}), i.post(`${
|
|
92
|
-
bodyLimit:
|
|
91
|
+
}), i.post(`${m}/batch`, {
|
|
92
|
+
bodyLimit: g,
|
|
93
93
|
schema: {
|
|
94
94
|
body: {
|
|
95
95
|
type: "object",
|
|
@@ -106,35 +106,35 @@ const N = function(i, k, R) {
|
|
|
106
106
|
try {
|
|
107
107
|
const { queries: e } = t.body;
|
|
108
108
|
if (!e || !Array.isArray(e))
|
|
109
|
-
return r.status(400).send(
|
|
109
|
+
return r.status(400).send(d(
|
|
110
110
|
'Request body must contain a "queries" array',
|
|
111
111
|
400
|
|
112
112
|
));
|
|
113
113
|
if (e.length === 0)
|
|
114
|
-
return r.status(400).send(
|
|
114
|
+
return r.status(400).send(d(
|
|
115
115
|
"Queries array cannot be empty",
|
|
116
116
|
400
|
|
117
117
|
));
|
|
118
|
-
const a = await
|
|
118
|
+
const a = await p(t), n = t.headers["x-cache-control"] === "no-cache";
|
|
119
119
|
return await X(e, a, c, { skipCache: n });
|
|
120
120
|
} catch (e) {
|
|
121
|
-
return t.log.error(e, "Batch execution error"), r.status(500).send(
|
|
121
|
+
return t.log.error(e, "Batch execution error"), r.status(500).send(d(
|
|
122
122
|
e instanceof Error ? e.message : "Batch execution failed",
|
|
123
123
|
500
|
|
124
124
|
));
|
|
125
125
|
}
|
|
126
|
-
}), i.get(`${
|
|
126
|
+
}), i.get(`${m}/meta`, async (t, r) => {
|
|
127
127
|
try {
|
|
128
128
|
const e = c.getMetadata();
|
|
129
129
|
return G(e);
|
|
130
130
|
} catch (e) {
|
|
131
|
-
return t.log.error(e, "Metadata error"), r.status(500).send(
|
|
131
|
+
return t.log.error(e, "Metadata error"), r.status(500).send(d(
|
|
132
132
|
e instanceof Error ? e.message : "Failed to fetch metadata",
|
|
133
133
|
500
|
|
134
134
|
));
|
|
135
135
|
}
|
|
136
|
-
}), i.post(`${
|
|
137
|
-
bodyLimit:
|
|
136
|
+
}), i.post(`${m}/sql`, {
|
|
137
|
+
bodyLimit: g,
|
|
138
138
|
schema: {
|
|
139
139
|
body: {
|
|
140
140
|
type: "object",
|
|
@@ -143,27 +143,27 @@ const N = function(i, k, R) {
|
|
|
143
143
|
}
|
|
144
144
|
}, async (t, r) => {
|
|
145
145
|
try {
|
|
146
|
-
const e = t.body, a = await
|
|
146
|
+
const e = t.body, a = await p(t), n = c.validateQuery(e);
|
|
147
147
|
if (!n.isValid)
|
|
148
|
-
return r.status(400).send(
|
|
148
|
+
return r.status(400).send(d(
|
|
149
149
|
`Query validation failed: ${n.errors.join(", ")}`,
|
|
150
150
|
400
|
|
151
151
|
));
|
|
152
152
|
const s = e.measures?.[0] || e.dimensions?.[0];
|
|
153
153
|
if (!s)
|
|
154
|
-
return r.status(400).send(
|
|
154
|
+
return r.status(400).send(d(
|
|
155
155
|
"No measures or dimensions specified",
|
|
156
156
|
400
|
|
157
157
|
));
|
|
158
|
-
const o = s.split(".")[0],
|
|
159
|
-
return I(e,
|
|
158
|
+
const o = s.split(".")[0], u = await c.generateSQL(o, e, a);
|
|
159
|
+
return I(e, u);
|
|
160
160
|
} catch (e) {
|
|
161
|
-
return t.log.error(e, "SQL generation error"), r.status(500).send(
|
|
161
|
+
return t.log.error(e, "SQL generation error"), r.status(500).send(d(
|
|
162
162
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
163
163
|
500
|
|
164
164
|
));
|
|
165
165
|
}
|
|
166
|
-
}), i.get(`${
|
|
166
|
+
}), i.get(`${m}/sql`, {
|
|
167
167
|
schema: {
|
|
168
168
|
querystring: {
|
|
169
169
|
type: "object",
|
|
@@ -175,28 +175,28 @@ const N = function(i, k, R) {
|
|
|
175
175
|
}
|
|
176
176
|
}, async (t, r) => {
|
|
177
177
|
try {
|
|
178
|
-
const { query: e } = t.query, a = JSON.parse(e), n = await
|
|
178
|
+
const { query: e } = t.query, a = JSON.parse(e), n = await p(t), s = c.validateQuery(a);
|
|
179
179
|
if (!s.isValid)
|
|
180
|
-
return r.status(400).send(
|
|
180
|
+
return r.status(400).send(d(
|
|
181
181
|
`Query validation failed: ${s.errors.join(", ")}`,
|
|
182
182
|
400
|
|
183
183
|
));
|
|
184
184
|
const o = a.measures?.[0] || a.dimensions?.[0];
|
|
185
185
|
if (!o)
|
|
186
|
-
return r.status(400).send(
|
|
186
|
+
return r.status(400).send(d(
|
|
187
187
|
"No measures or dimensions specified",
|
|
188
188
|
400
|
|
189
189
|
));
|
|
190
|
-
const
|
|
191
|
-
return I(a,
|
|
190
|
+
const u = o.split(".")[0], b = await c.generateSQL(u, a, n);
|
|
191
|
+
return I(a, b);
|
|
192
192
|
} catch (e) {
|
|
193
|
-
return t.log.error(e, "SQL generation error"), r.status(500).send(
|
|
193
|
+
return t.log.error(e, "SQL generation error"), r.status(500).send(d(
|
|
194
194
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
195
195
|
500
|
|
196
196
|
));
|
|
197
197
|
}
|
|
198
|
-
}), i.post(`${
|
|
199
|
-
bodyLimit:
|
|
198
|
+
}), i.post(`${m}/dry-run`, {
|
|
199
|
+
bodyLimit: g,
|
|
200
200
|
schema: {
|
|
201
201
|
body: {
|
|
202
202
|
type: "object",
|
|
@@ -205,7 +205,7 @@ const N = function(i, k, R) {
|
|
|
205
205
|
}
|
|
206
206
|
}, async (t, r) => {
|
|
207
207
|
try {
|
|
208
|
-
const e = t.body, a = e.query || e, n = await
|
|
208
|
+
const e = t.body, a = e.query || e, n = await p(t);
|
|
209
209
|
return await M(a, n, c);
|
|
210
210
|
} catch (e) {
|
|
211
211
|
return t.log.error(e, "Dry-run error"), r.status(400).send({
|
|
@@ -213,7 +213,7 @@ const N = function(i, k, R) {
|
|
|
213
213
|
valid: !1
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
|
-
}), i.get(`${
|
|
216
|
+
}), i.get(`${m}/dry-run`, {
|
|
217
217
|
schema: {
|
|
218
218
|
querystring: {
|
|
219
219
|
type: "object",
|
|
@@ -225,7 +225,7 @@ const N = function(i, k, R) {
|
|
|
225
225
|
}
|
|
226
226
|
}, async (t, r) => {
|
|
227
227
|
try {
|
|
228
|
-
const { query: e } = t.query, a = JSON.parse(e), n = await
|
|
228
|
+
const { query: e } = t.query, a = JSON.parse(e), n = await p(t);
|
|
229
229
|
return await M(a, n, c);
|
|
230
230
|
} catch (e) {
|
|
231
231
|
return t.log.error(e, "Dry-run error"), r.status(400).send({
|
|
@@ -233,8 +233,8 @@ const N = function(i, k, R) {
|
|
|
233
233
|
valid: !1
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
-
}), i.post(`${
|
|
237
|
-
bodyLimit:
|
|
236
|
+
}), i.post(`${m}/explain`, {
|
|
237
|
+
bodyLimit: g,
|
|
238
238
|
schema: {
|
|
239
239
|
body: {
|
|
240
240
|
type: "object",
|
|
@@ -243,7 +243,7 @@ const N = function(i, k, R) {
|
|
|
243
243
|
}
|
|
244
244
|
}, async (t, r) => {
|
|
245
245
|
try {
|
|
246
|
-
const e = t.body, a = e.query || e, n = e.options || {}, s = await
|
|
246
|
+
const e = t.body, a = e.query || e, n = e.options || {}, s = await p(t), o = c.validateQuery(a);
|
|
247
247
|
return o.isValid ? await c.explainQuery(a, s, n) : r.status(400).send({
|
|
248
248
|
error: `Query validation failed: ${o.errors.join(", ")}`
|
|
249
249
|
});
|
|
@@ -252,8 +252,8 @@ const N = function(i, k, R) {
|
|
|
252
252
|
error: e instanceof Error ? e.message : "Explain query failed"
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
|
-
}),
|
|
256
|
-
bodyLimit:
|
|
255
|
+
}), f && i.post(`${m}/agent/chat`, {
|
|
256
|
+
bodyLimit: g,
|
|
257
257
|
schema: {
|
|
258
258
|
body: {
|
|
259
259
|
type: "object",
|
|
@@ -262,42 +262,43 @@ const N = function(i, k, R) {
|
|
|
262
262
|
}
|
|
263
263
|
}, async (t, r) => {
|
|
264
264
|
try {
|
|
265
|
-
const { handleAgentChat: e } = await import("../handler-
|
|
265
|
+
const { handleAgentChat: e } = await import("../handler-CbDMdSY5.js"), a = t.body, { message: n, sessionId: s, history: o } = a;
|
|
266
266
|
if (!n || typeof n != "string")
|
|
267
267
|
return r.status(400).send({ error: "message is required and must be a string" });
|
|
268
|
-
let
|
|
269
|
-
if (
|
|
270
|
-
const
|
|
271
|
-
|
|
268
|
+
let u = (f.apiKey || "").trim();
|
|
269
|
+
if (f.allowClientApiKey) {
|
|
270
|
+
const y = t.headers["x-agent-api-key"];
|
|
271
|
+
y && (u = y.trim());
|
|
272
272
|
}
|
|
273
|
-
if (!
|
|
273
|
+
if (!u)
|
|
274
274
|
return r.status(401).send({
|
|
275
275
|
error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."
|
|
276
276
|
});
|
|
277
|
-
const
|
|
277
|
+
const b = await p(t), l = f.buildSystemContext?.(b);
|
|
278
278
|
r.raw.writeHead(200, {
|
|
279
279
|
"Content-Type": "text/event-stream",
|
|
280
280
|
"Cache-Control": "no-cache",
|
|
281
281
|
Connection: "keep-alive"
|
|
282
282
|
});
|
|
283
283
|
try {
|
|
284
|
-
const
|
|
284
|
+
const y = e({
|
|
285
285
|
message: n,
|
|
286
286
|
sessionId: s,
|
|
287
287
|
history: o,
|
|
288
288
|
semanticLayer: c,
|
|
289
|
-
securityContext:
|
|
290
|
-
agentConfig:
|
|
291
|
-
apiKey:
|
|
289
|
+
securityContext: b,
|
|
290
|
+
agentConfig: f,
|
|
291
|
+
apiKey: u,
|
|
292
|
+
systemContext: l
|
|
292
293
|
});
|
|
293
|
-
for await (const h of
|
|
294
|
+
for await (const h of y)
|
|
294
295
|
r.raw.write(`data: ${JSON.stringify(h)}
|
|
295
296
|
|
|
296
297
|
`);
|
|
297
|
-
} catch (
|
|
298
|
+
} catch (y) {
|
|
298
299
|
const h = {
|
|
299
300
|
type: "error",
|
|
300
|
-
data: { message:
|
|
301
|
+
data: { message: y instanceof Error ? y.message : "Stream failed" }
|
|
301
302
|
};
|
|
302
303
|
r.raw.write(`data: ${JSON.stringify(h)}
|
|
303
304
|
|
|
@@ -311,10 +312,10 @@ const N = function(i, k, R) {
|
|
|
311
312
|
error: e instanceof Error ? e.message : "Agent chat failed"
|
|
312
313
|
});
|
|
313
314
|
}
|
|
314
|
-
}),
|
|
315
|
-
const t =
|
|
315
|
+
}), C.enabled !== !1) {
|
|
316
|
+
const t = C.basePath ?? "/mcp";
|
|
316
317
|
i.post(`${t}`, {
|
|
317
|
-
bodyLimit:
|
|
318
|
+
bodyLimit: g,
|
|
318
319
|
schema: {
|
|
319
320
|
body: {
|
|
320
321
|
type: "object",
|
|
@@ -324,7 +325,7 @@ const N = function(i, k, R) {
|
|
|
324
325
|
}, async (r, e) => {
|
|
325
326
|
const a = K(
|
|
326
327
|
r.headers.origin,
|
|
327
|
-
|
|
328
|
+
C.allowedOrigins ? { allowedOrigins: C.allowedOrigins } : {}
|
|
328
329
|
);
|
|
329
330
|
if (!a.valid)
|
|
330
331
|
return e.status(403).send(x(null, -32600, a.reason));
|
|
@@ -340,14 +341,14 @@ const N = function(i, k, R) {
|
|
|
340
341
|
const o = z(r.body);
|
|
341
342
|
if (!o)
|
|
342
343
|
return e.status(400).send(x(null, -32600, "Invalid JSON-RPC 2.0 request"));
|
|
343
|
-
const
|
|
344
|
+
const u = _(n), b = o.method === "initialize";
|
|
344
345
|
try {
|
|
345
|
-
const
|
|
346
|
+
const l = await B(
|
|
346
347
|
o.method,
|
|
347
348
|
o.params,
|
|
348
349
|
{
|
|
349
350
|
semanticLayer: c,
|
|
350
|
-
extractSecurityContext:
|
|
351
|
+
extractSecurityContext: p,
|
|
351
352
|
rawRequest: r,
|
|
352
353
|
rawResponse: e,
|
|
353
354
|
negotiatedProtocol: s.negotiated
|
|
@@ -355,23 +356,23 @@ const N = function(i, k, R) {
|
|
|
355
356
|
);
|
|
356
357
|
if (j(o))
|
|
357
358
|
return e.status(202).send();
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
359
|
+
const y = b && l && typeof l == "object" && "sessionId" in l ? l.sessionId : void 0;
|
|
360
|
+
y && e.header(F, y);
|
|
361
|
+
const h = U(o.id ?? null, l);
|
|
362
|
+
if (u) {
|
|
362
363
|
const w = E();
|
|
363
364
|
e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${w}
|
|
364
365
|
|
|
365
|
-
${P(
|
|
366
|
+
${P(h, w)}`);
|
|
366
367
|
return;
|
|
367
368
|
}
|
|
368
|
-
return e.send(
|
|
369
|
-
} catch (
|
|
369
|
+
return e.send(h);
|
|
370
|
+
} catch (l) {
|
|
370
371
|
if (j(o))
|
|
371
|
-
return r.log.error(
|
|
372
|
-
r.log.error(
|
|
373
|
-
const
|
|
374
|
-
if (
|
|
372
|
+
return r.log.error(l, "MCP notification processing error"), e.status(202).send();
|
|
373
|
+
r.log.error(l, "MCP RPC error");
|
|
374
|
+
const y = l?.code ?? -32603, h = l?.data, w = l.message || "MCP request failed", Q = x(o.id ?? null, y, w, h);
|
|
375
|
+
if (u) {
|
|
375
376
|
const $ = E();
|
|
376
377
|
e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${$}
|
|
377
378
|
|
|
@@ -404,17 +405,17 @@ ${P(Q, $)}`);
|
|
|
404
405
|
i.setErrorHandler(async (t, r, e) => {
|
|
405
406
|
r.log.error(t, "Fastify cube adapter error"), e.statusCode < 400 && e.status(500);
|
|
406
407
|
const a = t instanceof Error ? t : String(t);
|
|
407
|
-
return
|
|
408
|
+
return d(a, e.statusCode);
|
|
408
409
|
}), R();
|
|
409
410
|
};
|
|
410
|
-
async function Z(
|
|
411
|
-
await
|
|
411
|
+
async function Z(v, i) {
|
|
412
|
+
await v.register(N, i);
|
|
412
413
|
}
|
|
413
|
-
function ee(
|
|
414
|
+
function ee(v) {
|
|
414
415
|
const i = require("fastify")({
|
|
415
416
|
logger: !0
|
|
416
417
|
});
|
|
417
|
-
return i.register(N,
|
|
418
|
+
return i.register(N, v), i;
|
|
418
419
|
}
|
|
419
420
|
export {
|
|
420
421
|
ee as createCubeApp,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as H, Q as B, j, D as
|
|
2
|
-
import { handleDiscover as
|
|
1
|
+
import { h as H, Q as B, j, D as U } from "./mcp-transport-m1X1GtwG.js";
|
|
2
|
+
import { handleDiscover as Z, handleLoad as G } from "./utils.js";
|
|
3
3
|
function K(l) {
|
|
4
4
|
if (l.length === 0)
|
|
5
5
|
return "No cubes are currently available.";
|
|
@@ -172,7 +172,7 @@ function W(l) {
|
|
|
172
172
|
"",
|
|
173
173
|
"---",
|
|
174
174
|
"",
|
|
175
|
-
I(
|
|
175
|
+
I(U),
|
|
176
176
|
"",
|
|
177
177
|
"---",
|
|
178
178
|
"",
|
|
@@ -1777,8 +1777,8 @@ function Te(l, t, a) {
|
|
|
1777
1777
|
);
|
|
1778
1778
|
if (x = n.filter((A) => !g.has(A)), x.length === 0) continue;
|
|
1779
1779
|
}
|
|
1780
|
-
const b = s.maxItems ?? 1 / 0,
|
|
1781
|
-
|
|
1780
|
+
const b = s.maxItems ?? 1 / 0, m = x.slice(0, b);
|
|
1781
|
+
m.length > 0 && (d[s.key] = m);
|
|
1782
1782
|
}
|
|
1783
1783
|
return d;
|
|
1784
1784
|
}
|
|
@@ -1798,8 +1798,8 @@ Chart config requirements by type:`];
|
|
|
1798
1798
|
continue;
|
|
1799
1799
|
}
|
|
1800
1800
|
const s = r.map((h) => {
|
|
1801
|
-
const
|
|
1802
|
-
return `${h.key}=[${
|
|
1801
|
+
const y = h.acceptTypes?.join("/") ?? "any", c = h.maxItems ? ` (max ${h.maxItems})` : "";
|
|
1802
|
+
return `${h.key}=[${y}]${c}`;
|
|
1803
1803
|
});
|
|
1804
1804
|
t.push(` ${a}${o} Requires ${s.join(", ")}.`);
|
|
1805
1805
|
}
|
|
@@ -2124,7 +2124,7 @@ The query is validated before adding. The portlet fetches its own data.`,
|
|
|
2124
2124
|
function Se(l) {
|
|
2125
2125
|
const { semanticLayer: t, securityContext: a } = l, i = /* @__PURE__ */ new Map();
|
|
2126
2126
|
i.set("discover_cubes", async (e) => {
|
|
2127
|
-
const o = await
|
|
2127
|
+
const o = await Z(t, {
|
|
2128
2128
|
topic: e.topic,
|
|
2129
2129
|
intent: e.intent,
|
|
2130
2130
|
limit: e.limit,
|
|
@@ -2147,26 +2147,26 @@ function Se(l) {
|
|
|
2147
2147
|
};
|
|
2148
2148
|
return i.set("execute_query", async (e) => {
|
|
2149
2149
|
try {
|
|
2150
|
-
const o = (
|
|
2151
|
-
if (!Array.isArray(
|
|
2150
|
+
const o = (y, c) => {
|
|
2151
|
+
if (!Array.isArray(y)) return;
|
|
2152
2152
|
const n = [], x = [];
|
|
2153
|
-
for (const b of
|
|
2153
|
+
for (const b of y) {
|
|
2154
2154
|
if (typeof b != "string") {
|
|
2155
2155
|
x.push(b);
|
|
2156
2156
|
continue;
|
|
2157
2157
|
}
|
|
2158
|
-
const
|
|
2159
|
-
if (
|
|
2158
|
+
const m = b.split(".");
|
|
2159
|
+
if (m.length === 1) {
|
|
2160
2160
|
n.push(`"${b}" is not valid — must be "CubeName.fieldName".${u(b, c)}`);
|
|
2161
2161
|
continue;
|
|
2162
2162
|
}
|
|
2163
|
-
if (
|
|
2164
|
-
const g = `${
|
|
2163
|
+
if (m.length === 3 && m[0] === m[1]) {
|
|
2164
|
+
const g = `${m[0]}.${m[2]}`;
|
|
2165
2165
|
x.push(g);
|
|
2166
2166
|
continue;
|
|
2167
2167
|
}
|
|
2168
|
-
if (
|
|
2169
|
-
n.push(`"${b}" is WRONG — "${
|
|
2168
|
+
if (m.length === 2 && m[0] === m[1]) {
|
|
2169
|
+
n.push(`"${b}" is WRONG — "${m[0]}" is the cube name, not a ${c.replace(/s$/, "")}.${u(m[0], c)}`);
|
|
2170
2170
|
continue;
|
|
2171
2171
|
}
|
|
2172
2172
|
x.push(b);
|
|
@@ -2178,21 +2178,21 @@ ${n.join(`
|
|
|
2178
2178
|
return x;
|
|
2179
2179
|
};
|
|
2180
2180
|
e.measures = o(e.measures, "measures") ?? e.measures, e.dimensions = o(e.dimensions, "dimensions") ?? e.dimensions;
|
|
2181
|
-
const r = (
|
|
2182
|
-
const c =
|
|
2183
|
-
return c.length === 3 && c[0] === c[1] ? `${c[0]}.${c[2]}` :
|
|
2181
|
+
const r = (y) => {
|
|
2182
|
+
const c = y.split(".");
|
|
2183
|
+
return c.length === 3 && c[0] === c[1] ? `${c[0]}.${c[2]}` : y;
|
|
2184
2184
|
};
|
|
2185
2185
|
if (Array.isArray(e.filters))
|
|
2186
|
-
for (const
|
|
2187
|
-
typeof
|
|
2186
|
+
for (const y of e.filters)
|
|
2187
|
+
typeof y.member == "string" && (y.member = r(y.member));
|
|
2188
2188
|
if (Array.isArray(e.timeDimensions))
|
|
2189
|
-
for (const
|
|
2190
|
-
typeof
|
|
2189
|
+
for (const y of e.timeDimensions)
|
|
2190
|
+
typeof y.dimension == "string" && (y.dimension = r(y.dimension));
|
|
2191
2191
|
if (e.order && typeof e.order == "object" && !Array.isArray(e.order)) {
|
|
2192
|
-
const
|
|
2192
|
+
const y = {};
|
|
2193
2193
|
for (const [c, n] of Object.entries(e.order))
|
|
2194
|
-
|
|
2195
|
-
e.order =
|
|
2194
|
+
y[r(c)] = n;
|
|
2195
|
+
e.order = y;
|
|
2196
2196
|
}
|
|
2197
2197
|
let s;
|
|
2198
2198
|
e.funnel ? s = { funnel: e.funnel } : e.flow ? s = { flow: e.flow } : e.retention ? s = { retention: e.retention } : s = {
|
|
@@ -2256,16 +2256,16 @@ Attempted query:
|
|
|
2256
2256
|
${JSON.stringify(s, null, 2)}`,
|
|
2257
2257
|
isError: !0
|
|
2258
2258
|
};
|
|
2259
|
-
const
|
|
2259
|
+
const y = !!(s.funnel || s.flow || s.retention);
|
|
2260
2260
|
let c;
|
|
2261
|
-
if (
|
|
2261
|
+
if (y)
|
|
2262
2262
|
c = e.chartConfig ?? {};
|
|
2263
2263
|
else {
|
|
2264
|
-
const b = Te(r, e.chartConfig, s),
|
|
2265
|
-
if (!
|
|
2264
|
+
const b = Te(r, e.chartConfig, s), m = Ce(r, b, s);
|
|
2265
|
+
if (!m.isValid)
|
|
2266
2266
|
return {
|
|
2267
2267
|
result: `Chart config invalid — fix these errors and retry:
|
|
2268
|
-
${
|
|
2268
|
+
${m.errors.join(`
|
|
2269
2269
|
`)}`,
|
|
2270
2270
|
isError: !0
|
|
2271
2271
|
};
|
|
@@ -2306,14 +2306,14 @@ ${y.errors.join(`
|
|
|
2306
2306
|
r.push(`Portlet "${n.title}": missing query`);
|
|
2307
2307
|
continue;
|
|
2308
2308
|
}
|
|
2309
|
-
let
|
|
2309
|
+
let m;
|
|
2310
2310
|
try {
|
|
2311
|
-
|
|
2311
|
+
m = JSON.parse(b);
|
|
2312
2312
|
} catch {
|
|
2313
2313
|
r.push(`Portlet "${n.title}": invalid JSON query`);
|
|
2314
2314
|
continue;
|
|
2315
2315
|
}
|
|
2316
|
-
const g = t.validateQuery(
|
|
2316
|
+
const g = t.validateQuery(m);
|
|
2317
2317
|
g.isValid || r.push(`Portlet "${n.title}": ${g.errors.join(", ")}`);
|
|
2318
2318
|
}
|
|
2319
2319
|
if (r.length > 0)
|
|
@@ -2325,7 +2325,7 @@ ${r.join(`
|
|
|
2325
2325
|
};
|
|
2326
2326
|
const s = {
|
|
2327
2327
|
portlets: o.map((n) => {
|
|
2328
|
-
const x = n.chartType, b = x === "markdown",
|
|
2328
|
+
const x = n.chartType, b = x === "markdown", m = b ? "query" : n.analysisType || "query", g = m === "funnel" ? "funnel" : m === "flow" ? "flow" : m === "retention" ? "retention" : "query", A = n.query || "{}";
|
|
2329
2329
|
let C;
|
|
2330
2330
|
try {
|
|
2331
2331
|
C = JSON.parse(A);
|
|
@@ -2358,9 +2358,9 @@ ${r.join(`
|
|
|
2358
2358
|
}),
|
|
2359
2359
|
filters: e.filters,
|
|
2360
2360
|
colorPalette: e.colorPalette
|
|
2361
|
-
}, h = e.title,
|
|
2361
|
+
}, h = e.title, y = s.portlets.length, c = s.filters?.length || 0;
|
|
2362
2362
|
return {
|
|
2363
|
-
result: `Dashboard "${h}" created with ${
|
|
2363
|
+
result: `Dashboard "${h}" created with ${y} portlets and ${c} filters.`,
|
|
2364
2364
|
sideEffect: {
|
|
2365
2365
|
type: "dashboard_saved",
|
|
2366
2366
|
data: {
|
|
@@ -2380,13 +2380,13 @@ ${r.join(`
|
|
|
2380
2380
|
}
|
|
2381
2381
|
async function* _e(l) {
|
|
2382
2382
|
const { message: t, history: a, semanticLayer: i, securityContext: d, agentConfig: u, apiKey: e } = l, o = l.sessionId || crypto.randomUUID(), r = u.observability, s = crypto.randomUUID(), h = Date.now();
|
|
2383
|
-
let
|
|
2383
|
+
let y;
|
|
2384
2384
|
try {
|
|
2385
2385
|
const f = await import(
|
|
2386
2386
|
/* webpackIgnore: true */
|
|
2387
2387
|
"@anthropic-ai/sdk"
|
|
2388
2388
|
);
|
|
2389
|
-
|
|
2389
|
+
y = f.default || f.Anthropic || f;
|
|
2390
2390
|
} catch {
|
|
2391
2391
|
yield {
|
|
2392
2392
|
type: "error",
|
|
@@ -2396,7 +2396,14 @@ async function* _e(l) {
|
|
|
2396
2396
|
};
|
|
2397
2397
|
return;
|
|
2398
2398
|
}
|
|
2399
|
-
const c = new
|
|
2399
|
+
const c = new y({ apiKey: e }), n = De(), x = Se({ semanticLayer: i, securityContext: d }), b = i.getMetadata();
|
|
2400
|
+
let m = W(b);
|
|
2401
|
+
l.systemContext && (m += `
|
|
2402
|
+
|
|
2403
|
+
## User Context
|
|
2404
|
+
|
|
2405
|
+
${l.systemContext}`);
|
|
2406
|
+
const g = u.model || "claude-sonnet-4-6", A = u.maxTurns || 25, C = u.maxTokens || 4096;
|
|
2400
2407
|
try {
|
|
2401
2408
|
r?.onChatStart?.({
|
|
2402
2409
|
traceId: s,
|
|
@@ -2442,7 +2449,7 @@ async function* _e(l) {
|
|
|
2442
2449
|
const F = await c.messages.create({
|
|
2443
2450
|
model: g,
|
|
2444
2451
|
max_tokens: C,
|
|
2445
|
-
system:
|
|
2452
|
+
system: m,
|
|
2446
2453
|
tools: n,
|
|
2447
2454
|
messages: k,
|
|
2448
2455
|
stream: !0
|