dp-widgets-framework 1.1.2 → 1.1.4
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/index.esm.js +86 -304
- package/dist/index.js +80 -298
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as LabelPrimitive from '@radix-ui/react-label';
|
|
|
7
7
|
import { cva } from 'class-variance-authority';
|
|
8
8
|
import * as SwitchPrimitives from '@radix-ui/react-switch';
|
|
9
9
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
10
|
-
import { ChevronDown, ChevronUp, Check, AlertCircle, MoveUp, MoveDown, Trash2, Plus, Bot, Type, Layout, LayoutGrid, BarChart
|
|
10
|
+
import { ChevronDown, ChevronUp, Check, AlertCircle, MoveUp, MoveDown, Trash2, Plus, Bot, Type, Layout, LayoutGrid, BarChart, Filter, Search, ArrowUp, ArrowDown, RefreshCw, X, LineChart, PieChart as PieChart$1, Table, FileText, Loader2, GripHorizontal, Edit, MessageCircleX, Edit2 } from 'lucide-react';
|
|
11
11
|
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
12
12
|
import { Slot } from '@radix-ui/react-slot';
|
|
13
13
|
import { debounce as debounce$1 } from 'lodash';
|
|
@@ -1912,7 +1912,7 @@ const IconMap$1 = {
|
|
|
1912
1912
|
search: Search,
|
|
1913
1913
|
filter: Filter,
|
|
1914
1914
|
results: LayoutGrid,
|
|
1915
|
-
analytics: BarChart
|
|
1915
|
+
analytics: BarChart,
|
|
1916
1916
|
custom: LayoutGrid,
|
|
1917
1917
|
header: Layout,
|
|
1918
1918
|
footer: Layout,
|
|
@@ -15048,78 +15048,6 @@ const Line = /* #__PURE__ */ createTypedChart('line', LineController);
|
|
|
15048
15048
|
const Bar = /* #__PURE__ */ createTypedChart('bar', BarController);
|
|
15049
15049
|
const Pie = /* #__PURE__ */ createTypedChart('pie', PieController);
|
|
15050
15050
|
|
|
15051
|
-
Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
|
|
15052
|
-
function BarChart({ orientation, title, data, options, className, units }) {
|
|
15053
|
-
const formatValue = (value) => {
|
|
15054
|
-
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
15055
|
-
if (units === '$' && !isNaN(numValue)) {
|
|
15056
|
-
return numValue.toLocaleString();
|
|
15057
|
-
}
|
|
15058
|
-
return value;
|
|
15059
|
-
};
|
|
15060
|
-
const defaultOptions = {
|
|
15061
|
-
responsive: true,
|
|
15062
|
-
maintainAspectRatio: false,
|
|
15063
|
-
indexAxis: orientation === "horizontal" ? "y" : "x",
|
|
15064
|
-
layout: {
|
|
15065
|
-
padding: {
|
|
15066
|
-
bottom: 0,
|
|
15067
|
-
top: 0,
|
|
15068
|
-
left: 0,
|
|
15069
|
-
right: 0,
|
|
15070
|
-
},
|
|
15071
|
-
},
|
|
15072
|
-
plugins: {
|
|
15073
|
-
legend: {
|
|
15074
|
-
display: false,
|
|
15075
|
-
labels: {
|
|
15076
|
-
boxWidth: 5,
|
|
15077
|
-
boxHeight: 5,
|
|
15078
|
-
},
|
|
15079
|
-
position: "bottom"
|
|
15080
|
-
},
|
|
15081
|
-
title: {
|
|
15082
|
-
display: true,
|
|
15083
|
-
text: title,
|
|
15084
|
-
font: {
|
|
15085
|
-
size: 18,
|
|
15086
|
-
weight: "bold",
|
|
15087
|
-
},
|
|
15088
|
-
color: "#0F172A"
|
|
15089
|
-
},
|
|
15090
|
-
tooltip: {
|
|
15091
|
-
callbacks: {
|
|
15092
|
-
label: function (context) {
|
|
15093
|
-
const value = context.parsed.y || context.parsed.x;
|
|
15094
|
-
return units ? `${context.dataset.label}: ${formatValue(value)} ${units}` : `${context.dataset.label}: ${value}`;
|
|
15095
|
-
}
|
|
15096
|
-
}
|
|
15097
|
-
},
|
|
15098
|
-
},
|
|
15099
|
-
scales: {
|
|
15100
|
-
x: {
|
|
15101
|
-
ticks: {
|
|
15102
|
-
autoSkip: false,
|
|
15103
|
-
maxRotation: 45,
|
|
15104
|
-
minRotation: 45,
|
|
15105
|
-
font: {
|
|
15106
|
-
size: 10
|
|
15107
|
-
}
|
|
15108
|
-
},
|
|
15109
|
-
},
|
|
15110
|
-
y: {
|
|
15111
|
-
beginAtZero: true,
|
|
15112
|
-
ticks: {
|
|
15113
|
-
callback: function (value) {
|
|
15114
|
-
return units ? `${formatValue(value)} ${units}` : value;
|
|
15115
|
-
}
|
|
15116
|
-
}
|
|
15117
|
-
},
|
|
15118
|
-
},
|
|
15119
|
-
};
|
|
15120
|
-
return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
|
|
15121
|
-
}
|
|
15122
|
-
|
|
15123
15051
|
Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
|
|
15124
15052
|
function SeriesChart({ orientation, title, data, options, className, units }) {
|
|
15125
15053
|
const formatValue = (value) => {
|
|
@@ -15308,70 +15236,6 @@ const PieChart = (props) => {
|
|
|
15308
15236
|
return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions });
|
|
15309
15237
|
};
|
|
15310
15238
|
|
|
15311
|
-
Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
|
|
15312
|
-
function LineChart({ title, data, options, className, units }) {
|
|
15313
|
-
const formatValue = (value) => {
|
|
15314
|
-
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
15315
|
-
if (units === '$' && !isNaN(numValue)) {
|
|
15316
|
-
return numValue.toLocaleString();
|
|
15317
|
-
}
|
|
15318
|
-
return value;
|
|
15319
|
-
};
|
|
15320
|
-
const defaultOptions = {
|
|
15321
|
-
responsive: true,
|
|
15322
|
-
maintainAspectRatio: false,
|
|
15323
|
-
layout: {
|
|
15324
|
-
padding: {
|
|
15325
|
-
bottom: 0,
|
|
15326
|
-
top: 0,
|
|
15327
|
-
left: 0,
|
|
15328
|
-
right: 0,
|
|
15329
|
-
},
|
|
15330
|
-
},
|
|
15331
|
-
plugins: {
|
|
15332
|
-
legend: {
|
|
15333
|
-
display: false,
|
|
15334
|
-
labels: {
|
|
15335
|
-
boxWidth: 5,
|
|
15336
|
-
boxHeight: 5,
|
|
15337
|
-
},
|
|
15338
|
-
position: "bottom"
|
|
15339
|
-
},
|
|
15340
|
-
title: {
|
|
15341
|
-
display: true,
|
|
15342
|
-
text: title,
|
|
15343
|
-
font: {
|
|
15344
|
-
size: 18,
|
|
15345
|
-
weight: "bold",
|
|
15346
|
-
},
|
|
15347
|
-
color: "#0F172A"
|
|
15348
|
-
},
|
|
15349
|
-
tooltip: {
|
|
15350
|
-
callbacks: {
|
|
15351
|
-
label: function (context) {
|
|
15352
|
-
const value = context.parsed.y;
|
|
15353
|
-
return units ? `${context.dataset.label}: ${formatValue(value)} ${units}` : `${context.dataset.label}: ${value}`;
|
|
15354
|
-
}
|
|
15355
|
-
}
|
|
15356
|
-
},
|
|
15357
|
-
},
|
|
15358
|
-
scales: {
|
|
15359
|
-
x: {
|
|
15360
|
-
ticks: { autoSkip: true, maxTicksLimit: 8, maxRotation: 45, minRotation: 0 },
|
|
15361
|
-
},
|
|
15362
|
-
y: {
|
|
15363
|
-
beginAtZero: true,
|
|
15364
|
-
ticks: {
|
|
15365
|
-
callback: function (value) {
|
|
15366
|
-
return units ? `${formatValue(value)} ${units}` : value;
|
|
15367
|
-
}
|
|
15368
|
-
}
|
|
15369
|
-
},
|
|
15370
|
-
},
|
|
15371
|
-
};
|
|
15372
|
-
return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
|
|
15373
|
-
}
|
|
15374
|
-
|
|
15375
15239
|
function DataGrid({ title, data, className }) {
|
|
15376
15240
|
const { columns, rows } = data;
|
|
15377
15241
|
if (!columns || columns.length === 0 || !rows || rows.length === 0) {
|
|
@@ -36072,24 +35936,12 @@ const createInitialChartState = (agentType, widgetIds, datasetId) => {
|
|
|
36072
35936
|
const baseState = { dataset_id: datasetId || "home_generation_dataset" };
|
|
36073
35937
|
switch (agentType) {
|
|
36074
35938
|
case "Pie Chart Agent":
|
|
36075
|
-
return {
|
|
36076
|
-
pie_chart_data: {
|
|
35939
|
+
return Object.assign({ pie_chart_data: {
|
|
36077
35940
|
title: "",
|
|
36078
35941
|
type: "pie",
|
|
36079
35942
|
chart_type: "financial",
|
|
36080
35943
|
data: { labels: [], values: [], percentages: [], total: 0 },
|
|
36081
35944
|
metadata: { categories: 0, largest_category: "", largest_value: 0, largest_percentage: 0 }
|
|
36082
|
-
}
|
|
36083
|
-
};
|
|
36084
|
-
case "Line Chart Agent":
|
|
36085
|
-
case "Bar Chart Agent":
|
|
36086
|
-
return Object.assign({ bar_chart_data: {
|
|
36087
|
-
title: "",
|
|
36088
|
-
type: agentType === "Line Chart Agent" ? "line" : "bar",
|
|
36089
|
-
chart_type: "financial",
|
|
36090
|
-
orientation: agentType === "Line Chart Agent" ? "horizontal" : "vertical",
|
|
36091
|
-
data: { labels: [], values: [], total: 0, average: 0 },
|
|
36092
|
-
metadata: { categories: 0, highest_category: "", highest_value: 0, lowest_category: "", lowest_value: 0, range: 0 }
|
|
36093
35945
|
} }, baseState);
|
|
36094
35946
|
case "Series Bar Chart Agent":
|
|
36095
35947
|
case "Series Line Chart Agent":
|
|
@@ -36098,6 +35950,7 @@ const createInitialChartState = (agentType, widgetIds, datasetId) => {
|
|
|
36098
35950
|
type: "series_bar",
|
|
36099
35951
|
chart_type: "financial",
|
|
36100
35952
|
orientation: "vertical",
|
|
35953
|
+
units: "",
|
|
36101
35954
|
data: { labels: [], series: [], total: 0, average: 0 },
|
|
36102
35955
|
metadata: {
|
|
36103
35956
|
categories: 0, series_count: 0, highest_category: "", highest_value: 0, highest_series: "",
|
|
@@ -36120,7 +35973,7 @@ const createInitialChartState = (agentType, widgetIds, datasetId) => {
|
|
|
36120
35973
|
metadata: { created_at: "", content_type: "text", is_multiline: false }
|
|
36121
35974
|
} }, baseState);
|
|
36122
35975
|
default:
|
|
36123
|
-
return { widget_ids: widgetIds };
|
|
35976
|
+
return Object.assign({ widget_ids: widgetIds }, baseState);
|
|
36124
35977
|
}
|
|
36125
35978
|
};
|
|
36126
35979
|
const loadAgentState = async (widgetBackendUrl, threadId, agentName) => {
|
|
@@ -36218,58 +36071,6 @@ const getStyleValues = (styles = {}) => {
|
|
|
36218
36071
|
textAlign: alignment,
|
|
36219
36072
|
};
|
|
36220
36073
|
};
|
|
36221
|
-
function BarChartComponent({ orientation, barChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36222
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
36223
|
-
const hasCalledRef = useRef(false);
|
|
36224
|
-
const labels = ((_b = (_a = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.labels) || ((_e = (_d = (_c = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _c === void 0 ? void 0 : _c.bar_chart_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.labels) || [];
|
|
36225
|
-
const values = ((_g = (_f = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.values) || ((_k = (_j = (_h = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _h === void 0 ? void 0 : _h.bar_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.values) || [];
|
|
36226
|
-
const chartTitle = ((_l = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _l === void 0 ? void 0 : _l.title) || ((_o = (_m = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _m === void 0 ? void 0 : _m.bar_chart_data) === null || _o === void 0 ? void 0 : _o.title) || "";
|
|
36227
|
-
const units = ((_p = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _p === void 0 ? void 0 : _p.units) || ((_r = (_q = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _q === void 0 ? void 0 : _q.bar_chart_data) === null || _r === void 0 ? void 0 : _r.units) || "";
|
|
36228
|
-
values.length > 0 ? Math.max(...values) : 0;
|
|
36229
|
-
const isEmpty = labels.length === 0 || values.length === 0;
|
|
36230
|
-
const handleRefresh = async () => {
|
|
36231
|
-
if (query && widgetBackendUrl && widgetId) {
|
|
36232
|
-
await clearChat(widgetBackendUrl, widgetId);
|
|
36233
|
-
appendMessage(new TextMessage({
|
|
36234
|
-
content: `${query} and render data on a bar chart`,
|
|
36235
|
-
role: Role.User,
|
|
36236
|
-
}));
|
|
36237
|
-
}
|
|
36238
|
-
};
|
|
36239
|
-
useEffect(() => {
|
|
36240
|
-
if (isEmpty && query && isFirstLoad && !(barChartState === null || barChartState === void 0 ? void 0 : barChartState.agent_message) && !hasCalledRef.current) {
|
|
36241
|
-
// console.log('calling append message')
|
|
36242
|
-
hasCalledRef.current = true;
|
|
36243
|
-
handleRefresh();
|
|
36244
|
-
}
|
|
36245
|
-
}, [isEmpty, query, isFirstLoad, barChartState]);
|
|
36246
|
-
// Start timeout when chart is empty and loading
|
|
36247
|
-
useEffect(() => {
|
|
36248
|
-
if (isEmpty && startLoadingTimeout && !(barChartState === null || barChartState === void 0 ? void 0 : barChartState.agent_message)) {
|
|
36249
|
-
startLoadingTimeout();
|
|
36250
|
-
}
|
|
36251
|
-
else if (!isEmpty && clearLoadingTimeout) {
|
|
36252
|
-
clearLoadingTimeout();
|
|
36253
|
-
}
|
|
36254
|
-
}, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
|
|
36255
|
-
const finalColors = useMemo(() => {
|
|
36256
|
-
return shuffleColors(DEFAULT_COLORS, labels === null || labels === void 0 ? void 0 : labels.length);
|
|
36257
|
-
}, [labels.length]);
|
|
36258
|
-
if (isEmpty) {
|
|
36259
|
-
return createLoadingComponent();
|
|
36260
|
-
}
|
|
36261
|
-
const transformedData = {
|
|
36262
|
-
labels: labels,
|
|
36263
|
-
datasets: [
|
|
36264
|
-
{
|
|
36265
|
-
label: chartTitle || "Data",
|
|
36266
|
-
data: values,
|
|
36267
|
-
backgroundColor: finalColors,
|
|
36268
|
-
},
|
|
36269
|
-
],
|
|
36270
|
-
};
|
|
36271
|
-
return (jsxRuntimeExports.jsx(BarChart, { orientation: orientation, title: chartTitle, data: transformedData, units: units }));
|
|
36272
|
-
}
|
|
36273
36074
|
function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36274
36075
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
36275
36076
|
const hasCalledRef = useRef(false);
|
|
@@ -36280,7 +36081,7 @@ function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, app
|
|
|
36280
36081
|
const isEmpty = labels.length === 0 || series.length === 0;
|
|
36281
36082
|
const handleRefresh = async () => {
|
|
36282
36083
|
if (query) {
|
|
36283
|
-
await clearChat();
|
|
36084
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36284
36085
|
// Send trigger event to clear chart state
|
|
36285
36086
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36286
36087
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36331,7 +36132,7 @@ function SeriesLineChartComponent({ orientation, seriesLineChartState, styles, a
|
|
|
36331
36132
|
const isEmpty = labels.length === 0 || series.length === 0;
|
|
36332
36133
|
const handleRefresh = async () => {
|
|
36333
36134
|
if (query) {
|
|
36334
|
-
await clearChat();
|
|
36135
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36335
36136
|
// Send trigger event to clear chart state
|
|
36336
36137
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36337
36138
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36390,7 +36191,7 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
|
|
|
36390
36191
|
const isEmpty = labels.length === 0 || values.length === 0;
|
|
36391
36192
|
const handleRefresh = async () => {
|
|
36392
36193
|
if (query) {
|
|
36393
|
-
await clearChat();
|
|
36194
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36394
36195
|
// Send trigger event to clear chart state
|
|
36395
36196
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36396
36197
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36434,63 +36235,6 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
|
|
|
36434
36235
|
};
|
|
36435
36236
|
return (jsxRuntimeExports.jsx(PieChart, { title: chartTitle, data: transformedData, units: units }));
|
|
36436
36237
|
}
|
|
36437
|
-
function LineChartComponent({ lineChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36438
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
36439
|
-
const hasCalledRef = useRef(false);
|
|
36440
|
-
const labels = ((_b = (_a = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.labels) || ((_e = (_d = (_c = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _c === void 0 ? void 0 : _c.bar_chart_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.labels) || [];
|
|
36441
|
-
const values = ((_g = (_f = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.values) || ((_k = (_j = (_h = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _h === void 0 ? void 0 : _h.bar_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.values) || [];
|
|
36442
|
-
const chartTitle = ((_l = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _l === void 0 ? void 0 : _l.title) || ((_o = (_m = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _m === void 0 ? void 0 : _m.bar_chart_data) === null || _o === void 0 ? void 0 : _o.title) || "";
|
|
36443
|
-
const units = ((_p = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _p === void 0 ? void 0 : _p.units) || ((_r = (_q = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _q === void 0 ? void 0 : _q.bar_chart_data) === null || _r === void 0 ? void 0 : _r.units) || "";
|
|
36444
|
-
values.length > 0 ? Math.max(...values) : 0;
|
|
36445
|
-
const isEmpty = labels.length === 0 || values.length === 0;
|
|
36446
|
-
const handleRefresh = async () => {
|
|
36447
|
-
if (query && widgetBackendUrl && widgetId) {
|
|
36448
|
-
await clearChat(widgetBackendUrl, widgetId);
|
|
36449
|
-
appendMessage(new TextMessage({
|
|
36450
|
-
content: `${query} and render data on a bar chart`,
|
|
36451
|
-
role: Role.User,
|
|
36452
|
-
}));
|
|
36453
|
-
}
|
|
36454
|
-
};
|
|
36455
|
-
useEffect(() => {
|
|
36456
|
-
if (isEmpty && query && isFirstLoad && !(lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.agent_message) && !hasCalledRef.current) {
|
|
36457
|
-
hasCalledRef.current = true;
|
|
36458
|
-
handleRefresh();
|
|
36459
|
-
}
|
|
36460
|
-
}, [isEmpty, query, isFirstLoad, lineChartState]);
|
|
36461
|
-
// Start timeout when chart is empty and loading
|
|
36462
|
-
useEffect(() => {
|
|
36463
|
-
if (isEmpty && startLoadingTimeout && !(lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.agent_message)) {
|
|
36464
|
-
startLoadingTimeout();
|
|
36465
|
-
}
|
|
36466
|
-
else if (!isEmpty && clearLoadingTimeout) {
|
|
36467
|
-
clearLoadingTimeout();
|
|
36468
|
-
}
|
|
36469
|
-
}, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
|
|
36470
|
-
const lineColor = useMemo(() => {
|
|
36471
|
-
return LINE_COLORS[Math.floor(Math.random() * LINE_COLORS.length)];
|
|
36472
|
-
}, [labels.length]);
|
|
36473
|
-
if (isEmpty) {
|
|
36474
|
-
return createLoadingComponent();
|
|
36475
|
-
}
|
|
36476
|
-
const transformedData = {
|
|
36477
|
-
labels: labels,
|
|
36478
|
-
datasets: [
|
|
36479
|
-
{
|
|
36480
|
-
label: chartTitle || "Data",
|
|
36481
|
-
data: values,
|
|
36482
|
-
borderColor: lineColor,
|
|
36483
|
-
backgroundColor: "rgba(96, 165, 250, 0.1)",
|
|
36484
|
-
borderWidth: 2,
|
|
36485
|
-
pointBackgroundColor: lineColor,
|
|
36486
|
-
pointBorderColor: lineColor,
|
|
36487
|
-
pointRadius: 4,
|
|
36488
|
-
fill: true,
|
|
36489
|
-
},
|
|
36490
|
-
],
|
|
36491
|
-
};
|
|
36492
|
-
return (jsxRuntimeExports.jsx(LineChart, { title: chartTitle, data: transformedData, units: units }));
|
|
36493
|
-
}
|
|
36494
36238
|
function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36495
36239
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
36496
36240
|
const hasCalledRef = useRef(false);
|
|
@@ -36500,7 +36244,7 @@ function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirs
|
|
|
36500
36244
|
const isEmpty = columns.length === 0 || rows.length === 0;
|
|
36501
36245
|
const handleRefresh = async () => {
|
|
36502
36246
|
if (query) {
|
|
36503
|
-
await clearChat();
|
|
36247
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36504
36248
|
// Send trigger event to clear chart state
|
|
36505
36249
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36506
36250
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36544,7 +36288,7 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
|
|
|
36544
36288
|
const isEmpty = !content || content.trim() === "";
|
|
36545
36289
|
const handleRefresh = async () => {
|
|
36546
36290
|
if (query) {
|
|
36547
|
-
await clearChat();
|
|
36291
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36548
36292
|
// Send trigger event to clear chart state
|
|
36549
36293
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36550
36294
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36578,7 +36322,7 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
|
|
|
36578
36322
|
return (jsxRuntimeExports.jsx(SummaryWidget, { title: title, data: data, metadata: metadata, className: "" }));
|
|
36579
36323
|
}
|
|
36580
36324
|
function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds, widgetBackendUrl, datasetId }) {
|
|
36581
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18
|
|
36325
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
|
|
36582
36326
|
const agentType = (_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentType;
|
|
36583
36327
|
const orientation = (_b = widget.config) === null || _b === void 0 ? void 0 : _b.orientation;
|
|
36584
36328
|
const isFirstLoad = (_c = widget.config) === null || _c === void 0 ? void 0 : _c.isFirstLoad;
|
|
@@ -36587,6 +36331,8 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
|
|
|
36587
36331
|
const [isTimeoutTriggered, setIsTimeoutTriggered] = useState(false);
|
|
36588
36332
|
const [apiCallCount, setApiCallCount] = useState(0);
|
|
36589
36333
|
const [hasTimeoutError, setHasTimeoutError] = useState(false);
|
|
36334
|
+
const [isAgentTriggered, setIsAgentTriggered] = useState(false);
|
|
36335
|
+
const pollingIntervalRef = useRef(null);
|
|
36590
36336
|
useEffect(() => {
|
|
36591
36337
|
setThreadId(widget.id);
|
|
36592
36338
|
}, [widget.id, setThreadId]);
|
|
@@ -36633,38 +36379,75 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
|
|
|
36633
36379
|
timeoutRef.current = null;
|
|
36634
36380
|
}
|
|
36635
36381
|
}, []);
|
|
36636
|
-
// Function to
|
|
36637
|
-
useCallback(
|
|
36638
|
-
|
|
36382
|
+
// Function to start polling for data availability
|
|
36383
|
+
const startPollingForData = useCallback(() => {
|
|
36384
|
+
var _a;
|
|
36385
|
+
if (!widgetBackendUrl || !((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName))
|
|
36639
36386
|
return;
|
|
36640
|
-
|
|
36641
|
-
|
|
36642
|
-
|
|
36643
|
-
|
|
36644
|
-
|
|
36645
|
-
|
|
36646
|
-
|
|
36647
|
-
|
|
36648
|
-
|
|
36649
|
-
|
|
36650
|
-
|
|
36651
|
-
|
|
36652
|
-
|
|
36653
|
-
|
|
36654
|
-
|
|
36655
|
-
|
|
36656
|
-
|
|
36657
|
-
|
|
36658
|
-
|
|
36659
|
-
|
|
36387
|
+
setIsAgentTriggered(true);
|
|
36388
|
+
setApiCallCount(0);
|
|
36389
|
+
setHasTimeoutError(false);
|
|
36390
|
+
// Clear any existing polling interval
|
|
36391
|
+
if (pollingIntervalRef.current) {
|
|
36392
|
+
clearInterval(pollingIntervalRef.current);
|
|
36393
|
+
}
|
|
36394
|
+
// Start polling immediately, then every CHART_REFRESH_TIMEOUT
|
|
36395
|
+
const pollForData = async () => {
|
|
36396
|
+
var _a, _b, _c;
|
|
36397
|
+
if (apiCallCount >= 10) {
|
|
36398
|
+
setHasTimeoutError(true);
|
|
36399
|
+
setIsAgentTriggered(false);
|
|
36400
|
+
if (pollingIntervalRef.current) {
|
|
36401
|
+
clearInterval(pollingIntervalRef.current);
|
|
36402
|
+
pollingIntervalRef.current = null;
|
|
36403
|
+
}
|
|
36404
|
+
return;
|
|
36405
|
+
}
|
|
36406
|
+
setApiCallCount(prev => prev + 1);
|
|
36407
|
+
const agentName = ((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName) || "adk-construction-project-agent";
|
|
36408
|
+
const apiResponse = await loadAgentState(widgetBackendUrl, widget.id, agentName);
|
|
36409
|
+
if (apiResponse && ((_c = (_b = apiResponse.data) === null || _b === void 0 ? void 0 : _b.loadAgentState) === null || _c === void 0 ? void 0 : _c.state)) {
|
|
36410
|
+
parseAndUpdateChartState(apiResponse, setChartState);
|
|
36411
|
+
setIsAgentTriggered(false);
|
|
36412
|
+
if (pollingIntervalRef.current) {
|
|
36413
|
+
clearInterval(pollingIntervalRef.current);
|
|
36414
|
+
pollingIntervalRef.current = null;
|
|
36415
|
+
}
|
|
36416
|
+
}
|
|
36417
|
+
};
|
|
36418
|
+
// Poll immediately
|
|
36419
|
+
pollForData();
|
|
36420
|
+
// Then poll every CHART_REFRESH_TIMEOUT
|
|
36421
|
+
pollingIntervalRef.current = setInterval(pollForData, CHART_REFRESH_TIMEOUT);
|
|
36422
|
+
// Set a maximum timeout to stop polling after 10 attempts
|
|
36423
|
+
setTimeout(() => {
|
|
36424
|
+
if (pollingIntervalRef.current) {
|
|
36425
|
+
clearInterval(pollingIntervalRef.current);
|
|
36426
|
+
pollingIntervalRef.current = null;
|
|
36427
|
+
setIsAgentTriggered(false);
|
|
36428
|
+
if (apiCallCount >= 10) {
|
|
36429
|
+
setHasTimeoutError(true);
|
|
36430
|
+
}
|
|
36431
|
+
}
|
|
36432
|
+
}, CHART_REFRESH_TIMEOUT * 10);
|
|
36433
|
+
}, [widgetBackendUrl, (_f = widget.config) === null || _f === void 0 ? void 0 : _f.agentName, widget.id, apiCallCount, setChartState]);
|
|
36434
|
+
// Clean up timeout and polling on unmount
|
|
36660
36435
|
useEffect(() => {
|
|
36661
36436
|
return () => {
|
|
36662
36437
|
if (timeoutRef.current) {
|
|
36663
36438
|
clearTimeout(timeoutRef.current);
|
|
36664
36439
|
}
|
|
36440
|
+
if (pollingIntervalRef.current) {
|
|
36441
|
+
clearInterval(pollingIntervalRef.current);
|
|
36442
|
+
}
|
|
36665
36443
|
};
|
|
36666
36444
|
}, []);
|
|
36667
|
-
const { appendMessage, reset } = useCopilotChat();
|
|
36445
|
+
const { appendMessage: originalAppendMessage, reset } = useCopilotChat();
|
|
36446
|
+
// Wrapper function for appendMessage that triggers polling
|
|
36447
|
+
const appendMessage = useCallback((message) => {
|
|
36448
|
+
startPollingForData();
|
|
36449
|
+
return originalAppendMessage(message);
|
|
36450
|
+
}, [originalAppendMessage, startPollingForData]);
|
|
36668
36451
|
// Register the reset function with the parent component
|
|
36669
36452
|
useEffect(() => {
|
|
36670
36453
|
if (onResetReady && reset && widget.id) {
|
|
@@ -36726,17 +36509,16 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
|
|
|
36726
36509
|
}, [widget.id, appendMessage, agentType, setChartState]);
|
|
36727
36510
|
return (jsxRuntimeExports.jsxs("div", { className: cn("flex flex-col h-full"), children: [showHeader && (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-between pb-2 border-b", children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(Bot, { className: "h-4 w-4" }), jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })] }) })), jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState === null || chartState === void 0 ? void 0 : chartState.agent_message) && agentType !== "chatbot" && (
|
|
36728
36511
|
// Check if data is empty based on agent type
|
|
36729
|
-
(agentType === "Bar Chart Agent" && (!((
|
|
36730
|
-
(agentType === "Series
|
|
36731
|
-
(agentType === "
|
|
36732
|
-
(agentType === "
|
|
36733
|
-
(agentType === "
|
|
36734
|
-
|
|
36735
|
-
|
|
36736
|
-
title: ((_29 = widget.config) === null || _29 === void 0 ? void 0 : _29.copilotTitle) || widget.title,
|
|
36737
|
-
initial: ((_30 = widget.config) === null || _30 === void 0 ? void 0 : _30.copilotInitialMessage) || ((_31 = widget.config) === null || _31 === void 0 ? void 0 : _31.placeholder) || "How can I help you today?"
|
|
36512
|
+
(agentType === "Series Bar Chart Agent" && (!((_j = (_h = (_g = chartState.series_bar_chart_data) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.labels) === null || _j === void 0 ? void 0 : _j.length) || !((_m = (_l = (_k = chartState.series_bar_chart_data) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.series) === null || _m === void 0 ? void 0 : _m.length))) ||
|
|
36513
|
+
(agentType === "Series Line Chart Agent" && (!((_q = (_p = (_o = chartState.series_bar_chart_data) === null || _o === void 0 ? void 0 : _o.data) === null || _p === void 0 ? void 0 : _p.labels) === null || _q === void 0 ? void 0 : _q.length) || !((_t = (_s = (_r = chartState.series_bar_chart_data) === null || _r === void 0 ? void 0 : _r.data) === null || _s === void 0 ? void 0 : _s.series) === null || _t === void 0 ? void 0 : _t.length))) ||
|
|
36514
|
+
(agentType === "Pie Chart Agent" && (!((_w = (_v = (_u = chartState.pie_chart_data) === null || _u === void 0 ? void 0 : _u.data) === null || _v === void 0 ? void 0 : _v.labels) === null || _w === void 0 ? void 0 : _w.length) || !((_z = (_y = (_x = chartState.pie_chart_data) === null || _x === void 0 ? void 0 : _x.data) === null || _y === void 0 ? void 0 : _y.values) === null || _z === void 0 ? void 0 : _z.length))) ||
|
|
36515
|
+
(agentType === "Data Grid Agent" && (!((_2 = (_1 = (_0 = chartState.matrix_grid_data) === null || _0 === void 0 ? void 0 : _0.data) === null || _1 === void 0 ? void 0 : _1.headers) === null || _2 === void 0 ? void 0 : _2.length) || !((_5 = (_4 = (_3 = chartState.matrix_grid_data) === null || _3 === void 0 ? void 0 : _3.data) === null || _4 === void 0 ? void 0 : _4.rows) === null || _5 === void 0 ? void 0 : _5.length))) ||
|
|
36516
|
+
(agentType === "Summary Agent" && (!((_7 = (_6 = chartState.summary_data) === null || _6 === void 0 ? void 0 : _6.data) === null || _7 === void 0 ? void 0 : _7.content) || ((_10 = (_9 = (_8 = chartState.summary_data) === null || _8 === void 0 ? void 0 : _8.data) === null || _9 === void 0 ? void 0 : _9.content) === null || _10 === void 0 ? void 0 : _10.trim()) === ""))) ? (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) })) : isAgentTriggered ? (createLoadingComponent("Agent processing your request...")) : agentType === "Series Bar Chart Agent" ? (jsxRuntimeExports.jsx(SeriesBarChartComponent, { seriesBarChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_11 = widget.config) === null || _11 === void 0 ? void 0 : _11.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Series Line Chart Agent" ? (jsxRuntimeExports.jsx(SeriesLineChartComponent, { seriesLineChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_12 = widget.config) === null || _12 === void 0 ? void 0 : _12.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Pie Chart Agent" ? (jsxRuntimeExports.jsx(PieChartComponent, { pieChartState: chartState, styles: styles, appendMessage: appendMessage, query: (_13 = widget.config) === null || _13 === void 0 ? void 0 : _13.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Data Grid Agent" ? (jsxRuntimeExports.jsx(DataGridComponent, { dataGridState: chartState, styles: styles, appendMessage: appendMessage, query: (_14 = widget.config) === null || _14 === void 0 ? void 0 : _14.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Summary Agent" ? (jsxRuntimeExports.jsx(SummaryComponent, { summaryState: chartState, styles: styles, appendMessage: appendMessage, query: (_15 = widget.config) === null || _15 === void 0 ? void 0 : _15.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, widget_ids: widgetIds, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout, setChartState: setChartState })) : (jsxRuntimeExports.jsx(CopilotChat, { className: "h-full text-xs [&_.copilot-chat-message]:text-xs [&_.copilot-chat-input]:text-xs", labels: {
|
|
36517
|
+
title: ((_16 = widget.config) === null || _16 === void 0 ? void 0 : _16.copilotTitle) || widget.title,
|
|
36518
|
+
initial: ((_17 = widget.config) === null || _17 === void 0 ? void 0 : _17.copilotInitialMessage) || ((_18 = widget.config) === null || _18 === void 0 ? void 0 : _18.placeholder) || "How can I help you today?"
|
|
36738
36519
|
}, onSubmitMessage: () => {
|
|
36739
36520
|
setChartState(prevState => (Object.assign(Object.assign({}, prevState), { widget_ids: widgetIds, dataset_id: datasetId })));
|
|
36521
|
+
startPollingForData();
|
|
36740
36522
|
} })) })] }));
|
|
36741
36523
|
}
|
|
36742
36524
|
function AgentWidget({ widget, showHeader = true, widgetBackendUrl, onResetReady, widgetIds, datasetId, }) {
|
|
@@ -36820,14 +36602,14 @@ function AddWidgetDialog({ isOpen, onClose, addWidgetFn, defaultAgentName = "adk
|
|
|
36820
36602
|
{
|
|
36821
36603
|
type: 'series-bar-chart',
|
|
36822
36604
|
title: 'Bar Chart Widget',
|
|
36823
|
-
icon: BarChart
|
|
36605
|
+
icon: BarChart,
|
|
36824
36606
|
description: 'Create interactive series bar charts with custom queries',
|
|
36825
36607
|
configRequired: true
|
|
36826
36608
|
},
|
|
36827
36609
|
{
|
|
36828
36610
|
type: 'series-line-chart',
|
|
36829
36611
|
title: 'Line Chart Widget',
|
|
36830
|
-
icon: LineChart
|
|
36612
|
+
icon: LineChart,
|
|
36831
36613
|
description: 'Create interactive series line charts with custom queries',
|
|
36832
36614
|
configRequired: true
|
|
36833
36615
|
},
|
|
@@ -37003,13 +36785,13 @@ const IconMap = {
|
|
|
37003
36785
|
search: Search,
|
|
37004
36786
|
filter: Filter,
|
|
37005
36787
|
results: LayoutGrid,
|
|
37006
|
-
analytics: BarChart
|
|
36788
|
+
analytics: BarChart,
|
|
37007
36789
|
custom: LayoutGrid,
|
|
37008
36790
|
header: Layout,
|
|
37009
36791
|
footer: Layout,
|
|
37010
36792
|
text: Type,
|
|
37011
36793
|
agent: Bot,
|
|
37012
|
-
'bar-chart': BarChart
|
|
36794
|
+
'bar-chart': BarChart,
|
|
37013
36795
|
'pie-chart': PieChart$1,
|
|
37014
36796
|
'chatbot': Bot,
|
|
37015
36797
|
};
|
package/dist/index.js
CHANGED
|
@@ -15075,78 +15075,6 @@ const Line = /* #__PURE__ */ createTypedChart('line', LineController);
|
|
|
15075
15075
|
const Bar = /* #__PURE__ */ createTypedChart('bar', BarController);
|
|
15076
15076
|
const Pie = /* #__PURE__ */ createTypedChart('pie', PieController);
|
|
15077
15077
|
|
|
15078
|
-
Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
|
|
15079
|
-
function BarChart({ orientation, title, data, options, className, units }) {
|
|
15080
|
-
const formatValue = (value) => {
|
|
15081
|
-
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
15082
|
-
if (units === '$' && !isNaN(numValue)) {
|
|
15083
|
-
return numValue.toLocaleString();
|
|
15084
|
-
}
|
|
15085
|
-
return value;
|
|
15086
|
-
};
|
|
15087
|
-
const defaultOptions = {
|
|
15088
|
-
responsive: true,
|
|
15089
|
-
maintainAspectRatio: false,
|
|
15090
|
-
indexAxis: orientation === "horizontal" ? "y" : "x",
|
|
15091
|
-
layout: {
|
|
15092
|
-
padding: {
|
|
15093
|
-
bottom: 0,
|
|
15094
|
-
top: 0,
|
|
15095
|
-
left: 0,
|
|
15096
|
-
right: 0,
|
|
15097
|
-
},
|
|
15098
|
-
},
|
|
15099
|
-
plugins: {
|
|
15100
|
-
legend: {
|
|
15101
|
-
display: false,
|
|
15102
|
-
labels: {
|
|
15103
|
-
boxWidth: 5,
|
|
15104
|
-
boxHeight: 5,
|
|
15105
|
-
},
|
|
15106
|
-
position: "bottom"
|
|
15107
|
-
},
|
|
15108
|
-
title: {
|
|
15109
|
-
display: true,
|
|
15110
|
-
text: title,
|
|
15111
|
-
font: {
|
|
15112
|
-
size: 18,
|
|
15113
|
-
weight: "bold",
|
|
15114
|
-
},
|
|
15115
|
-
color: "#0F172A"
|
|
15116
|
-
},
|
|
15117
|
-
tooltip: {
|
|
15118
|
-
callbacks: {
|
|
15119
|
-
label: function (context) {
|
|
15120
|
-
const value = context.parsed.y || context.parsed.x;
|
|
15121
|
-
return units ? `${context.dataset.label}: ${formatValue(value)} ${units}` : `${context.dataset.label}: ${value}`;
|
|
15122
|
-
}
|
|
15123
|
-
}
|
|
15124
|
-
},
|
|
15125
|
-
},
|
|
15126
|
-
scales: {
|
|
15127
|
-
x: {
|
|
15128
|
-
ticks: {
|
|
15129
|
-
autoSkip: false,
|
|
15130
|
-
maxRotation: 45,
|
|
15131
|
-
minRotation: 45,
|
|
15132
|
-
font: {
|
|
15133
|
-
size: 10
|
|
15134
|
-
}
|
|
15135
|
-
},
|
|
15136
|
-
},
|
|
15137
|
-
y: {
|
|
15138
|
-
beginAtZero: true,
|
|
15139
|
-
ticks: {
|
|
15140
|
-
callback: function (value) {
|
|
15141
|
-
return units ? `${formatValue(value)} ${units}` : value;
|
|
15142
|
-
}
|
|
15143
|
-
}
|
|
15144
|
-
},
|
|
15145
|
-
},
|
|
15146
|
-
};
|
|
15147
|
-
return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
|
|
15148
|
-
}
|
|
15149
|
-
|
|
15150
15078
|
Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
|
|
15151
15079
|
function SeriesChart({ orientation, title, data, options, className, units }) {
|
|
15152
15080
|
const formatValue = (value) => {
|
|
@@ -15335,70 +15263,6 @@ const PieChart = (props) => {
|
|
|
15335
15263
|
return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions });
|
|
15336
15264
|
};
|
|
15337
15265
|
|
|
15338
|
-
Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
|
|
15339
|
-
function LineChart({ title, data, options, className, units }) {
|
|
15340
|
-
const formatValue = (value) => {
|
|
15341
|
-
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
15342
|
-
if (units === '$' && !isNaN(numValue)) {
|
|
15343
|
-
return numValue.toLocaleString();
|
|
15344
|
-
}
|
|
15345
|
-
return value;
|
|
15346
|
-
};
|
|
15347
|
-
const defaultOptions = {
|
|
15348
|
-
responsive: true,
|
|
15349
|
-
maintainAspectRatio: false,
|
|
15350
|
-
layout: {
|
|
15351
|
-
padding: {
|
|
15352
|
-
bottom: 0,
|
|
15353
|
-
top: 0,
|
|
15354
|
-
left: 0,
|
|
15355
|
-
right: 0,
|
|
15356
|
-
},
|
|
15357
|
-
},
|
|
15358
|
-
plugins: {
|
|
15359
|
-
legend: {
|
|
15360
|
-
display: false,
|
|
15361
|
-
labels: {
|
|
15362
|
-
boxWidth: 5,
|
|
15363
|
-
boxHeight: 5,
|
|
15364
|
-
},
|
|
15365
|
-
position: "bottom"
|
|
15366
|
-
},
|
|
15367
|
-
title: {
|
|
15368
|
-
display: true,
|
|
15369
|
-
text: title,
|
|
15370
|
-
font: {
|
|
15371
|
-
size: 18,
|
|
15372
|
-
weight: "bold",
|
|
15373
|
-
},
|
|
15374
|
-
color: "#0F172A"
|
|
15375
|
-
},
|
|
15376
|
-
tooltip: {
|
|
15377
|
-
callbacks: {
|
|
15378
|
-
label: function (context) {
|
|
15379
|
-
const value = context.parsed.y;
|
|
15380
|
-
return units ? `${context.dataset.label}: ${formatValue(value)} ${units}` : `${context.dataset.label}: ${value}`;
|
|
15381
|
-
}
|
|
15382
|
-
}
|
|
15383
|
-
},
|
|
15384
|
-
},
|
|
15385
|
-
scales: {
|
|
15386
|
-
x: {
|
|
15387
|
-
ticks: { autoSkip: true, maxTicksLimit: 8, maxRotation: 45, minRotation: 0 },
|
|
15388
|
-
},
|
|
15389
|
-
y: {
|
|
15390
|
-
beginAtZero: true,
|
|
15391
|
-
ticks: {
|
|
15392
|
-
callback: function (value) {
|
|
15393
|
-
return units ? `${formatValue(value)} ${units}` : value;
|
|
15394
|
-
}
|
|
15395
|
-
}
|
|
15396
|
-
},
|
|
15397
|
-
},
|
|
15398
|
-
};
|
|
15399
|
-
return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
|
|
15400
|
-
}
|
|
15401
|
-
|
|
15402
15266
|
function DataGrid({ title, data, className }) {
|
|
15403
15267
|
const { columns, rows } = data;
|
|
15404
15268
|
if (!columns || columns.length === 0 || !rows || rows.length === 0) {
|
|
@@ -36099,24 +35963,12 @@ const createInitialChartState = (agentType, widgetIds, datasetId) => {
|
|
|
36099
35963
|
const baseState = { dataset_id: datasetId || "home_generation_dataset" };
|
|
36100
35964
|
switch (agentType) {
|
|
36101
35965
|
case "Pie Chart Agent":
|
|
36102
|
-
return {
|
|
36103
|
-
pie_chart_data: {
|
|
35966
|
+
return Object.assign({ pie_chart_data: {
|
|
36104
35967
|
title: "",
|
|
36105
35968
|
type: "pie",
|
|
36106
35969
|
chart_type: "financial",
|
|
36107
35970
|
data: { labels: [], values: [], percentages: [], total: 0 },
|
|
36108
35971
|
metadata: { categories: 0, largest_category: "", largest_value: 0, largest_percentage: 0 }
|
|
36109
|
-
}
|
|
36110
|
-
};
|
|
36111
|
-
case "Line Chart Agent":
|
|
36112
|
-
case "Bar Chart Agent":
|
|
36113
|
-
return Object.assign({ bar_chart_data: {
|
|
36114
|
-
title: "",
|
|
36115
|
-
type: agentType === "Line Chart Agent" ? "line" : "bar",
|
|
36116
|
-
chart_type: "financial",
|
|
36117
|
-
orientation: agentType === "Line Chart Agent" ? "horizontal" : "vertical",
|
|
36118
|
-
data: { labels: [], values: [], total: 0, average: 0 },
|
|
36119
|
-
metadata: { categories: 0, highest_category: "", highest_value: 0, lowest_category: "", lowest_value: 0, range: 0 }
|
|
36120
35972
|
} }, baseState);
|
|
36121
35973
|
case "Series Bar Chart Agent":
|
|
36122
35974
|
case "Series Line Chart Agent":
|
|
@@ -36125,6 +35977,7 @@ const createInitialChartState = (agentType, widgetIds, datasetId) => {
|
|
|
36125
35977
|
type: "series_bar",
|
|
36126
35978
|
chart_type: "financial",
|
|
36127
35979
|
orientation: "vertical",
|
|
35980
|
+
units: "",
|
|
36128
35981
|
data: { labels: [], series: [], total: 0, average: 0 },
|
|
36129
35982
|
metadata: {
|
|
36130
35983
|
categories: 0, series_count: 0, highest_category: "", highest_value: 0, highest_series: "",
|
|
@@ -36147,7 +36000,7 @@ const createInitialChartState = (agentType, widgetIds, datasetId) => {
|
|
|
36147
36000
|
metadata: { created_at: "", content_type: "text", is_multiline: false }
|
|
36148
36001
|
} }, baseState);
|
|
36149
36002
|
default:
|
|
36150
|
-
return { widget_ids: widgetIds };
|
|
36003
|
+
return Object.assign({ widget_ids: widgetIds }, baseState);
|
|
36151
36004
|
}
|
|
36152
36005
|
};
|
|
36153
36006
|
const loadAgentState = async (widgetBackendUrl, threadId, agentName) => {
|
|
@@ -36245,58 +36098,6 @@ const getStyleValues = (styles = {}) => {
|
|
|
36245
36098
|
textAlign: alignment,
|
|
36246
36099
|
};
|
|
36247
36100
|
};
|
|
36248
|
-
function BarChartComponent({ orientation, barChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36249
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
36250
|
-
const hasCalledRef = React.useRef(false);
|
|
36251
|
-
const labels = ((_b = (_a = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.labels) || ((_e = (_d = (_c = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _c === void 0 ? void 0 : _c.bar_chart_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.labels) || [];
|
|
36252
|
-
const values = ((_g = (_f = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.values) || ((_k = (_j = (_h = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _h === void 0 ? void 0 : _h.bar_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.values) || [];
|
|
36253
|
-
const chartTitle = ((_l = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _l === void 0 ? void 0 : _l.title) || ((_o = (_m = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _m === void 0 ? void 0 : _m.bar_chart_data) === null || _o === void 0 ? void 0 : _o.title) || "";
|
|
36254
|
-
const units = ((_p = barChartState === null || barChartState === void 0 ? void 0 : barChartState.bar_chart_data) === null || _p === void 0 ? void 0 : _p.units) || ((_r = (_q = barChartState === null || barChartState === void 0 ? void 0 : barChartState.state) === null || _q === void 0 ? void 0 : _q.bar_chart_data) === null || _r === void 0 ? void 0 : _r.units) || "";
|
|
36255
|
-
values.length > 0 ? Math.max(...values) : 0;
|
|
36256
|
-
const isEmpty = labels.length === 0 || values.length === 0;
|
|
36257
|
-
const handleRefresh = async () => {
|
|
36258
|
-
if (query && widgetBackendUrl && widgetId) {
|
|
36259
|
-
await clearChat(widgetBackendUrl, widgetId);
|
|
36260
|
-
appendMessage(new TextMessage({
|
|
36261
|
-
content: `${query} and render data on a bar chart`,
|
|
36262
|
-
role: Role.User,
|
|
36263
|
-
}));
|
|
36264
|
-
}
|
|
36265
|
-
};
|
|
36266
|
-
React.useEffect(() => {
|
|
36267
|
-
if (isEmpty && query && isFirstLoad && !(barChartState === null || barChartState === void 0 ? void 0 : barChartState.agent_message) && !hasCalledRef.current) {
|
|
36268
|
-
// console.log('calling append message')
|
|
36269
|
-
hasCalledRef.current = true;
|
|
36270
|
-
handleRefresh();
|
|
36271
|
-
}
|
|
36272
|
-
}, [isEmpty, query, isFirstLoad, barChartState]);
|
|
36273
|
-
// Start timeout when chart is empty and loading
|
|
36274
|
-
React.useEffect(() => {
|
|
36275
|
-
if (isEmpty && startLoadingTimeout && !(barChartState === null || barChartState === void 0 ? void 0 : barChartState.agent_message)) {
|
|
36276
|
-
startLoadingTimeout();
|
|
36277
|
-
}
|
|
36278
|
-
else if (!isEmpty && clearLoadingTimeout) {
|
|
36279
|
-
clearLoadingTimeout();
|
|
36280
|
-
}
|
|
36281
|
-
}, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
|
|
36282
|
-
const finalColors = React.useMemo(() => {
|
|
36283
|
-
return shuffleColors(DEFAULT_COLORS, labels === null || labels === void 0 ? void 0 : labels.length);
|
|
36284
|
-
}, [labels.length]);
|
|
36285
|
-
if (isEmpty) {
|
|
36286
|
-
return createLoadingComponent();
|
|
36287
|
-
}
|
|
36288
|
-
const transformedData = {
|
|
36289
|
-
labels: labels,
|
|
36290
|
-
datasets: [
|
|
36291
|
-
{
|
|
36292
|
-
label: chartTitle || "Data",
|
|
36293
|
-
data: values,
|
|
36294
|
-
backgroundColor: finalColors,
|
|
36295
|
-
},
|
|
36296
|
-
],
|
|
36297
|
-
};
|
|
36298
|
-
return (jsxRuntimeExports.jsx(BarChart, { orientation: orientation, title: chartTitle, data: transformedData, units: units }));
|
|
36299
|
-
}
|
|
36300
36101
|
function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36301
36102
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
36302
36103
|
const hasCalledRef = React.useRef(false);
|
|
@@ -36307,7 +36108,7 @@ function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, app
|
|
|
36307
36108
|
const isEmpty = labels.length === 0 || series.length === 0;
|
|
36308
36109
|
const handleRefresh = async () => {
|
|
36309
36110
|
if (query) {
|
|
36310
|
-
await clearChat();
|
|
36111
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36311
36112
|
// Send trigger event to clear chart state
|
|
36312
36113
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36313
36114
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36358,7 +36159,7 @@ function SeriesLineChartComponent({ orientation, seriesLineChartState, styles, a
|
|
|
36358
36159
|
const isEmpty = labels.length === 0 || series.length === 0;
|
|
36359
36160
|
const handleRefresh = async () => {
|
|
36360
36161
|
if (query) {
|
|
36361
|
-
await clearChat();
|
|
36162
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36362
36163
|
// Send trigger event to clear chart state
|
|
36363
36164
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36364
36165
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36417,7 +36218,7 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
|
|
|
36417
36218
|
const isEmpty = labels.length === 0 || values.length === 0;
|
|
36418
36219
|
const handleRefresh = async () => {
|
|
36419
36220
|
if (query) {
|
|
36420
|
-
await clearChat();
|
|
36221
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36421
36222
|
// Send trigger event to clear chart state
|
|
36422
36223
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36423
36224
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36461,63 +36262,6 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
|
|
|
36461
36262
|
};
|
|
36462
36263
|
return (jsxRuntimeExports.jsx(PieChart, { title: chartTitle, data: transformedData, units: units }));
|
|
36463
36264
|
}
|
|
36464
|
-
function LineChartComponent({ lineChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36465
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
36466
|
-
const hasCalledRef = React.useRef(false);
|
|
36467
|
-
const labels = ((_b = (_a = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.labels) || ((_e = (_d = (_c = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _c === void 0 ? void 0 : _c.bar_chart_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.labels) || [];
|
|
36468
|
-
const values = ((_g = (_f = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.values) || ((_k = (_j = (_h = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _h === void 0 ? void 0 : _h.bar_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.values) || [];
|
|
36469
|
-
const chartTitle = ((_l = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _l === void 0 ? void 0 : _l.title) || ((_o = (_m = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _m === void 0 ? void 0 : _m.bar_chart_data) === null || _o === void 0 ? void 0 : _o.title) || "";
|
|
36470
|
-
const units = ((_p = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.bar_chart_data) === null || _p === void 0 ? void 0 : _p.units) || ((_r = (_q = lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.state) === null || _q === void 0 ? void 0 : _q.bar_chart_data) === null || _r === void 0 ? void 0 : _r.units) || "";
|
|
36471
|
-
values.length > 0 ? Math.max(...values) : 0;
|
|
36472
|
-
const isEmpty = labels.length === 0 || values.length === 0;
|
|
36473
|
-
const handleRefresh = async () => {
|
|
36474
|
-
if (query && widgetBackendUrl && widgetId) {
|
|
36475
|
-
await clearChat(widgetBackendUrl, widgetId);
|
|
36476
|
-
appendMessage(new TextMessage({
|
|
36477
|
-
content: `${query} and render data on a bar chart`,
|
|
36478
|
-
role: Role.User,
|
|
36479
|
-
}));
|
|
36480
|
-
}
|
|
36481
|
-
};
|
|
36482
|
-
React.useEffect(() => {
|
|
36483
|
-
if (isEmpty && query && isFirstLoad && !(lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.agent_message) && !hasCalledRef.current) {
|
|
36484
|
-
hasCalledRef.current = true;
|
|
36485
|
-
handleRefresh();
|
|
36486
|
-
}
|
|
36487
|
-
}, [isEmpty, query, isFirstLoad, lineChartState]);
|
|
36488
|
-
// Start timeout when chart is empty and loading
|
|
36489
|
-
React.useEffect(() => {
|
|
36490
|
-
if (isEmpty && startLoadingTimeout && !(lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.agent_message)) {
|
|
36491
|
-
startLoadingTimeout();
|
|
36492
|
-
}
|
|
36493
|
-
else if (!isEmpty && clearLoadingTimeout) {
|
|
36494
|
-
clearLoadingTimeout();
|
|
36495
|
-
}
|
|
36496
|
-
}, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
|
|
36497
|
-
const lineColor = React.useMemo(() => {
|
|
36498
|
-
return LINE_COLORS[Math.floor(Math.random() * LINE_COLORS.length)];
|
|
36499
|
-
}, [labels.length]);
|
|
36500
|
-
if (isEmpty) {
|
|
36501
|
-
return createLoadingComponent();
|
|
36502
|
-
}
|
|
36503
|
-
const transformedData = {
|
|
36504
|
-
labels: labels,
|
|
36505
|
-
datasets: [
|
|
36506
|
-
{
|
|
36507
|
-
label: chartTitle || "Data",
|
|
36508
|
-
data: values,
|
|
36509
|
-
borderColor: lineColor,
|
|
36510
|
-
backgroundColor: "rgba(96, 165, 250, 0.1)",
|
|
36511
|
-
borderWidth: 2,
|
|
36512
|
-
pointBackgroundColor: lineColor,
|
|
36513
|
-
pointBorderColor: lineColor,
|
|
36514
|
-
pointRadius: 4,
|
|
36515
|
-
fill: true,
|
|
36516
|
-
},
|
|
36517
|
-
],
|
|
36518
|
-
};
|
|
36519
|
-
return (jsxRuntimeExports.jsx(LineChart, { title: chartTitle, data: transformedData, units: units }));
|
|
36520
|
-
}
|
|
36521
36265
|
function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
|
|
36522
36266
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
36523
36267
|
const hasCalledRef = React.useRef(false);
|
|
@@ -36527,7 +36271,7 @@ function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirs
|
|
|
36527
36271
|
const isEmpty = columns.length === 0 || rows.length === 0;
|
|
36528
36272
|
const handleRefresh = async () => {
|
|
36529
36273
|
if (query) {
|
|
36530
|
-
await clearChat();
|
|
36274
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36531
36275
|
// Send trigger event to clear chart state
|
|
36532
36276
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36533
36277
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36571,7 +36315,7 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
|
|
|
36571
36315
|
const isEmpty = !content || content.trim() === "";
|
|
36572
36316
|
const handleRefresh = async () => {
|
|
36573
36317
|
if (query) {
|
|
36574
|
-
await clearChat();
|
|
36318
|
+
await clearChat(widgetBackendUrl, widgetId);
|
|
36575
36319
|
// Send trigger event to clear chart state
|
|
36576
36320
|
console.log('Dispatching clearChartState event for widgetId:', widgetId);
|
|
36577
36321
|
window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
|
|
@@ -36605,7 +36349,7 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
|
|
|
36605
36349
|
return (jsxRuntimeExports.jsx(SummaryWidget, { title: title, data: data, metadata: metadata, className: "" }));
|
|
36606
36350
|
}
|
|
36607
36351
|
function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds, widgetBackendUrl, datasetId }) {
|
|
36608
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18
|
|
36352
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
|
|
36609
36353
|
const agentType = (_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentType;
|
|
36610
36354
|
const orientation = (_b = widget.config) === null || _b === void 0 ? void 0 : _b.orientation;
|
|
36611
36355
|
const isFirstLoad = (_c = widget.config) === null || _c === void 0 ? void 0 : _c.isFirstLoad;
|
|
@@ -36614,6 +36358,8 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
|
|
|
36614
36358
|
const [isTimeoutTriggered, setIsTimeoutTriggered] = React.useState(false);
|
|
36615
36359
|
const [apiCallCount, setApiCallCount] = React.useState(0);
|
|
36616
36360
|
const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
|
|
36361
|
+
const [isAgentTriggered, setIsAgentTriggered] = React.useState(false);
|
|
36362
|
+
const pollingIntervalRef = React.useRef(null);
|
|
36617
36363
|
React.useEffect(() => {
|
|
36618
36364
|
setThreadId(widget.id);
|
|
36619
36365
|
}, [widget.id, setThreadId]);
|
|
@@ -36660,38 +36406,75 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
|
|
|
36660
36406
|
timeoutRef.current = null;
|
|
36661
36407
|
}
|
|
36662
36408
|
}, []);
|
|
36663
|
-
// Function to
|
|
36664
|
-
React.useCallback(
|
|
36665
|
-
|
|
36409
|
+
// Function to start polling for data availability
|
|
36410
|
+
const startPollingForData = React.useCallback(() => {
|
|
36411
|
+
var _a;
|
|
36412
|
+
if (!widgetBackendUrl || !((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName))
|
|
36666
36413
|
return;
|
|
36667
|
-
|
|
36668
|
-
|
|
36669
|
-
|
|
36670
|
-
|
|
36671
|
-
|
|
36672
|
-
|
|
36673
|
-
|
|
36674
|
-
|
|
36675
|
-
|
|
36676
|
-
|
|
36677
|
-
|
|
36678
|
-
|
|
36679
|
-
|
|
36680
|
-
|
|
36681
|
-
|
|
36682
|
-
|
|
36683
|
-
|
|
36684
|
-
|
|
36685
|
-
|
|
36686
|
-
|
|
36414
|
+
setIsAgentTriggered(true);
|
|
36415
|
+
setApiCallCount(0);
|
|
36416
|
+
setHasTimeoutError(false);
|
|
36417
|
+
// Clear any existing polling interval
|
|
36418
|
+
if (pollingIntervalRef.current) {
|
|
36419
|
+
clearInterval(pollingIntervalRef.current);
|
|
36420
|
+
}
|
|
36421
|
+
// Start polling immediately, then every CHART_REFRESH_TIMEOUT
|
|
36422
|
+
const pollForData = async () => {
|
|
36423
|
+
var _a, _b, _c;
|
|
36424
|
+
if (apiCallCount >= 10) {
|
|
36425
|
+
setHasTimeoutError(true);
|
|
36426
|
+
setIsAgentTriggered(false);
|
|
36427
|
+
if (pollingIntervalRef.current) {
|
|
36428
|
+
clearInterval(pollingIntervalRef.current);
|
|
36429
|
+
pollingIntervalRef.current = null;
|
|
36430
|
+
}
|
|
36431
|
+
return;
|
|
36432
|
+
}
|
|
36433
|
+
setApiCallCount(prev => prev + 1);
|
|
36434
|
+
const agentName = ((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName) || "adk-construction-project-agent";
|
|
36435
|
+
const apiResponse = await loadAgentState(widgetBackendUrl, widget.id, agentName);
|
|
36436
|
+
if (apiResponse && ((_c = (_b = apiResponse.data) === null || _b === void 0 ? void 0 : _b.loadAgentState) === null || _c === void 0 ? void 0 : _c.state)) {
|
|
36437
|
+
parseAndUpdateChartState(apiResponse, setChartState);
|
|
36438
|
+
setIsAgentTriggered(false);
|
|
36439
|
+
if (pollingIntervalRef.current) {
|
|
36440
|
+
clearInterval(pollingIntervalRef.current);
|
|
36441
|
+
pollingIntervalRef.current = null;
|
|
36442
|
+
}
|
|
36443
|
+
}
|
|
36444
|
+
};
|
|
36445
|
+
// Poll immediately
|
|
36446
|
+
pollForData();
|
|
36447
|
+
// Then poll every CHART_REFRESH_TIMEOUT
|
|
36448
|
+
pollingIntervalRef.current = setInterval(pollForData, CHART_REFRESH_TIMEOUT);
|
|
36449
|
+
// Set a maximum timeout to stop polling after 10 attempts
|
|
36450
|
+
setTimeout(() => {
|
|
36451
|
+
if (pollingIntervalRef.current) {
|
|
36452
|
+
clearInterval(pollingIntervalRef.current);
|
|
36453
|
+
pollingIntervalRef.current = null;
|
|
36454
|
+
setIsAgentTriggered(false);
|
|
36455
|
+
if (apiCallCount >= 10) {
|
|
36456
|
+
setHasTimeoutError(true);
|
|
36457
|
+
}
|
|
36458
|
+
}
|
|
36459
|
+
}, CHART_REFRESH_TIMEOUT * 10);
|
|
36460
|
+
}, [widgetBackendUrl, (_f = widget.config) === null || _f === void 0 ? void 0 : _f.agentName, widget.id, apiCallCount, setChartState]);
|
|
36461
|
+
// Clean up timeout and polling on unmount
|
|
36687
36462
|
React.useEffect(() => {
|
|
36688
36463
|
return () => {
|
|
36689
36464
|
if (timeoutRef.current) {
|
|
36690
36465
|
clearTimeout(timeoutRef.current);
|
|
36691
36466
|
}
|
|
36467
|
+
if (pollingIntervalRef.current) {
|
|
36468
|
+
clearInterval(pollingIntervalRef.current);
|
|
36469
|
+
}
|
|
36692
36470
|
};
|
|
36693
36471
|
}, []);
|
|
36694
|
-
const { appendMessage, reset } = reactCore.useCopilotChat();
|
|
36472
|
+
const { appendMessage: originalAppendMessage, reset } = reactCore.useCopilotChat();
|
|
36473
|
+
// Wrapper function for appendMessage that triggers polling
|
|
36474
|
+
const appendMessage = React.useCallback((message) => {
|
|
36475
|
+
startPollingForData();
|
|
36476
|
+
return originalAppendMessage(message);
|
|
36477
|
+
}, [originalAppendMessage, startPollingForData]);
|
|
36695
36478
|
// Register the reset function with the parent component
|
|
36696
36479
|
React.useEffect(() => {
|
|
36697
36480
|
if (onResetReady && reset && widget.id) {
|
|
@@ -36753,17 +36536,16 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
|
|
|
36753
36536
|
}, [widget.id, appendMessage, agentType, setChartState]);
|
|
36754
36537
|
return (jsxRuntimeExports.jsxs("div", { className: cn("flex flex-col h-full"), children: [showHeader && (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-between pb-2 border-b", children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.Bot, { className: "h-4 w-4" }), jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })] }) })), jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState === null || chartState === void 0 ? void 0 : chartState.agent_message) && agentType !== "chatbot" && (
|
|
36755
36538
|
// Check if data is empty based on agent type
|
|
36756
|
-
(agentType === "Bar Chart Agent" && (!((
|
|
36757
|
-
(agentType === "Series
|
|
36758
|
-
(agentType === "
|
|
36759
|
-
(agentType === "
|
|
36760
|
-
(agentType === "
|
|
36761
|
-
|
|
36762
|
-
|
|
36763
|
-
title: ((_29 = widget.config) === null || _29 === void 0 ? void 0 : _29.copilotTitle) || widget.title,
|
|
36764
|
-
initial: ((_30 = widget.config) === null || _30 === void 0 ? void 0 : _30.copilotInitialMessage) || ((_31 = widget.config) === null || _31 === void 0 ? void 0 : _31.placeholder) || "How can I help you today?"
|
|
36539
|
+
(agentType === "Series Bar Chart Agent" && (!((_j = (_h = (_g = chartState.series_bar_chart_data) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.labels) === null || _j === void 0 ? void 0 : _j.length) || !((_m = (_l = (_k = chartState.series_bar_chart_data) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.series) === null || _m === void 0 ? void 0 : _m.length))) ||
|
|
36540
|
+
(agentType === "Series Line Chart Agent" && (!((_q = (_p = (_o = chartState.series_bar_chart_data) === null || _o === void 0 ? void 0 : _o.data) === null || _p === void 0 ? void 0 : _p.labels) === null || _q === void 0 ? void 0 : _q.length) || !((_t = (_s = (_r = chartState.series_bar_chart_data) === null || _r === void 0 ? void 0 : _r.data) === null || _s === void 0 ? void 0 : _s.series) === null || _t === void 0 ? void 0 : _t.length))) ||
|
|
36541
|
+
(agentType === "Pie Chart Agent" && (!((_w = (_v = (_u = chartState.pie_chart_data) === null || _u === void 0 ? void 0 : _u.data) === null || _v === void 0 ? void 0 : _v.labels) === null || _w === void 0 ? void 0 : _w.length) || !((_z = (_y = (_x = chartState.pie_chart_data) === null || _x === void 0 ? void 0 : _x.data) === null || _y === void 0 ? void 0 : _y.values) === null || _z === void 0 ? void 0 : _z.length))) ||
|
|
36542
|
+
(agentType === "Data Grid Agent" && (!((_2 = (_1 = (_0 = chartState.matrix_grid_data) === null || _0 === void 0 ? void 0 : _0.data) === null || _1 === void 0 ? void 0 : _1.headers) === null || _2 === void 0 ? void 0 : _2.length) || !((_5 = (_4 = (_3 = chartState.matrix_grid_data) === null || _3 === void 0 ? void 0 : _3.data) === null || _4 === void 0 ? void 0 : _4.rows) === null || _5 === void 0 ? void 0 : _5.length))) ||
|
|
36543
|
+
(agentType === "Summary Agent" && (!((_7 = (_6 = chartState.summary_data) === null || _6 === void 0 ? void 0 : _6.data) === null || _7 === void 0 ? void 0 : _7.content) || ((_10 = (_9 = (_8 = chartState.summary_data) === null || _8 === void 0 ? void 0 : _8.data) === null || _9 === void 0 ? void 0 : _9.content) === null || _10 === void 0 ? void 0 : _10.trim()) === ""))) ? (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) })) : isAgentTriggered ? (createLoadingComponent("Agent processing your request...")) : agentType === "Series Bar Chart Agent" ? (jsxRuntimeExports.jsx(SeriesBarChartComponent, { seriesBarChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_11 = widget.config) === null || _11 === void 0 ? void 0 : _11.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Series Line Chart Agent" ? (jsxRuntimeExports.jsx(SeriesLineChartComponent, { seriesLineChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_12 = widget.config) === null || _12 === void 0 ? void 0 : _12.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Pie Chart Agent" ? (jsxRuntimeExports.jsx(PieChartComponent, { pieChartState: chartState, styles: styles, appendMessage: appendMessage, query: (_13 = widget.config) === null || _13 === void 0 ? void 0 : _13.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Data Grid Agent" ? (jsxRuntimeExports.jsx(DataGridComponent, { dataGridState: chartState, styles: styles, appendMessage: appendMessage, query: (_14 = widget.config) === null || _14 === void 0 ? void 0 : _14.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Summary Agent" ? (jsxRuntimeExports.jsx(SummaryComponent, { summaryState: chartState, styles: styles, appendMessage: appendMessage, query: (_15 = widget.config) === null || _15 === void 0 ? void 0 : _15.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, widget_ids: widgetIds, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout, setChartState: setChartState })) : (jsxRuntimeExports.jsx(reactUi.CopilotChat, { className: "h-full text-xs [&_.copilot-chat-message]:text-xs [&_.copilot-chat-input]:text-xs", labels: {
|
|
36544
|
+
title: ((_16 = widget.config) === null || _16 === void 0 ? void 0 : _16.copilotTitle) || widget.title,
|
|
36545
|
+
initial: ((_17 = widget.config) === null || _17 === void 0 ? void 0 : _17.copilotInitialMessage) || ((_18 = widget.config) === null || _18 === void 0 ? void 0 : _18.placeholder) || "How can I help you today?"
|
|
36765
36546
|
}, onSubmitMessage: () => {
|
|
36766
36547
|
setChartState(prevState => (Object.assign(Object.assign({}, prevState), { widget_ids: widgetIds, dataset_id: datasetId })));
|
|
36548
|
+
startPollingForData();
|
|
36767
36549
|
} })) })] }));
|
|
36768
36550
|
}
|
|
36769
36551
|
function AgentWidget({ widget, showHeader = true, widgetBackendUrl, onResetReady, widgetIds, datasetId, }) {
|