drizzle-cube 0.4.17 → 0.4.18
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-DefTXJpi.js} +329 -269
- package/dist/adapters/{handler-C1rOM9M_.cjs → handler-hwoGzGex.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 +1706 -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 m =
|
|
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 m = d[s.key];
|
|
1756
1756
|
if (Array.isArray(m) ? m.length > 0 : !!m) continue;
|
|
1757
|
-
const
|
|
1758
|
-
if (
|
|
1759
|
-
if (
|
|
1757
|
+
const y = s.acceptTypes ?? [];
|
|
1758
|
+
if (s.key === "sizeField" || s.key === "colorField") {
|
|
1759
|
+
if (y.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 (y.includes("dimension") && n.push(...e), y.includes("timeDimension") && n.push(...r), y.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, c = x.slice(0, b);
|
|
1781
|
+
c.length > 0 && (d[s.key] = c);
|
|
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((m) => m.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 `${m.key}=[${
|
|
1800
|
+
const s = r.map((m) => {
|
|
1801
|
+
const f = m.acceptTypes?.join("/") ?? "any", y = m.maxItems ? ` (max ${m.maxItems})` : "";
|
|
1802
|
+
return `${m.key}=[${f}]${y}`;
|
|
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,75 @@ 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((m) => `"${m}"`).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 = (f, y) => {
|
|
2151
|
+
if (!Array.isArray(f)) return;
|
|
2152
|
+
const n = [], x = [];
|
|
2153
|
+
for (const b of f) {
|
|
2154
|
+
if (typeof b != "string") {
|
|
2155
|
+
x.push(b);
|
|
2156
|
+
continue;
|
|
2157
|
+
}
|
|
2158
|
+
const c = b.split(".");
|
|
2159
|
+
if (c.length === 1) {
|
|
2160
|
+
n.push(`"${b}" is not valid — must be "CubeName.fieldName".${u(b, y)}`);
|
|
2161
|
+
continue;
|
|
2162
|
+
}
|
|
2163
|
+
if (c.length === 3 && c[0] === c[1]) {
|
|
2164
|
+
const g = `${c[0]}.${c[2]}`;
|
|
2165
|
+
x.push(g);
|
|
2166
|
+
continue;
|
|
2167
|
+
}
|
|
2168
|
+
if (c.length === 2 && c[0] === c[1]) {
|
|
2169
|
+
n.push(`"${b}" is WRONG — "${c[0]}" is the cube name, not a ${y.replace(/s$/, "")}.${u(c[0], y)}`);
|
|
2170
|
+
continue;
|
|
2171
|
+
}
|
|
2172
|
+
x.push(b);
|
|
2173
|
+
}
|
|
2174
|
+
if (n.length > 0)
|
|
2175
|
+
throw new Error(`Invalid ${y}:
|
|
2176
|
+
${n.join(`
|
|
2177
|
+
`)}`);
|
|
2178
|
+
return x;
|
|
2179
|
+
};
|
|
2180
|
+
e.measures = o(e.measures, "measures") ?? e.measures, e.dimensions = o(e.dimensions, "dimensions") ?? e.dimensions;
|
|
2181
|
+
const r = (f) => {
|
|
2182
|
+
const y = f.split(".");
|
|
2183
|
+
return y.length === 3 && y[0] === y[1] ? `${y[0]}.${y[2]}` : f;
|
|
2146
2184
|
};
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2185
|
+
if (Array.isArray(e.filters))
|
|
2186
|
+
for (const f of e.filters)
|
|
2187
|
+
typeof f.member == "string" && (f.member = r(f.member));
|
|
2188
|
+
if (Array.isArray(e.timeDimensions))
|
|
2189
|
+
for (const f of e.timeDimensions)
|
|
2190
|
+
typeof f.dimension == "string" && (f.dimension = r(f.dimension));
|
|
2191
|
+
let s;
|
|
2192
|
+
e.funnel ? s = { funnel: e.funnel } : e.flow ? s = { flow: e.flow } : e.retention ? s = { retention: e.retention } : s = {
|
|
2150
2193
|
measures: e.measures,
|
|
2151
2194
|
dimensions: e.dimensions,
|
|
2152
2195
|
filters: e.filters,
|
|
@@ -2154,135 +2197,152 @@ function Se(o) {
|
|
|
2154
2197
|
order: e.order,
|
|
2155
2198
|
limit: e.limit
|
|
2156
2199
|
};
|
|
2157
|
-
const
|
|
2200
|
+
const m = await G(t, a, { query: s });
|
|
2158
2201
|
return {
|
|
2159
2202
|
result: JSON.stringify({
|
|
2160
|
-
rowCount:
|
|
2161
|
-
data:
|
|
2162
|
-
annotation:
|
|
2203
|
+
rowCount: m.data.length,
|
|
2204
|
+
data: m.data,
|
|
2205
|
+
annotation: m.annotation
|
|
2163
2206
|
}, null, 2)
|
|
2164
2207
|
};
|
|
2165
|
-
} catch (
|
|
2208
|
+
} catch (o) {
|
|
2209
|
+
const r = {
|
|
2210
|
+
measures: e.measures,
|
|
2211
|
+
dimensions: e.dimensions,
|
|
2212
|
+
filters: e.filters,
|
|
2213
|
+
timeDimensions: e.timeDimensions,
|
|
2214
|
+
order: e.order,
|
|
2215
|
+
limit: e.limit,
|
|
2216
|
+
...e.funnel ? { funnel: e.funnel } : {},
|
|
2217
|
+
...e.flow ? { flow: e.flow } : {},
|
|
2218
|
+
...e.retention ? { retention: e.retention } : {}
|
|
2219
|
+
};
|
|
2166
2220
|
return {
|
|
2167
|
-
result: `Query execution failed: ${
|
|
2221
|
+
result: `Query execution failed: ${o instanceof Error ? o.message : "Unknown error"}
|
|
2222
|
+
|
|
2223
|
+
Attempted query:
|
|
2224
|
+
${JSON.stringify(r, null, 2)}`,
|
|
2168
2225
|
isError: !0
|
|
2169
2226
|
};
|
|
2170
2227
|
}
|
|
2171
2228
|
}), i.set("add_portlet", async (e) => {
|
|
2172
|
-
const
|
|
2229
|
+
const r = {
|
|
2173
2230
|
number: "kpiNumber",
|
|
2174
2231
|
retention: "retentionHeatmap"
|
|
2175
2232
|
}[e.chartType] ?? e.chartType;
|
|
2176
|
-
let
|
|
2233
|
+
let s;
|
|
2177
2234
|
try {
|
|
2178
|
-
|
|
2235
|
+
s = JSON.parse(e.query);
|
|
2179
2236
|
} catch {
|
|
2180
2237
|
return {
|
|
2181
2238
|
result: "Invalid query: could not parse JSON string. Ensure `query` is a valid JSON string.",
|
|
2182
2239
|
isError: !0
|
|
2183
2240
|
};
|
|
2184
2241
|
}
|
|
2185
|
-
const
|
|
2186
|
-
if (!
|
|
2242
|
+
const m = t.validateQuery(s);
|
|
2243
|
+
if (!m.isValid)
|
|
2187
2244
|
return {
|
|
2188
2245
|
result: `Invalid query — fix these errors and retry:
|
|
2189
|
-
${
|
|
2190
|
-
`)}
|
|
2246
|
+
${m.errors.join(`
|
|
2247
|
+
`)}
|
|
2248
|
+
|
|
2249
|
+
Attempted query:
|
|
2250
|
+
${JSON.stringify(s, null, 2)}`,
|
|
2191
2251
|
isError: !0
|
|
2192
2252
|
};
|
|
2193
|
-
const
|
|
2194
|
-
let
|
|
2195
|
-
if (
|
|
2196
|
-
|
|
2253
|
+
const f = !!(s.funnel || s.flow || s.retention);
|
|
2254
|
+
let y;
|
|
2255
|
+
if (f)
|
|
2256
|
+
y = e.chartConfig ?? {};
|
|
2197
2257
|
else {
|
|
2198
|
-
const
|
|
2199
|
-
if (!
|
|
2258
|
+
const b = Te(r, e.chartConfig, s), c = Ce(r, b, s);
|
|
2259
|
+
if (!c.isValid)
|
|
2200
2260
|
return {
|
|
2201
2261
|
result: `Chart config invalid — fix these errors and retry:
|
|
2202
|
-
${
|
|
2262
|
+
${c.errors.join(`
|
|
2203
2263
|
`)}`,
|
|
2204
2264
|
isError: !0
|
|
2205
2265
|
};
|
|
2206
|
-
|
|
2266
|
+
y = b;
|
|
2207
2267
|
}
|
|
2208
|
-
const n = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
2268
|
+
const n = `portlet-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, x = {
|
|
2209
2269
|
id: n,
|
|
2210
2270
|
title: e.title,
|
|
2211
2271
|
query: e.query,
|
|
2212
|
-
chartType:
|
|
2213
|
-
chartConfig:
|
|
2272
|
+
chartType: r,
|
|
2273
|
+
chartConfig: y,
|
|
2214
2274
|
displayConfig: e.displayConfig
|
|
2215
2275
|
};
|
|
2216
2276
|
return {
|
|
2217
|
-
result: `Portlet "${e.title}" added to notebook (id: ${n}, chart: ${
|
|
2218
|
-
sideEffect: { type: "add_portlet", data:
|
|
2277
|
+
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.]`,
|
|
2278
|
+
sideEffect: { type: "add_portlet", data: x }
|
|
2219
2279
|
};
|
|
2220
2280
|
}), i.set("add_markdown", async (e) => {
|
|
2221
|
-
const
|
|
2222
|
-
id:
|
|
2281
|
+
const o = `markdown-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, r = {
|
|
2282
|
+
id: o,
|
|
2223
2283
|
title: e.title,
|
|
2224
2284
|
content: e.content
|
|
2225
2285
|
};
|
|
2226
2286
|
return {
|
|
2227
|
-
result: `Markdown block added to notebook (id: ${
|
|
2228
|
-
sideEffect: { type: "add_markdown", data:
|
|
2287
|
+
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.]`,
|
|
2288
|
+
sideEffect: { type: "add_markdown", data: r }
|
|
2229
2289
|
};
|
|
2230
2290
|
}), i.set("save_as_dashboard", async (e) => {
|
|
2231
2291
|
try {
|
|
2232
|
-
const
|
|
2233
|
-
if (!
|
|
2292
|
+
const o = e.portlets;
|
|
2293
|
+
if (!o || o.length === 0)
|
|
2234
2294
|
return { result: "Dashboard must contain at least one portlet.", isError: !0 };
|
|
2235
|
-
const
|
|
2236
|
-
for (const n of
|
|
2295
|
+
const r = [];
|
|
2296
|
+
for (const n of o) {
|
|
2237
2297
|
if (n.chartType === "markdown") continue;
|
|
2238
|
-
const
|
|
2239
|
-
if (!
|
|
2240
|
-
|
|
2298
|
+
const b = n.query;
|
|
2299
|
+
if (!b) {
|
|
2300
|
+
r.push(`Portlet "${n.title}": missing query`);
|
|
2241
2301
|
continue;
|
|
2242
2302
|
}
|
|
2243
|
-
let
|
|
2303
|
+
let c;
|
|
2244
2304
|
try {
|
|
2245
|
-
|
|
2305
|
+
c = JSON.parse(b);
|
|
2246
2306
|
} catch {
|
|
2247
|
-
|
|
2307
|
+
r.push(`Portlet "${n.title}": invalid JSON query`);
|
|
2248
2308
|
continue;
|
|
2249
2309
|
}
|
|
2250
|
-
const
|
|
2251
|
-
|
|
2310
|
+
const g = t.validateQuery(c);
|
|
2311
|
+
g.isValid || r.push(`Portlet "${n.title}": ${g.errors.join(", ")}`);
|
|
2252
2312
|
}
|
|
2253
|
-
if (
|
|
2313
|
+
if (r.length > 0)
|
|
2254
2314
|
return {
|
|
2255
2315
|
result: `Dashboard has invalid portlets — fix these errors and retry:
|
|
2256
|
-
${
|
|
2316
|
+
${r.join(`
|
|
2257
2317
|
`)}`,
|
|
2258
2318
|
isError: !0
|
|
2259
2319
|
};
|
|
2260
|
-
const
|
|
2261
|
-
portlets:
|
|
2262
|
-
const
|
|
2263
|
-
let
|
|
2320
|
+
const s = {
|
|
2321
|
+
portlets: o.map((n) => {
|
|
2322
|
+
const x = n.chartType, b = x === "markdown", c = b ? "query" : n.analysisType || "query", g = c === "funnel" ? "funnel" : c === "flow" ? "flow" : c === "retention" ? "retention" : "query", A = n.query || "{}";
|
|
2323
|
+
let C;
|
|
2264
2324
|
try {
|
|
2265
|
-
|
|
2325
|
+
C = JSON.parse(A);
|
|
2266
2326
|
} catch {
|
|
2267
|
-
|
|
2327
|
+
C = {};
|
|
2268
2328
|
}
|
|
2269
|
-
const
|
|
2329
|
+
const k = {
|
|
2270
2330
|
version: 1,
|
|
2271
|
-
analysisType:
|
|
2331
|
+
analysisType: g,
|
|
2272
2332
|
activeView: "chart",
|
|
2273
2333
|
charts: {
|
|
2274
|
-
[
|
|
2275
|
-
chartType:
|
|
2334
|
+
[g]: {
|
|
2335
|
+
chartType: x,
|
|
2276
2336
|
chartConfig: n.chartConfig || {},
|
|
2277
2337
|
displayConfig: n.displayConfig || {}
|
|
2278
2338
|
}
|
|
2279
2339
|
},
|
|
2280
|
-
query:
|
|
2340
|
+
query: b ? {} : C
|
|
2281
2341
|
};
|
|
2282
2342
|
return {
|
|
2283
2343
|
id: n.id,
|
|
2284
2344
|
title: n.title,
|
|
2285
|
-
analysisConfig:
|
|
2345
|
+
analysisConfig: k,
|
|
2286
2346
|
dashboardFilterMapping: n.dashboardFilterMapping,
|
|
2287
2347
|
w: n.w,
|
|
2288
2348
|
h: n.h,
|
|
@@ -2292,35 +2352,35 @@ ${l.join(`
|
|
|
2292
2352
|
}),
|
|
2293
2353
|
filters: e.filters,
|
|
2294
2354
|
colorPalette: e.colorPalette
|
|
2295
|
-
},
|
|
2355
|
+
}, m = e.title, f = s.portlets.length, y = s.filters?.length || 0;
|
|
2296
2356
|
return {
|
|
2297
|
-
result: `Dashboard "${
|
|
2357
|
+
result: `Dashboard "${m}" created with ${f} portlets and ${y} filters.`,
|
|
2298
2358
|
sideEffect: {
|
|
2299
2359
|
type: "dashboard_saved",
|
|
2300
2360
|
data: {
|
|
2301
|
-
title:
|
|
2361
|
+
title: m,
|
|
2302
2362
|
description: e.description,
|
|
2303
|
-
dashboardConfig:
|
|
2363
|
+
dashboardConfig: s
|
|
2304
2364
|
}
|
|
2305
2365
|
}
|
|
2306
2366
|
};
|
|
2307
|
-
} catch (
|
|
2367
|
+
} catch (o) {
|
|
2308
2368
|
return {
|
|
2309
|
-
result: `Failed to save dashboard: ${
|
|
2369
|
+
result: `Failed to save dashboard: ${o instanceof Error ? o.message : "Unknown error"}`,
|
|
2310
2370
|
isError: !0
|
|
2311
2371
|
};
|
|
2312
2372
|
}
|
|
2313
2373
|
}), i;
|
|
2314
2374
|
}
|
|
2315
|
-
async function*
|
|
2316
|
-
const { message: t, history: a, semanticLayer: i, securityContext:
|
|
2317
|
-
let
|
|
2375
|
+
async function* _e(l) {
|
|
2376
|
+
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(), m = Date.now();
|
|
2377
|
+
let f;
|
|
2318
2378
|
try {
|
|
2319
|
-
const
|
|
2379
|
+
const h = await import(
|
|
2320
2380
|
/* webpackIgnore: true */
|
|
2321
2381
|
"@anthropic-ai/sdk"
|
|
2322
2382
|
);
|
|
2323
|
-
|
|
2383
|
+
f = h.default || h.Anthropic || h;
|
|
2324
2384
|
} catch {
|
|
2325
2385
|
yield {
|
|
2326
2386
|
type: "error",
|
|
@@ -2330,171 +2390,171 @@ async function* Ee(o) {
|
|
|
2330
2390
|
};
|
|
2331
2391
|
return;
|
|
2332
2392
|
}
|
|
2333
|
-
const
|
|
2393
|
+
const y = new f({ apiKey: e }), n = De(), x = Se({ semanticLayer: i, securityContext: d }), b = i.getMetadata(), c = W(b), g = u.model || "claude-sonnet-4-6", A = u.maxTurns || 25, C = u.maxTokens || 4096;
|
|
2334
2394
|
try {
|
|
2335
|
-
|
|
2336
|
-
traceId:
|
|
2337
|
-
sessionId:
|
|
2395
|
+
r?.onChatStart?.({
|
|
2396
|
+
traceId: s,
|
|
2397
|
+
sessionId: o,
|
|
2338
2398
|
message: t,
|
|
2339
2399
|
model: g,
|
|
2340
2400
|
historyLength: a?.length ?? 0
|
|
2341
2401
|
});
|
|
2342
2402
|
} catch {
|
|
2343
2403
|
}
|
|
2344
|
-
const
|
|
2404
|
+
const k = [];
|
|
2345
2405
|
if (a && a.length > 0) {
|
|
2346
|
-
for (const
|
|
2347
|
-
if (
|
|
2348
|
-
|
|
2349
|
-
else if (
|
|
2406
|
+
for (const h of a)
|
|
2407
|
+
if (h.role === "user")
|
|
2408
|
+
k.push({ role: "user", content: h.content });
|
|
2409
|
+
else if (h.role === "assistant") {
|
|
2350
2410
|
const F = [];
|
|
2351
|
-
if (
|
|
2352
|
-
for (const
|
|
2411
|
+
if (h.content && F.push({ type: "text", text: h.content }), h.toolCalls && h.toolCalls.length > 0) {
|
|
2412
|
+
for (const w of h.toolCalls)
|
|
2353
2413
|
F.push({
|
|
2354
2414
|
type: "tool_use",
|
|
2355
|
-
id:
|
|
2356
|
-
name:
|
|
2357
|
-
input:
|
|
2415
|
+
id: w.id,
|
|
2416
|
+
name: w.name,
|
|
2417
|
+
input: w.input || {}
|
|
2358
2418
|
});
|
|
2359
|
-
|
|
2419
|
+
k.push({ role: "assistant", content: F }), k.push({
|
|
2360
2420
|
role: "user",
|
|
2361
|
-
content:
|
|
2421
|
+
content: h.toolCalls.map((w) => ({
|
|
2362
2422
|
type: "tool_result",
|
|
2363
|
-
tool_use_id:
|
|
2364
|
-
content: typeof
|
|
2365
|
-
...
|
|
2423
|
+
tool_use_id: w.id,
|
|
2424
|
+
content: typeof w.result == "string" ? w.result : JSON.stringify(w.result ?? ""),
|
|
2425
|
+
...w.status === "error" ? { is_error: !0 } : {}
|
|
2366
2426
|
}))
|
|
2367
2427
|
});
|
|
2368
|
-
} else F.length > 0 &&
|
|
2428
|
+
} else F.length > 0 && k.push({ role: "assistant", content: h.content });
|
|
2369
2429
|
}
|
|
2370
2430
|
}
|
|
2371
|
-
|
|
2372
|
-
let
|
|
2431
|
+
k.push({ role: "user", content: t });
|
|
2432
|
+
let E = 0;
|
|
2373
2433
|
try {
|
|
2374
|
-
for (let
|
|
2375
|
-
|
|
2376
|
-
const F = await
|
|
2434
|
+
for (let h = 0; h < A; h++) {
|
|
2435
|
+
E = h + 1;
|
|
2436
|
+
const F = await y.messages.create({
|
|
2377
2437
|
model: g,
|
|
2378
|
-
max_tokens:
|
|
2379
|
-
system:
|
|
2380
|
-
tools:
|
|
2381
|
-
messages:
|
|
2438
|
+
max_tokens: C,
|
|
2439
|
+
system: c,
|
|
2440
|
+
tools: n,
|
|
2441
|
+
messages: k,
|
|
2382
2442
|
stream: !0
|
|
2383
|
-
}),
|
|
2384
|
-
let q = -1,
|
|
2385
|
-
const
|
|
2386
|
-
for await (const
|
|
2387
|
-
switch (
|
|
2443
|
+
}), w = [];
|
|
2444
|
+
let q = -1, V = "", O = "", L, M;
|
|
2445
|
+
const z = Date.now();
|
|
2446
|
+
for await (const v of F)
|
|
2447
|
+
switch (v.type) {
|
|
2388
2448
|
case "content_block_start": {
|
|
2389
2449
|
q++;
|
|
2390
|
-
const
|
|
2391
|
-
|
|
2450
|
+
const p = v.content_block;
|
|
2451
|
+
p.type === "tool_use" ? (w.push({ type: "tool_use", id: p.id, name: p.name, input: {} }), V = "", yield {
|
|
2392
2452
|
type: "tool_use_start",
|
|
2393
|
-
data: { id:
|
|
2394
|
-
}) :
|
|
2453
|
+
data: { id: p.id, name: p.name, input: void 0 }
|
|
2454
|
+
}) : p.type === "text" && w.push({ type: "text", text: "" });
|
|
2395
2455
|
break;
|
|
2396
2456
|
}
|
|
2397
2457
|
case "content_block_delta": {
|
|
2398
|
-
const
|
|
2399
|
-
if (
|
|
2400
|
-
const
|
|
2401
|
-
|
|
2402
|
-
} else
|
|
2458
|
+
const p = v.delta;
|
|
2459
|
+
if (p.type === "text_delta" && p.text) {
|
|
2460
|
+
const D = w[q];
|
|
2461
|
+
D && (D.text = (D.text || "") + p.text), yield { type: "text_delta", data: p.text };
|
|
2462
|
+
} else p.type === "input_json_delta" && p.partial_json && (V += p.partial_json);
|
|
2403
2463
|
break;
|
|
2404
2464
|
}
|
|
2405
2465
|
case "content_block_stop": {
|
|
2406
|
-
const
|
|
2407
|
-
if (
|
|
2466
|
+
const p = w[q];
|
|
2467
|
+
if (p?.type === "tool_use" && V) {
|
|
2408
2468
|
try {
|
|
2409
|
-
|
|
2469
|
+
p.input = JSON.parse(V);
|
|
2410
2470
|
} catch {
|
|
2411
|
-
|
|
2471
|
+
p.input = {};
|
|
2412
2472
|
}
|
|
2413
|
-
|
|
2473
|
+
V = "";
|
|
2414
2474
|
}
|
|
2415
2475
|
break;
|
|
2416
2476
|
}
|
|
2417
2477
|
case "message_start": {
|
|
2418
|
-
const
|
|
2419
|
-
|
|
2478
|
+
const p = v.message;
|
|
2479
|
+
p?.usage?.input_tokens != null && (L = p.usage.input_tokens);
|
|
2420
2480
|
break;
|
|
2421
2481
|
}
|
|
2422
2482
|
case "message_delta": {
|
|
2423
|
-
const
|
|
2424
|
-
|
|
2483
|
+
const p = v.delta, D = v.usage;
|
|
2484
|
+
D?.output_tokens != null && (M = D.output_tokens), p.stop_reason && (O = p.stop_reason);
|
|
2425
2485
|
break;
|
|
2426
2486
|
}
|
|
2427
2487
|
}
|
|
2428
2488
|
try {
|
|
2429
|
-
|
|
2430
|
-
traceId:
|
|
2431
|
-
turn:
|
|
2489
|
+
r?.onGenerationEnd?.({
|
|
2490
|
+
traceId: s,
|
|
2491
|
+
turn: h,
|
|
2432
2492
|
model: g,
|
|
2433
2493
|
stopReason: O,
|
|
2434
2494
|
inputTokens: L,
|
|
2435
|
-
outputTokens:
|
|
2436
|
-
durationMs: Date.now() -
|
|
2495
|
+
outputTokens: M,
|
|
2496
|
+
durationMs: Date.now() - z
|
|
2437
2497
|
});
|
|
2438
2498
|
} catch {
|
|
2439
2499
|
}
|
|
2440
|
-
if (
|
|
2500
|
+
if (k.push({ role: "assistant", content: w }), O !== "tool_use")
|
|
2441
2501
|
break;
|
|
2442
|
-
const
|
|
2443
|
-
for (const
|
|
2444
|
-
if (
|
|
2445
|
-
const
|
|
2446
|
-
if (!
|
|
2447
|
-
|
|
2502
|
+
const _ = [];
|
|
2503
|
+
for (const v of w) {
|
|
2504
|
+
if (v.type !== "tool_use") continue;
|
|
2505
|
+
const p = v.name, D = v.input || {}, S = v.id, R = x.get(p);
|
|
2506
|
+
if (!R) {
|
|
2507
|
+
_.push({
|
|
2448
2508
|
type: "tool_result",
|
|
2449
|
-
tool_use_id:
|
|
2450
|
-
content: `Unknown tool: ${
|
|
2509
|
+
tool_use_id: S,
|
|
2510
|
+
content: `Unknown tool: ${p}`,
|
|
2451
2511
|
is_error: !0
|
|
2452
2512
|
}), yield {
|
|
2453
2513
|
type: "tool_use_result",
|
|
2454
|
-
data: { id:
|
|
2514
|
+
data: { id: S, name: p, result: `Unknown tool: ${p}`, isError: !0 }
|
|
2455
2515
|
};
|
|
2456
2516
|
continue;
|
|
2457
2517
|
}
|
|
2458
2518
|
const Y = Date.now();
|
|
2459
2519
|
try {
|
|
2460
|
-
const
|
|
2461
|
-
|
|
2520
|
+
const T = await R(D);
|
|
2521
|
+
T.sideEffect && (yield T.sideEffect), _.push({
|
|
2462
2522
|
type: "tool_result",
|
|
2463
|
-
tool_use_id:
|
|
2464
|
-
content:
|
|
2465
|
-
...
|
|
2523
|
+
tool_use_id: S,
|
|
2524
|
+
content: T.result,
|
|
2525
|
+
...T.isError ? { is_error: !0 } : {}
|
|
2466
2526
|
}), yield {
|
|
2467
2527
|
type: "tool_use_result",
|
|
2468
|
-
data: { id:
|
|
2528
|
+
data: { id: S, name: p, result: T.result, ...T.isError ? { isError: !0 } : {} }
|
|
2469
2529
|
};
|
|
2470
2530
|
try {
|
|
2471
|
-
|
|
2472
|
-
traceId:
|
|
2473
|
-
turn:
|
|
2474
|
-
toolName:
|
|
2475
|
-
toolUseId:
|
|
2476
|
-
isError: !!
|
|
2531
|
+
r?.onToolEnd?.({
|
|
2532
|
+
traceId: s,
|
|
2533
|
+
turn: h,
|
|
2534
|
+
toolName: p,
|
|
2535
|
+
toolUseId: S,
|
|
2536
|
+
isError: !!T.isError,
|
|
2477
2537
|
durationMs: Date.now() - Y
|
|
2478
2538
|
});
|
|
2479
2539
|
} catch {
|
|
2480
2540
|
}
|
|
2481
|
-
} catch (
|
|
2482
|
-
const
|
|
2483
|
-
|
|
2541
|
+
} catch (T) {
|
|
2542
|
+
const $ = T instanceof Error ? T.message : "Tool execution failed";
|
|
2543
|
+
_.push({
|
|
2484
2544
|
type: "tool_result",
|
|
2485
|
-
tool_use_id:
|
|
2486
|
-
content:
|
|
2545
|
+
tool_use_id: S,
|
|
2546
|
+
content: $,
|
|
2487
2547
|
is_error: !0
|
|
2488
2548
|
}), yield {
|
|
2489
2549
|
type: "tool_use_result",
|
|
2490
|
-
data: { id:
|
|
2550
|
+
data: { id: S, name: p, result: $, isError: !0 }
|
|
2491
2551
|
};
|
|
2492
2552
|
try {
|
|
2493
|
-
|
|
2494
|
-
traceId:
|
|
2495
|
-
turn:
|
|
2496
|
-
toolName:
|
|
2497
|
-
toolUseId:
|
|
2553
|
+
r?.onToolEnd?.({
|
|
2554
|
+
traceId: s,
|
|
2555
|
+
turn: h,
|
|
2556
|
+
toolName: p,
|
|
2557
|
+
toolUseId: S,
|
|
2498
2558
|
isError: !0,
|
|
2499
2559
|
durationMs: Date.now() - Y
|
|
2500
2560
|
});
|
|
@@ -2502,60 +2562,60 @@ async function* Ee(o) {
|
|
|
2502
2562
|
}
|
|
2503
2563
|
}
|
|
2504
2564
|
}
|
|
2505
|
-
yield { type: "turn_complete", data: {} },
|
|
2565
|
+
yield { type: "turn_complete", data: {} }, k.push({ role: "user", content: _ });
|
|
2506
2566
|
}
|
|
2507
2567
|
try {
|
|
2508
|
-
|
|
2509
|
-
traceId:
|
|
2510
|
-
sessionId:
|
|
2511
|
-
totalTurns:
|
|
2568
|
+
r?.onChatEnd?.({
|
|
2569
|
+
traceId: s,
|
|
2570
|
+
sessionId: o,
|
|
2571
|
+
totalTurns: E,
|
|
2512
2572
|
durationMs: Date.now() - m
|
|
2513
2573
|
});
|
|
2514
2574
|
} catch {
|
|
2515
2575
|
}
|
|
2516
2576
|
yield {
|
|
2517
2577
|
type: "done",
|
|
2518
|
-
data: { sessionId:
|
|
2578
|
+
data: { sessionId: o || "", traceId: s }
|
|
2519
2579
|
};
|
|
2520
|
-
} catch (
|
|
2580
|
+
} catch (h) {
|
|
2521
2581
|
try {
|
|
2522
|
-
|
|
2523
|
-
traceId:
|
|
2524
|
-
sessionId:
|
|
2582
|
+
r?.onChatEnd?.({
|
|
2583
|
+
traceId: s,
|
|
2584
|
+
sessionId: o,
|
|
2525
2585
|
totalTurns: 0,
|
|
2526
2586
|
durationMs: Date.now() - m,
|
|
2527
|
-
error:
|
|
2587
|
+
error: h instanceof Error ? h.message : "Unknown error"
|
|
2528
2588
|
});
|
|
2529
2589
|
} catch {
|
|
2530
2590
|
}
|
|
2531
2591
|
yield {
|
|
2532
2592
|
type: "error",
|
|
2533
2593
|
data: {
|
|
2534
|
-
message: Fe(
|
|
2594
|
+
message: Fe(h)
|
|
2535
2595
|
}
|
|
2536
2596
|
};
|
|
2537
2597
|
}
|
|
2538
2598
|
}
|
|
2539
|
-
function Fe(
|
|
2540
|
-
if (!
|
|
2599
|
+
function Fe(l) {
|
|
2600
|
+
if (!l || !(l instanceof Error))
|
|
2541
2601
|
return "Something went wrong. Please try again.";
|
|
2542
|
-
const t =
|
|
2602
|
+
const t = l.message || "", a = {
|
|
2543
2603
|
overloaded_error: "The AI service is temporarily overloaded. Please try again in a moment.",
|
|
2544
2604
|
rate_limit_error: "Too many requests. Please wait a moment and try again.",
|
|
2545
2605
|
api_error: "The AI service encountered an error. Please try again.",
|
|
2546
2606
|
authentication_error: "Authentication failed. Please check your API key configuration.",
|
|
2547
2607
|
invalid_request_error: "There was a problem with the request. Please try again."
|
|
2548
|
-
}, i =
|
|
2608
|
+
}, i = l;
|
|
2549
2609
|
if (i.status || i.type) {
|
|
2550
|
-
const
|
|
2551
|
-
if (a[
|
|
2552
|
-
return a[
|
|
2610
|
+
const d = i.error?.type || i.type || "";
|
|
2611
|
+
if (a[d])
|
|
2612
|
+
return a[d];
|
|
2553
2613
|
}
|
|
2554
2614
|
if (t.startsWith("{") || t.startsWith("Error: {")) {
|
|
2555
2615
|
try {
|
|
2556
|
-
const
|
|
2557
|
-
if (a[
|
|
2558
|
-
return a[
|
|
2616
|
+
const d = JSON.parse(t.replace(/^Error:\s*/, "")), u = d.error?.type || d.type || "";
|
|
2617
|
+
if (a[u])
|
|
2618
|
+
return a[u];
|
|
2559
2619
|
} catch {
|
|
2560
2620
|
}
|
|
2561
2621
|
return "The AI service encountered an error. Please try again.";
|
|
@@ -2563,5 +2623,5 @@ function Fe(o) {
|
|
|
2563
2623
|
return t;
|
|
2564
2624
|
}
|
|
2565
2625
|
export {
|
|
2566
|
-
|
|
2626
|
+
_e as handleAgentChat
|
|
2567
2627
|
};
|