drizzle-cube 0.4.17 → 0.4.19
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 +1 -1
- package/dist/adapters/express/index.js +1 -1
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.js +1 -1
- package/dist/adapters/{handler-nTycPMWF.js → handler-BV4JuWNW.js} +338 -272
- package/dist/adapters/{handler-C1rOM9M_.cjs → handler-D4MVKkVy.cjs} +19 -11
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +1 -1
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/server/index.cjs +51 -43
- package/dist/server/index.js +1712 -1646
- package/package.json +1 -1
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { handleDiscover as
|
|
3
|
-
function K(
|
|
4
|
-
if (
|
|
1
|
+
import { h as H, Q as B, j, D as Z } from "./mcp-transport-m1X1GtwG.js";
|
|
2
|
+
import { handleDiscover as U, handleLoad as G } from "./utils.js";
|
|
3
|
+
function K(l) {
|
|
4
|
+
if (l.length === 0)
|
|
5
5
|
return "No cubes are currently available.";
|
|
6
6
|
const t = ["## Available Cubes", ""];
|
|
7
|
-
for (const a of
|
|
7
|
+
for (const a of l) {
|
|
8
8
|
if (t.push(`### ${a.name}`), a.description && t.push(a.description), a.measures && a.measures.length > 0) {
|
|
9
9
|
t.push(""), t.push("**Measures:**");
|
|
10
10
|
for (const i of a.measures) {
|
|
11
|
-
const
|
|
12
|
-
t.push(`- \`${a.name}.${i.name}\` (${i.type})${
|
|
11
|
+
const d = i.description ? ` - ${i.description}` : "";
|
|
12
|
+
t.push(`- \`${a.name}.${i.name}\` (${i.type})${d}`);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
if (a.dimensions && a.dimensions.length > 0) {
|
|
16
16
|
t.push(""), t.push("**Dimensions:**");
|
|
17
17
|
for (const i of a.dimensions) {
|
|
18
|
-
const
|
|
19
|
-
t.push(`- \`${a.name}.${i.name}\` (${i.type})${
|
|
18
|
+
const d = i.description ? ` - ${i.description}` : "";
|
|
19
|
+
t.push(`- \`${a.name}.${i.name}\` (${i.type})${d}`);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
if (a.relationships && a.relationships.length > 0) {
|
|
@@ -29,12 +29,12 @@ function K(o) {
|
|
|
29
29
|
return t.join(`
|
|
30
30
|
`);
|
|
31
31
|
}
|
|
32
|
-
function I(
|
|
33
|
-
return
|
|
32
|
+
function I(l) {
|
|
33
|
+
return l.messages.map((t) => t.content.text).join(`
|
|
34
34
|
|
|
35
35
|
`);
|
|
36
36
|
}
|
|
37
|
-
function W(
|
|
37
|
+
function W(l) {
|
|
38
38
|
return [
|
|
39
39
|
"# Drizzle Cube Analytics Agent",
|
|
40
40
|
"",
|
|
@@ -160,7 +160,7 @@ function W(o) {
|
|
|
160
160
|
"",
|
|
161
161
|
"---",
|
|
162
162
|
"",
|
|
163
|
-
I(
|
|
163
|
+
I(H),
|
|
164
164
|
"",
|
|
165
165
|
"---",
|
|
166
166
|
"",
|
|
@@ -172,7 +172,7 @@ function W(o) {
|
|
|
172
172
|
"",
|
|
173
173
|
"---",
|
|
174
174
|
"",
|
|
175
|
-
I(
|
|
175
|
+
I(Z),
|
|
176
176
|
"",
|
|
177
177
|
"---",
|
|
178
178
|
"",
|
|
@@ -226,7 +226,7 @@ function W(o) {
|
|
|
226
226
|
"",
|
|
227
227
|
"---",
|
|
228
228
|
"",
|
|
229
|
-
K(
|
|
229
|
+
K(l)
|
|
230
230
|
].join(`
|
|
231
231
|
`);
|
|
232
232
|
}
|
|
@@ -769,8 +769,8 @@ const X = {
|
|
|
769
769
|
description: "Automatically size blocks to fill portlet width and height while maintaining aspect ratio"
|
|
770
770
|
}
|
|
771
771
|
],
|
|
772
|
-
validate: (
|
|
773
|
-
const { dateField: t, valueField: a } =
|
|
772
|
+
validate: (l) => {
|
|
773
|
+
const { dateField: t, valueField: a } = l;
|
|
774
774
|
return !t || Array.isArray(t) && t.length === 0 ? {
|
|
775
775
|
isValid: !1,
|
|
776
776
|
message: "Time dimension is required for activity grid"
|
|
@@ -938,7 +938,7 @@ const X = {
|
|
|
938
938
|
}
|
|
939
939
|
],
|
|
940
940
|
displayOptions: ["hideHeader"],
|
|
941
|
-
validate: (
|
|
941
|
+
validate: (l) => !l.yAxis || Array.isArray(l.yAxis) && l.yAxis.length === 0 ? {
|
|
942
942
|
isValid: !1,
|
|
943
943
|
message: "A measure is required for KPI Delta charts"
|
|
944
944
|
} : { isValid: !0 }
|
|
@@ -1335,7 +1335,7 @@ Use --- for horizontal rules.`,
|
|
|
1335
1335
|
description: "Number formatting for cell values and legend"
|
|
1336
1336
|
}
|
|
1337
1337
|
],
|
|
1338
|
-
validate: (
|
|
1338
|
+
validate: (l) => l.xAxis?.length ? l.yAxis?.length ? l.valueField?.length ? { isValid: !0 } : { isValid: !1, message: "Value measure required" } : { isValid: !1, message: "Y-axis dimension required" } : { isValid: !1, message: "X-axis dimension required" }
|
|
1339
1339
|
}, fe = {
|
|
1340
1340
|
label: "Retention Matrix",
|
|
1341
1341
|
// RetentionHeatmap auto-configures from the retention data structure
|
|
@@ -1708,100 +1708,100 @@ Use --- for horizontal rules.`,
|
|
|
1708
1708
|
measureProfile: ke,
|
|
1709
1709
|
gauge: ve
|
|
1710
1710
|
};
|
|
1711
|
-
function Ce(
|
|
1712
|
-
const i = P[
|
|
1711
|
+
function Ce(l, t, a) {
|
|
1712
|
+
const i = P[l];
|
|
1713
1713
|
if (!i)
|
|
1714
1714
|
return { isValid: !0, errors: [] };
|
|
1715
1715
|
if (i.skipQuery)
|
|
1716
1716
|
return { isValid: !0, errors: [] };
|
|
1717
|
-
const
|
|
1718
|
-
for (const
|
|
1719
|
-
if (!
|
|
1720
|
-
const
|
|
1721
|
-
if (!(Array.isArray(
|
|
1722
|
-
const
|
|
1723
|
-
|
|
1724
|
-
`chartConfig.${
|
|
1717
|
+
const d = [];
|
|
1718
|
+
for (const u of i.dropZones) {
|
|
1719
|
+
if (!u.mandatory) continue;
|
|
1720
|
+
const e = t?.[u.key];
|
|
1721
|
+
if (!(Array.isArray(e) ? e.length > 0 : !!e)) {
|
|
1722
|
+
const r = u.acceptTypes?.join("/") ?? "fields";
|
|
1723
|
+
d.push(
|
|
1724
|
+
`chartConfig.${u.key} is required for ${l} chart (${u.label}). Accepts: ${r}.`
|
|
1725
1725
|
);
|
|
1726
1726
|
}
|
|
1727
1727
|
}
|
|
1728
|
-
if (
|
|
1729
|
-
const
|
|
1730
|
-
if (!(Array.isArray(
|
|
1731
|
-
const
|
|
1732
|
-
|
|
1728
|
+
if (l === "bar") {
|
|
1729
|
+
const u = t?.xAxis;
|
|
1730
|
+
if (!(Array.isArray(u) ? u.length > 0 : !!u)) {
|
|
1731
|
+
const o = a.dimensions ?? [], r = a.timeDimensions ?? [];
|
|
1732
|
+
o.length > 0 || r.length > 0 ? d.push(
|
|
1733
1733
|
"chartConfig.xAxis is required for bar charts. Put a dimension in xAxis so bars have category labels."
|
|
1734
|
-
) :
|
|
1734
|
+
) : d.push(
|
|
1735
1735
|
'Bar charts need an xAxis dimension for category labels. Add a dimension to the query or use "table" chart type instead.'
|
|
1736
1736
|
);
|
|
1737
1737
|
}
|
|
1738
1738
|
}
|
|
1739
1739
|
if (t?.xAxis && t?.series) {
|
|
1740
|
-
const
|
|
1740
|
+
const u = new Set(
|
|
1741
1741
|
Array.isArray(t.xAxis) ? t.xAxis : [t.xAxis]
|
|
1742
|
-
),
|
|
1743
|
-
|
|
1744
|
-
`chartConfig.series must not contain the same field as xAxis (found: ${
|
|
1742
|
+
), o = (Array.isArray(t.series) ? t.series : [t.series]).filter((r) => u.has(r));
|
|
1743
|
+
o.length > 0 && d.push(
|
|
1744
|
+
`chartConfig.series must not contain the same field as xAxis (found: ${o.join(", ")}). The series field is only for splitting into grouped/stacked sub-series by a DIFFERENT dimension. Remove the duplicate from series.`
|
|
1745
1745
|
);
|
|
1746
1746
|
}
|
|
1747
|
-
return { isValid:
|
|
1747
|
+
return { isValid: d.length === 0, errors: d };
|
|
1748
1748
|
}
|
|
1749
|
-
function Te(
|
|
1750
|
-
const i = P[
|
|
1749
|
+
function Te(l, t, a) {
|
|
1750
|
+
const i = P[l];
|
|
1751
1751
|
if (!i)
|
|
1752
1752
|
return t ?? {};
|
|
1753
|
-
const
|
|
1754
|
-
for (const
|
|
1755
|
-
const
|
|
1756
|
-
if (Array.isArray(
|
|
1757
|
-
const
|
|
1758
|
-
if (
|
|
1759
|
-
if (
|
|
1753
|
+
const d = { ...t }, u = a.measures ?? [], e = a.dimensions ?? [], r = (a.timeDimensions ?? []).map((s) => s.dimension);
|
|
1754
|
+
for (const s of i.dropZones) {
|
|
1755
|
+
const h = d[s.key];
|
|
1756
|
+
if (Array.isArray(h) ? h.length > 0 : !!h) continue;
|
|
1757
|
+
const c = s.acceptTypes ?? [];
|
|
1758
|
+
if (s.key === "sizeField" || s.key === "colorField") {
|
|
1759
|
+
if (c.includes("measure")) {
|
|
1760
1760
|
const g = /* @__PURE__ */ new Set();
|
|
1761
|
-
for (const
|
|
1762
|
-
if (
|
|
1763
|
-
const
|
|
1764
|
-
Array.isArray(
|
|
1761
|
+
for (const C of i.dropZones) {
|
|
1762
|
+
if (C.key === s.key) continue;
|
|
1763
|
+
const k = d[C.key];
|
|
1764
|
+
Array.isArray(k) ? k.forEach((E) => g.add(E)) : typeof k == "string" && g.add(k);
|
|
1765
1765
|
}
|
|
1766
|
-
const
|
|
1767
|
-
|
|
1766
|
+
const A = u.filter((C) => !g.has(C));
|
|
1767
|
+
A.length > 0 && (d[s.key] = A[0]);
|
|
1768
1768
|
}
|
|
1769
1769
|
continue;
|
|
1770
1770
|
}
|
|
1771
|
-
const
|
|
1772
|
-
if (
|
|
1773
|
-
let
|
|
1774
|
-
if (
|
|
1771
|
+
const n = [];
|
|
1772
|
+
if (c.includes("dimension") && n.push(...e), c.includes("timeDimension") && n.push(...r), c.includes("measure") && n.push(...u), n.length === 0) continue;
|
|
1773
|
+
let x = n;
|
|
1774
|
+
if (s.key === "series") {
|
|
1775
1775
|
const g = new Set(
|
|
1776
|
-
Array.isArray(
|
|
1776
|
+
Array.isArray(d.xAxis) ? d.xAxis : d.xAxis ? [d.xAxis] : []
|
|
1777
1777
|
);
|
|
1778
|
-
if (
|
|
1778
|
+
if (x = n.filter((A) => !g.has(A)), x.length === 0) continue;
|
|
1779
1779
|
}
|
|
1780
|
-
const
|
|
1781
|
-
|
|
1780
|
+
const b = s.maxItems ?? 1 / 0, y = x.slice(0, b);
|
|
1781
|
+
y.length > 0 && (d[s.key] = y);
|
|
1782
1782
|
}
|
|
1783
|
-
return
|
|
1783
|
+
return d;
|
|
1784
1784
|
}
|
|
1785
|
-
function Ae(
|
|
1785
|
+
function Ae(l) {
|
|
1786
1786
|
const t = [`
|
|
1787
1787
|
Chart config requirements by type:`];
|
|
1788
|
-
for (const a of
|
|
1788
|
+
for (const a of l) {
|
|
1789
1789
|
const i = P[a];
|
|
1790
1790
|
if (!i) continue;
|
|
1791
|
-
const
|
|
1792
|
-
if (
|
|
1793
|
-
t.push(` ${a}${
|
|
1791
|
+
const d = i.description ?? "", u = i.useCase ?? "", e = [d, u].filter(Boolean).join(". "), o = e ? ` — ${e}.` : "", r = i.dropZones.filter((h) => h.mandatory);
|
|
1792
|
+
if (r.length === 0 && !i.skipQuery) {
|
|
1793
|
+
t.push(` ${a}${o} chartConfig auto-inferred from query.`);
|
|
1794
1794
|
continue;
|
|
1795
1795
|
}
|
|
1796
1796
|
if (i.skipQuery) {
|
|
1797
|
-
t.push(` ${a}${
|
|
1797
|
+
t.push(` ${a}${o} No query needed.`);
|
|
1798
1798
|
continue;
|
|
1799
1799
|
}
|
|
1800
|
-
const
|
|
1801
|
-
const
|
|
1802
|
-
return `${
|
|
1800
|
+
const s = r.map((h) => {
|
|
1801
|
+
const m = h.acceptTypes?.join("/") ?? "any", c = h.maxItems ? ` (max ${h.maxItems})` : "";
|
|
1802
|
+
return `${h.key}=[${m}]${c}`;
|
|
1803
1803
|
});
|
|
1804
|
-
t.push(` ${a}${
|
|
1804
|
+
t.push(` ${a}${o} Requires ${s.join(", ")}.`);
|
|
1805
1805
|
}
|
|
1806
1806
|
return t.join(`
|
|
1807
1807
|
`);
|
|
@@ -2121,32 +2121,81 @@ The query is validated before adding. The portlet fetches its own data.`,
|
|
|
2121
2121
|
}
|
|
2122
2122
|
];
|
|
2123
2123
|
}
|
|
2124
|
-
function Se(
|
|
2125
|
-
const { semanticLayer: t, securityContext: a } =
|
|
2126
|
-
|
|
2127
|
-
const
|
|
2124
|
+
function Se(l) {
|
|
2125
|
+
const { semanticLayer: t, securityContext: a } = l, i = /* @__PURE__ */ new Map();
|
|
2126
|
+
i.set("discover_cubes", async (e) => {
|
|
2127
|
+
const o = await U(t, {
|
|
2128
2128
|
topic: e.topic,
|
|
2129
2129
|
intent: e.intent,
|
|
2130
2130
|
limit: e.limit,
|
|
2131
2131
|
minScore: e.minScore
|
|
2132
2132
|
});
|
|
2133
|
-
return { result: JSON.stringify(
|
|
2133
|
+
return { result: JSON.stringify(o, null, 2) };
|
|
2134
2134
|
}), i.set("get_cube_metadata", async () => {
|
|
2135
2135
|
const e = t.getMetadata();
|
|
2136
2136
|
return { result: JSON.stringify(e, null, 2) };
|
|
2137
|
-
})
|
|
2137
|
+
});
|
|
2138
|
+
const d = /* @__PURE__ */ new Map();
|
|
2139
|
+
for (const e of t.getMetadata())
|
|
2140
|
+
d.set(e.name, {
|
|
2141
|
+
measures: (e.measures || []).map((o) => o.name),
|
|
2142
|
+
dimensions: (e.dimensions || []).map((o) => o.name)
|
|
2143
|
+
});
|
|
2144
|
+
const u = (e, o) => {
|
|
2145
|
+
const r = d.get(e), s = o === "measures" ? r?.measures : r?.dimensions;
|
|
2146
|
+
return !s || s.length === 0 ? "" : ` Available ${o}: ${s.slice(0, 5).map((h) => `"${h}"`).join(", ")}`;
|
|
2147
|
+
};
|
|
2148
|
+
return i.set("execute_query", async (e) => {
|
|
2138
2149
|
try {
|
|
2139
|
-
const
|
|
2140
|
-
if (!Array.isArray(
|
|
2141
|
-
const
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2150
|
+
const o = (m, c) => {
|
|
2151
|
+
if (!Array.isArray(m)) return;
|
|
2152
|
+
const n = [], x = [];
|
|
2153
|
+
for (const b of m) {
|
|
2154
|
+
if (typeof b != "string") {
|
|
2155
|
+
x.push(b);
|
|
2156
|
+
continue;
|
|
2157
|
+
}
|
|
2158
|
+
const y = b.split(".");
|
|
2159
|
+
if (y.length === 1) {
|
|
2160
|
+
n.push(`"${b}" is not valid — must be "CubeName.fieldName".${u(b, c)}`);
|
|
2161
|
+
continue;
|
|
2162
|
+
}
|
|
2163
|
+
if (y.length === 3 && y[0] === y[1]) {
|
|
2164
|
+
const g = `${y[0]}.${y[2]}`;
|
|
2165
|
+
x.push(g);
|
|
2166
|
+
continue;
|
|
2167
|
+
}
|
|
2168
|
+
if (y.length === 2 && y[0] === y[1]) {
|
|
2169
|
+
n.push(`"${b}" is WRONG — "${y[0]}" is the cube name, not a ${c.replace(/s$/, "")}.${u(y[0], c)}`);
|
|
2170
|
+
continue;
|
|
2171
|
+
}
|
|
2172
|
+
x.push(b);
|
|
2173
|
+
}
|
|
2174
|
+
if (n.length > 0)
|
|
2175
|
+
throw new Error(`Invalid ${c}:
|
|
2176
|
+
${n.join(`
|
|
2177
|
+
`)}`);
|
|
2178
|
+
return x;
|
|
2146
2179
|
};
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2180
|
+
e.measures = o(e.measures, "measures") ?? e.measures, e.dimensions = o(e.dimensions, "dimensions") ?? e.dimensions;
|
|
2181
|
+
const r = (m) => {
|
|
2182
|
+
const c = m.split(".");
|
|
2183
|
+
return c.length === 3 && c[0] === c[1] ? `${c[0]}.${c[2]}` : m;
|
|
2184
|
+
};
|
|
2185
|
+
if (Array.isArray(e.filters))
|
|
2186
|
+
for (const m of e.filters)
|
|
2187
|
+
typeof m.member == "string" && (m.member = r(m.member));
|
|
2188
|
+
if (Array.isArray(e.timeDimensions))
|
|
2189
|
+
for (const m of e.timeDimensions)
|
|
2190
|
+
typeof m.dimension == "string" && (m.dimension = r(m.dimension));
|
|
2191
|
+
if (e.order && typeof e.order == "object" && !Array.isArray(e.order)) {
|
|
2192
|
+
const m = {};
|
|
2193
|
+
for (const [c, n] of Object.entries(e.order))
|
|
2194
|
+
m[r(c)] = n;
|
|
2195
|
+
e.order = m;
|
|
2196
|
+
}
|
|
2197
|
+
let s;
|
|
2198
|
+
e.funnel ? s = { funnel: e.funnel } : e.flow ? s = { flow: e.flow } : e.retention ? s = { retention: e.retention } : s = {
|
|
2150
2199
|
measures: e.measures,
|
|
2151
2200
|
dimensions: e.dimensions,
|
|
2152
2201
|
filters: e.filters,
|
|
@@ -2154,135 +2203,152 @@ function Se(o) {
|
|
|
2154
2203
|
order: e.order,
|
|
2155
2204
|
limit: e.limit
|
|
2156
2205
|
};
|
|
2157
|
-
const
|
|
2206
|
+
const h = await G(t, a, { query: s });
|
|
2158
2207
|
return {
|
|
2159
2208
|
result: JSON.stringify({
|
|
2160
|
-
rowCount:
|
|
2161
|
-
data:
|
|
2162
|
-
annotation:
|
|
2209
|
+
rowCount: h.data.length,
|
|
2210
|
+
data: h.data,
|
|
2211
|
+
annotation: h.annotation
|
|
2163
2212
|
}, null, 2)
|
|
2164
2213
|
};
|
|
2165
|
-
} catch (
|
|
2214
|
+
} catch (o) {
|
|
2215
|
+
const r = {
|
|
2216
|
+
measures: e.measures,
|
|
2217
|
+
dimensions: e.dimensions,
|
|
2218
|
+
filters: e.filters,
|
|
2219
|
+
timeDimensions: e.timeDimensions,
|
|
2220
|
+
order: e.order,
|
|
2221
|
+
limit: e.limit,
|
|
2222
|
+
...e.funnel ? { funnel: e.funnel } : {},
|
|
2223
|
+
...e.flow ? { flow: e.flow } : {},
|
|
2224
|
+
...e.retention ? { retention: e.retention } : {}
|
|
2225
|
+
};
|
|
2166
2226
|
return {
|
|
2167
|
-
result: `Query execution failed: ${
|
|
2227
|
+
result: `Query execution failed: ${o instanceof Error ? o.message : "Unknown error"}
|
|
2228
|
+
|
|
2229
|
+
Attempted query:
|
|
2230
|
+
${JSON.stringify(r, null, 2)}`,
|
|
2168
2231
|
isError: !0
|
|
2169
2232
|
};
|
|
2170
2233
|
}
|
|
2171
2234
|
}), i.set("add_portlet", async (e) => {
|
|
2172
|
-
const
|
|
2235
|
+
const r = {
|
|
2173
2236
|
number: "kpiNumber",
|
|
2174
2237
|
retention: "retentionHeatmap"
|
|
2175
2238
|
}[e.chartType] ?? e.chartType;
|
|
2176
|
-
let
|
|
2239
|
+
let s;
|
|
2177
2240
|
try {
|
|
2178
|
-
|
|
2241
|
+
s = JSON.parse(e.query);
|
|
2179
2242
|
} catch {
|
|
2180
2243
|
return {
|
|
2181
2244
|
result: "Invalid query: could not parse JSON string. Ensure `query` is a valid JSON string.",
|
|
2182
2245
|
isError: !0
|
|
2183
2246
|
};
|
|
2184
2247
|
}
|
|
2185
|
-
const
|
|
2186
|
-
if (!
|
|
2248
|
+
const h = t.validateQuery(s);
|
|
2249
|
+
if (!h.isValid)
|
|
2187
2250
|
return {
|
|
2188
2251
|
result: `Invalid query — fix these errors and retry:
|
|
2189
|
-
${
|
|
2190
|
-
`)}
|
|
2252
|
+
${h.errors.join(`
|
|
2253
|
+
`)}
|
|
2254
|
+
|
|
2255
|
+
Attempted query:
|
|
2256
|
+
${JSON.stringify(s, null, 2)}`,
|
|
2191
2257
|
isError: !0
|
|
2192
2258
|
};
|
|
2193
|
-
const
|
|
2194
|
-
let
|
|
2195
|
-
if (
|
|
2196
|
-
|
|
2259
|
+
const m = !!(s.funnel || s.flow || s.retention);
|
|
2260
|
+
let c;
|
|
2261
|
+
if (m)
|
|
2262
|
+
c = e.chartConfig ?? {};
|
|
2197
2263
|
else {
|
|
2198
|
-
const
|
|
2199
|
-
if (!
|
|
2264
|
+
const b = Te(r, e.chartConfig, s), y = Ce(r, b, s);
|
|
2265
|
+
if (!y.isValid)
|
|
2200
2266
|
return {
|
|
2201
2267
|
result: `Chart config invalid — fix these errors and retry:
|
|
2202
|
-
${
|
|
2268
|
+
${y.errors.join(`
|
|
2203
2269
|
`)}`,
|
|
2204
2270
|
isError: !0
|
|
2205
2271
|
};
|
|
2206
|
-
|
|
2272
|
+
c = b;
|
|
2207
2273
|
}
|
|
2208
|
-
const n = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
2274
|
+
const n = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, x = {
|
|
2209
2275
|
id: n,
|
|
2210
2276
|
title: e.title,
|
|
2211
2277
|
query: e.query,
|
|
2212
|
-
chartType:
|
|
2213
|
-
chartConfig:
|
|
2278
|
+
chartType: r,
|
|
2279
|
+
chartConfig: c,
|
|
2214
2280
|
displayConfig: e.displayConfig
|
|
2215
2281
|
};
|
|
2216
2282
|
return {
|
|
2217
|
-
result: `Portlet "${e.title}" added to notebook (id: ${n}, chart: ${
|
|
2218
|
-
sideEffect: { type: "add_portlet", data:
|
|
2283
|
+
result: `Portlet "${e.title}" added to notebook (id: ${n}, chart: ${r}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
|
|
2284
|
+
sideEffect: { type: "add_portlet", data: x }
|
|
2219
2285
|
};
|
|
2220
2286
|
}), i.set("add_markdown", async (e) => {
|
|
2221
|
-
const
|
|
2222
|
-
id:
|
|
2287
|
+
const o = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, r = {
|
|
2288
|
+
id: o,
|
|
2223
2289
|
title: e.title,
|
|
2224
2290
|
content: e.content
|
|
2225
2291
|
};
|
|
2226
2292
|
return {
|
|
2227
|
-
result: `Markdown block added to notebook (id: ${
|
|
2228
|
-
sideEffect: { type: "add_markdown", data:
|
|
2293
|
+
result: `Markdown block added to notebook (id: ${o}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,
|
|
2294
|
+
sideEffect: { type: "add_markdown", data: r }
|
|
2229
2295
|
};
|
|
2230
2296
|
}), i.set("save_as_dashboard", async (e) => {
|
|
2231
2297
|
try {
|
|
2232
|
-
const
|
|
2233
|
-
if (!
|
|
2298
|
+
const o = e.portlets;
|
|
2299
|
+
if (!o || o.length === 0)
|
|
2234
2300
|
return { result: "Dashboard must contain at least one portlet.", isError: !0 };
|
|
2235
|
-
const
|
|
2236
|
-
for (const n of
|
|
2301
|
+
const r = [];
|
|
2302
|
+
for (const n of o) {
|
|
2237
2303
|
if (n.chartType === "markdown") continue;
|
|
2238
|
-
const
|
|
2239
|
-
if (!
|
|
2240
|
-
|
|
2304
|
+
const b = n.query;
|
|
2305
|
+
if (!b) {
|
|
2306
|
+
r.push(`Portlet "${n.title}": missing query`);
|
|
2241
2307
|
continue;
|
|
2242
2308
|
}
|
|
2243
|
-
let
|
|
2309
|
+
let y;
|
|
2244
2310
|
try {
|
|
2245
|
-
|
|
2311
|
+
y = JSON.parse(b);
|
|
2246
2312
|
} catch {
|
|
2247
|
-
|
|
2313
|
+
r.push(`Portlet "${n.title}": invalid JSON query`);
|
|
2248
2314
|
continue;
|
|
2249
2315
|
}
|
|
2250
|
-
const
|
|
2251
|
-
|
|
2316
|
+
const g = t.validateQuery(y);
|
|
2317
|
+
g.isValid || r.push(`Portlet "${n.title}": ${g.errors.join(", ")}`);
|
|
2252
2318
|
}
|
|
2253
|
-
if (
|
|
2319
|
+
if (r.length > 0)
|
|
2254
2320
|
return {
|
|
2255
2321
|
result: `Dashboard has invalid portlets — fix these errors and retry:
|
|
2256
|
-
${
|
|
2322
|
+
${r.join(`
|
|
2257
2323
|
`)}`,
|
|
2258
2324
|
isError: !0
|
|
2259
2325
|
};
|
|
2260
|
-
const
|
|
2261
|
-
portlets:
|
|
2262
|
-
const
|
|
2263
|
-
let
|
|
2326
|
+
const s = {
|
|
2327
|
+
portlets: o.map((n) => {
|
|
2328
|
+
const x = n.chartType, b = x === "markdown", y = b ? "query" : n.analysisType || "query", g = y === "funnel" ? "funnel" : y === "flow" ? "flow" : y === "retention" ? "retention" : "query", A = n.query || "{}";
|
|
2329
|
+
let C;
|
|
2264
2330
|
try {
|
|
2265
|
-
|
|
2331
|
+
C = JSON.parse(A);
|
|
2266
2332
|
} catch {
|
|
2267
|
-
|
|
2333
|
+
C = {};
|
|
2268
2334
|
}
|
|
2269
|
-
const
|
|
2335
|
+
const k = {
|
|
2270
2336
|
version: 1,
|
|
2271
|
-
analysisType:
|
|
2337
|
+
analysisType: g,
|
|
2272
2338
|
activeView: "chart",
|
|
2273
2339
|
charts: {
|
|
2274
|
-
[
|
|
2275
|
-
chartType:
|
|
2340
|
+
[g]: {
|
|
2341
|
+
chartType: x,
|
|
2276
2342
|
chartConfig: n.chartConfig || {},
|
|
2277
2343
|
displayConfig: n.displayConfig || {}
|
|
2278
2344
|
}
|
|
2279
2345
|
},
|
|
2280
|
-
query:
|
|
2346
|
+
query: b ? {} : C
|
|
2281
2347
|
};
|
|
2282
2348
|
return {
|
|
2283
2349
|
id: n.id,
|
|
2284
2350
|
title: n.title,
|
|
2285
|
-
analysisConfig:
|
|
2351
|
+
analysisConfig: k,
|
|
2286
2352
|
dashboardFilterMapping: n.dashboardFilterMapping,
|
|
2287
2353
|
w: n.w,
|
|
2288
2354
|
h: n.h,
|
|
@@ -2292,35 +2358,35 @@ ${l.join(`
|
|
|
2292
2358
|
}),
|
|
2293
2359
|
filters: e.filters,
|
|
2294
2360
|
colorPalette: e.colorPalette
|
|
2295
|
-
},
|
|
2361
|
+
}, h = e.title, m = s.portlets.length, c = s.filters?.length || 0;
|
|
2296
2362
|
return {
|
|
2297
|
-
result: `Dashboard "${
|
|
2363
|
+
result: `Dashboard "${h}" created with ${m} portlets and ${c} filters.`,
|
|
2298
2364
|
sideEffect: {
|
|
2299
2365
|
type: "dashboard_saved",
|
|
2300
2366
|
data: {
|
|
2301
|
-
title:
|
|
2367
|
+
title: h,
|
|
2302
2368
|
description: e.description,
|
|
2303
|
-
dashboardConfig:
|
|
2369
|
+
dashboardConfig: s
|
|
2304
2370
|
}
|
|
2305
2371
|
}
|
|
2306
2372
|
};
|
|
2307
|
-
} catch (
|
|
2373
|
+
} catch (o) {
|
|
2308
2374
|
return {
|
|
2309
|
-
result: `Failed to save dashboard: ${
|
|
2375
|
+
result: `Failed to save dashboard: ${o instanceof Error ? o.message : "Unknown error"}`,
|
|
2310
2376
|
isError: !0
|
|
2311
2377
|
};
|
|
2312
2378
|
}
|
|
2313
2379
|
}), i;
|
|
2314
2380
|
}
|
|
2315
|
-
async function*
|
|
2316
|
-
const { message: t, history: a, semanticLayer: i, securityContext:
|
|
2317
|
-
let
|
|
2381
|
+
async function* _e(l) {
|
|
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 m;
|
|
2318
2384
|
try {
|
|
2319
|
-
const
|
|
2385
|
+
const f = await import(
|
|
2320
2386
|
/* webpackIgnore: true */
|
|
2321
2387
|
"@anthropic-ai/sdk"
|
|
2322
2388
|
);
|
|
2323
|
-
|
|
2389
|
+
m = f.default || f.Anthropic || f;
|
|
2324
2390
|
} catch {
|
|
2325
2391
|
yield {
|
|
2326
2392
|
type: "error",
|
|
@@ -2330,171 +2396,171 @@ async function* Ee(o) {
|
|
|
2330
2396
|
};
|
|
2331
2397
|
return;
|
|
2332
2398
|
}
|
|
2333
|
-
const
|
|
2399
|
+
const c = new m({ apiKey: e }), n = De(), x = Se({ semanticLayer: i, securityContext: d }), b = i.getMetadata(), y = W(b), g = u.model || "claude-sonnet-4-6", A = u.maxTurns || 25, C = u.maxTokens || 4096;
|
|
2334
2400
|
try {
|
|
2335
|
-
|
|
2336
|
-
traceId:
|
|
2337
|
-
sessionId:
|
|
2401
|
+
r?.onChatStart?.({
|
|
2402
|
+
traceId: s,
|
|
2403
|
+
sessionId: o,
|
|
2338
2404
|
message: t,
|
|
2339
2405
|
model: g,
|
|
2340
2406
|
historyLength: a?.length ?? 0
|
|
2341
2407
|
});
|
|
2342
2408
|
} catch {
|
|
2343
2409
|
}
|
|
2344
|
-
const
|
|
2410
|
+
const k = [];
|
|
2345
2411
|
if (a && a.length > 0) {
|
|
2346
|
-
for (const
|
|
2347
|
-
if (
|
|
2348
|
-
|
|
2349
|
-
else if (
|
|
2412
|
+
for (const f of a)
|
|
2413
|
+
if (f.role === "user")
|
|
2414
|
+
k.push({ role: "user", content: f.content });
|
|
2415
|
+
else if (f.role === "assistant") {
|
|
2350
2416
|
const F = [];
|
|
2351
|
-
if (
|
|
2352
|
-
for (const
|
|
2417
|
+
if (f.content && F.push({ type: "text", text: f.content }), f.toolCalls && f.toolCalls.length > 0) {
|
|
2418
|
+
for (const w of f.toolCalls)
|
|
2353
2419
|
F.push({
|
|
2354
2420
|
type: "tool_use",
|
|
2355
|
-
id:
|
|
2356
|
-
name:
|
|
2357
|
-
input:
|
|
2421
|
+
id: w.id,
|
|
2422
|
+
name: w.name,
|
|
2423
|
+
input: w.input || {}
|
|
2358
2424
|
});
|
|
2359
|
-
|
|
2425
|
+
k.push({ role: "assistant", content: F }), k.push({
|
|
2360
2426
|
role: "user",
|
|
2361
|
-
content:
|
|
2427
|
+
content: f.toolCalls.map((w) => ({
|
|
2362
2428
|
type: "tool_result",
|
|
2363
|
-
tool_use_id:
|
|
2364
|
-
content: typeof
|
|
2365
|
-
...
|
|
2429
|
+
tool_use_id: w.id,
|
|
2430
|
+
content: typeof w.result == "string" ? w.result : JSON.stringify(w.result ?? ""),
|
|
2431
|
+
...w.status === "error" ? { is_error: !0 } : {}
|
|
2366
2432
|
}))
|
|
2367
2433
|
});
|
|
2368
|
-
} else F.length > 0 &&
|
|
2434
|
+
} else F.length > 0 && k.push({ role: "assistant", content: f.content });
|
|
2369
2435
|
}
|
|
2370
2436
|
}
|
|
2371
|
-
|
|
2372
|
-
let
|
|
2437
|
+
k.push({ role: "user", content: t });
|
|
2438
|
+
let E = 0;
|
|
2373
2439
|
try {
|
|
2374
|
-
for (let
|
|
2375
|
-
|
|
2376
|
-
const F = await
|
|
2440
|
+
for (let f = 0; f < A; f++) {
|
|
2441
|
+
E = f + 1;
|
|
2442
|
+
const F = await c.messages.create({
|
|
2377
2443
|
model: g,
|
|
2378
|
-
max_tokens:
|
|
2379
|
-
system:
|
|
2380
|
-
tools:
|
|
2381
|
-
messages:
|
|
2444
|
+
max_tokens: C,
|
|
2445
|
+
system: y,
|
|
2446
|
+
tools: n,
|
|
2447
|
+
messages: k,
|
|
2382
2448
|
stream: !0
|
|
2383
|
-
}),
|
|
2384
|
-
let q = -1,
|
|
2385
|
-
const
|
|
2386
|
-
for await (const
|
|
2387
|
-
switch (
|
|
2449
|
+
}), w = [];
|
|
2450
|
+
let q = -1, V = "", O = "", L, M;
|
|
2451
|
+
const z = Date.now();
|
|
2452
|
+
for await (const v of F)
|
|
2453
|
+
switch (v.type) {
|
|
2388
2454
|
case "content_block_start": {
|
|
2389
2455
|
q++;
|
|
2390
|
-
const
|
|
2391
|
-
|
|
2456
|
+
const p = v.content_block;
|
|
2457
|
+
p.type === "tool_use" ? (w.push({ type: "tool_use", id: p.id, name: p.name, input: {} }), V = "", yield {
|
|
2392
2458
|
type: "tool_use_start",
|
|
2393
|
-
data: { id:
|
|
2394
|
-
}) :
|
|
2459
|
+
data: { id: p.id, name: p.name, input: void 0 }
|
|
2460
|
+
}) : p.type === "text" && w.push({ type: "text", text: "" });
|
|
2395
2461
|
break;
|
|
2396
2462
|
}
|
|
2397
2463
|
case "content_block_delta": {
|
|
2398
|
-
const
|
|
2399
|
-
if (
|
|
2400
|
-
const
|
|
2401
|
-
|
|
2402
|
-
} else
|
|
2464
|
+
const p = v.delta;
|
|
2465
|
+
if (p.type === "text_delta" && p.text) {
|
|
2466
|
+
const D = w[q];
|
|
2467
|
+
D && (D.text = (D.text || "") + p.text), yield { type: "text_delta", data: p.text };
|
|
2468
|
+
} else p.type === "input_json_delta" && p.partial_json && (V += p.partial_json);
|
|
2403
2469
|
break;
|
|
2404
2470
|
}
|
|
2405
2471
|
case "content_block_stop": {
|
|
2406
|
-
const
|
|
2407
|
-
if (
|
|
2472
|
+
const p = w[q];
|
|
2473
|
+
if (p?.type === "tool_use" && V) {
|
|
2408
2474
|
try {
|
|
2409
|
-
|
|
2475
|
+
p.input = JSON.parse(V);
|
|
2410
2476
|
} catch {
|
|
2411
|
-
|
|
2477
|
+
p.input = {};
|
|
2412
2478
|
}
|
|
2413
|
-
|
|
2479
|
+
V = "";
|
|
2414
2480
|
}
|
|
2415
2481
|
break;
|
|
2416
2482
|
}
|
|
2417
2483
|
case "message_start": {
|
|
2418
|
-
const
|
|
2419
|
-
|
|
2484
|
+
const p = v.message;
|
|
2485
|
+
p?.usage?.input_tokens != null && (L = p.usage.input_tokens);
|
|
2420
2486
|
break;
|
|
2421
2487
|
}
|
|
2422
2488
|
case "message_delta": {
|
|
2423
|
-
const
|
|
2424
|
-
|
|
2489
|
+
const p = v.delta, D = v.usage;
|
|
2490
|
+
D?.output_tokens != null && (M = D.output_tokens), p.stop_reason && (O = p.stop_reason);
|
|
2425
2491
|
break;
|
|
2426
2492
|
}
|
|
2427
2493
|
}
|
|
2428
2494
|
try {
|
|
2429
|
-
|
|
2430
|
-
traceId:
|
|
2431
|
-
turn:
|
|
2495
|
+
r?.onGenerationEnd?.({
|
|
2496
|
+
traceId: s,
|
|
2497
|
+
turn: f,
|
|
2432
2498
|
model: g,
|
|
2433
2499
|
stopReason: O,
|
|
2434
2500
|
inputTokens: L,
|
|
2435
|
-
outputTokens:
|
|
2436
|
-
durationMs: Date.now() -
|
|
2501
|
+
outputTokens: M,
|
|
2502
|
+
durationMs: Date.now() - z
|
|
2437
2503
|
});
|
|
2438
2504
|
} catch {
|
|
2439
2505
|
}
|
|
2440
|
-
if (
|
|
2506
|
+
if (k.push({ role: "assistant", content: w }), O !== "tool_use")
|
|
2441
2507
|
break;
|
|
2442
|
-
const
|
|
2443
|
-
for (const
|
|
2444
|
-
if (
|
|
2445
|
-
const
|
|
2446
|
-
if (!
|
|
2447
|
-
|
|
2508
|
+
const _ = [];
|
|
2509
|
+
for (const v of w) {
|
|
2510
|
+
if (v.type !== "tool_use") continue;
|
|
2511
|
+
const p = v.name, D = v.input || {}, S = v.id, R = x.get(p);
|
|
2512
|
+
if (!R) {
|
|
2513
|
+
_.push({
|
|
2448
2514
|
type: "tool_result",
|
|
2449
|
-
tool_use_id:
|
|
2450
|
-
content: `Unknown tool: ${
|
|
2515
|
+
tool_use_id: S,
|
|
2516
|
+
content: `Unknown tool: ${p}`,
|
|
2451
2517
|
is_error: !0
|
|
2452
2518
|
}), yield {
|
|
2453
2519
|
type: "tool_use_result",
|
|
2454
|
-
data: { id:
|
|
2520
|
+
data: { id: S, name: p, result: `Unknown tool: ${p}`, isError: !0 }
|
|
2455
2521
|
};
|
|
2456
2522
|
continue;
|
|
2457
2523
|
}
|
|
2458
2524
|
const Y = Date.now();
|
|
2459
2525
|
try {
|
|
2460
|
-
const
|
|
2461
|
-
|
|
2526
|
+
const T = await R(D);
|
|
2527
|
+
T.sideEffect && (yield T.sideEffect), _.push({
|
|
2462
2528
|
type: "tool_result",
|
|
2463
|
-
tool_use_id:
|
|
2464
|
-
content:
|
|
2465
|
-
...
|
|
2529
|
+
tool_use_id: S,
|
|
2530
|
+
content: T.result,
|
|
2531
|
+
...T.isError ? { is_error: !0 } : {}
|
|
2466
2532
|
}), yield {
|
|
2467
2533
|
type: "tool_use_result",
|
|
2468
|
-
data: { id:
|
|
2534
|
+
data: { id: S, name: p, result: T.result, ...T.isError ? { isError: !0 } : {} }
|
|
2469
2535
|
};
|
|
2470
2536
|
try {
|
|
2471
|
-
|
|
2472
|
-
traceId:
|
|
2473
|
-
turn:
|
|
2474
|
-
toolName:
|
|
2475
|
-
toolUseId:
|
|
2476
|
-
isError: !!
|
|
2537
|
+
r?.onToolEnd?.({
|
|
2538
|
+
traceId: s,
|
|
2539
|
+
turn: f,
|
|
2540
|
+
toolName: p,
|
|
2541
|
+
toolUseId: S,
|
|
2542
|
+
isError: !!T.isError,
|
|
2477
2543
|
durationMs: Date.now() - Y
|
|
2478
2544
|
});
|
|
2479
2545
|
} catch {
|
|
2480
2546
|
}
|
|
2481
|
-
} catch (
|
|
2482
|
-
const
|
|
2483
|
-
|
|
2547
|
+
} catch (T) {
|
|
2548
|
+
const $ = T instanceof Error ? T.message : "Tool execution failed";
|
|
2549
|
+
_.push({
|
|
2484
2550
|
type: "tool_result",
|
|
2485
|
-
tool_use_id:
|
|
2486
|
-
content:
|
|
2551
|
+
tool_use_id: S,
|
|
2552
|
+
content: $,
|
|
2487
2553
|
is_error: !0
|
|
2488
2554
|
}), yield {
|
|
2489
2555
|
type: "tool_use_result",
|
|
2490
|
-
data: { id:
|
|
2556
|
+
data: { id: S, name: p, result: $, isError: !0 }
|
|
2491
2557
|
};
|
|
2492
2558
|
try {
|
|
2493
|
-
|
|
2494
|
-
traceId:
|
|
2495
|
-
turn:
|
|
2496
|
-
toolName:
|
|
2497
|
-
toolUseId:
|
|
2559
|
+
r?.onToolEnd?.({
|
|
2560
|
+
traceId: s,
|
|
2561
|
+
turn: f,
|
|
2562
|
+
toolName: p,
|
|
2563
|
+
toolUseId: S,
|
|
2498
2564
|
isError: !0,
|
|
2499
2565
|
durationMs: Date.now() - Y
|
|
2500
2566
|
});
|
|
@@ -2502,60 +2568,60 @@ async function* Ee(o) {
|
|
|
2502
2568
|
}
|
|
2503
2569
|
}
|
|
2504
2570
|
}
|
|
2505
|
-
yield { type: "turn_complete", data: {} },
|
|
2571
|
+
yield { type: "turn_complete", data: {} }, k.push({ role: "user", content: _ });
|
|
2506
2572
|
}
|
|
2507
2573
|
try {
|
|
2508
|
-
|
|
2509
|
-
traceId:
|
|
2510
|
-
sessionId:
|
|
2511
|
-
totalTurns:
|
|
2512
|
-
durationMs: Date.now() -
|
|
2574
|
+
r?.onChatEnd?.({
|
|
2575
|
+
traceId: s,
|
|
2576
|
+
sessionId: o,
|
|
2577
|
+
totalTurns: E,
|
|
2578
|
+
durationMs: Date.now() - h
|
|
2513
2579
|
});
|
|
2514
2580
|
} catch {
|
|
2515
2581
|
}
|
|
2516
2582
|
yield {
|
|
2517
2583
|
type: "done",
|
|
2518
|
-
data: { sessionId:
|
|
2584
|
+
data: { sessionId: o || "", traceId: s }
|
|
2519
2585
|
};
|
|
2520
|
-
} catch (
|
|
2586
|
+
} catch (f) {
|
|
2521
2587
|
try {
|
|
2522
|
-
|
|
2523
|
-
traceId:
|
|
2524
|
-
sessionId:
|
|
2588
|
+
r?.onChatEnd?.({
|
|
2589
|
+
traceId: s,
|
|
2590
|
+
sessionId: o,
|
|
2525
2591
|
totalTurns: 0,
|
|
2526
|
-
durationMs: Date.now() -
|
|
2527
|
-
error:
|
|
2592
|
+
durationMs: Date.now() - h,
|
|
2593
|
+
error: f instanceof Error ? f.message : "Unknown error"
|
|
2528
2594
|
});
|
|
2529
2595
|
} catch {
|
|
2530
2596
|
}
|
|
2531
2597
|
yield {
|
|
2532
2598
|
type: "error",
|
|
2533
2599
|
data: {
|
|
2534
|
-
message: Fe(
|
|
2600
|
+
message: Fe(f)
|
|
2535
2601
|
}
|
|
2536
2602
|
};
|
|
2537
2603
|
}
|
|
2538
2604
|
}
|
|
2539
|
-
function Fe(
|
|
2540
|
-
if (!
|
|
2605
|
+
function Fe(l) {
|
|
2606
|
+
if (!l || !(l instanceof Error))
|
|
2541
2607
|
return "Something went wrong. Please try again.";
|
|
2542
|
-
const t =
|
|
2608
|
+
const t = l.message || "", a = {
|
|
2543
2609
|
overloaded_error: "The AI service is temporarily overloaded. Please try again in a moment.",
|
|
2544
2610
|
rate_limit_error: "Too many requests. Please wait a moment and try again.",
|
|
2545
2611
|
api_error: "The AI service encountered an error. Please try again.",
|
|
2546
2612
|
authentication_error: "Authentication failed. Please check your API key configuration.",
|
|
2547
2613
|
invalid_request_error: "There was a problem with the request. Please try again."
|
|
2548
|
-
}, i =
|
|
2614
|
+
}, i = l;
|
|
2549
2615
|
if (i.status || i.type) {
|
|
2550
|
-
const
|
|
2551
|
-
if (a[
|
|
2552
|
-
return a[
|
|
2616
|
+
const d = i.error?.type || i.type || "";
|
|
2617
|
+
if (a[d])
|
|
2618
|
+
return a[d];
|
|
2553
2619
|
}
|
|
2554
2620
|
if (t.startsWith("{") || t.startsWith("Error: {")) {
|
|
2555
2621
|
try {
|
|
2556
|
-
const
|
|
2557
|
-
if (a[
|
|
2558
|
-
return a[
|
|
2622
|
+
const d = JSON.parse(t.replace(/^Error:\s*/, "")), u = d.error?.type || d.type || "";
|
|
2623
|
+
if (a[u])
|
|
2624
|
+
return a[u];
|
|
2559
2625
|
} catch {
|
|
2560
2626
|
}
|
|
2561
2627
|
return "The AI service encountered an error. Please try again.";
|
|
@@ -2563,5 +2629,5 @@ function Fe(o) {
|
|
|
2563
2629
|
return t;
|
|
2564
2630
|
}
|
|
2565
2631
|
export {
|
|
2566
|
-
|
|
2632
|
+
_e as handleAgentChat
|
|
2567
2633
|
};
|