dp-widgets-framework 1.0.5 → 1.0.7

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.
Files changed (3) hide show
  1. package/dist/index.esm.js +166 -644
  2. package/dist/index.js +166 -644
  3. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -15083,7 +15083,14 @@ function BarChart({ orientation, title, data, options, className }) {
15083
15083
  },
15084
15084
  scales: {
15085
15085
  x: {
15086
- ticks: { autoSkip: true, maxTicksLimit: 8, maxRotation: 45, minRotation: 0 },
15086
+ ticks: {
15087
+ autoSkip: false,
15088
+ maxRotation: 45,
15089
+ minRotation: 45,
15090
+ font: {
15091
+ size: 10
15092
+ }
15093
+ },
15087
15094
  },
15088
15095
  y: { beginAtZero: true },
15089
15096
  },
@@ -35932,7 +35939,87 @@ function SummaryWidget({ title, data, metadata, className }) {
35932
35939
  }, children: title }) })), jsxRuntimeExports.jsx("div", { className: "flex-1 overflow-auto space-y-4", children: jsxRuntimeExports.jsx("div", { className: "prose prose-sm max-w-none", children: jsxRuntimeExports.jsx(Markdown, { className: "text-gray-800 dark:text-gray-200", children: data.content }) }) })] }));
35933
35940
  }
35934
35941
 
35935
- const CHART_REFRESH_TIMEOUT = 5000;
35942
+ const CHART_REFRESH_TIMEOUT = 3000;
35943
+ const DEFAULT_COLORS = ["#E4DCB8", "#DAC46C", "#808080", "#582809", "#A3ADD0", "#398E6F", "#AF123D", "#8C99C4", "#5290AC", "#601B07", "#50649D", "#B4A8A0", "#6F2587"];
35944
+ const LINE_COLORS = ["#243D84", "#69238B", "#4A959F", "#D0A677", "#B31E47", "#396431"];
35945
+ const clearChat = async (widgetBackendUrl, widgetId) => {
35946
+ if (!widgetBackendUrl || !widgetId)
35947
+ return;
35948
+ console.log('clearChat called for widgetId:', widgetId);
35949
+ try {
35950
+ await fetch(`${widgetBackendUrl}/api/clear-chat`, {
35951
+ method: 'POST',
35952
+ headers: {
35953
+ 'Content-Type': 'application/json',
35954
+ },
35955
+ body: JSON.stringify({
35956
+ session_id: widgetId,
35957
+ delete_state: true
35958
+ }),
35959
+ });
35960
+ console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
35961
+ window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
35962
+ }
35963
+ catch (error) {
35964
+ console.error('Failed to clear chat:', error);
35965
+ }
35966
+ };
35967
+ const createLoadingComponent = (message = "Loading chart data...") => (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: message })] }) }));
35968
+ const createInitialChartState = (agentType, widgetIds, datasetId) => {
35969
+ const baseState = { dataset_id: datasetId || "home_generation_dataset" };
35970
+ switch (agentType) {
35971
+ case "Pie Chart Agent":
35972
+ return {
35973
+ pie_chart_data: {
35974
+ title: "",
35975
+ type: "pie",
35976
+ chart_type: "financial",
35977
+ data: { labels: [], values: [], percentages: [], total: 0 },
35978
+ metadata: { categories: 0, largest_category: "", largest_value: 0, largest_percentage: 0 }
35979
+ }
35980
+ };
35981
+ case "Line Chart Agent":
35982
+ case "Bar Chart Agent":
35983
+ return Object.assign({ bar_chart_data: {
35984
+ title: "",
35985
+ type: agentType === "Line Chart Agent" ? "line" : "bar",
35986
+ chart_type: "financial",
35987
+ orientation: agentType === "Line Chart Agent" ? "horizontal" : "vertical",
35988
+ data: { labels: [], values: [], total: 0, average: 0 },
35989
+ metadata: { categories: 0, highest_category: "", highest_value: 0, lowest_category: "", lowest_value: 0, range: 0 }
35990
+ } }, baseState);
35991
+ case "Series Bar Chart Agent":
35992
+ case "Series Line Chart Agent":
35993
+ return Object.assign({ series_bar_chart_data: {
35994
+ title: "",
35995
+ type: "series_bar",
35996
+ chart_type: "financial",
35997
+ orientation: "vertical",
35998
+ data: { labels: [], series: [], total: 0, average: 0 },
35999
+ metadata: {
36000
+ categories: 0, series_count: 0, highest_category: "", highest_value: 0, highest_series: "",
36001
+ lowest_category: "", lowest_value: 0, lowest_series: "", range: 0, series_totals: {}, series_averages: {}
36002
+ }
36003
+ } }, baseState);
36004
+ case "Data Grid Agent":
36005
+ return Object.assign({ matrix_grid_data: {
36006
+ title: "",
36007
+ type: "data_grid",
36008
+ grid_type: "",
36009
+ data: { headers: [], rows: [], row_count: 0, column_count: 0 },
36010
+ metadata: { total_rows: 0, total_columns: 0, numeric_columns: [] }
36011
+ } }, baseState);
36012
+ case "Summary Agent":
36013
+ return Object.assign({ summary_data: {
36014
+ title: "",
36015
+ type: "summary",
36016
+ data: { content: "", word_count: 0, character_count: 0, character_count_no_spaces: 0, line_count: 0 },
36017
+ metadata: { created_at: "", content_type: "text", is_multiline: false }
36018
+ } }, baseState);
36019
+ default:
36020
+ return { widget_ids: widgetIds };
36021
+ }
36022
+ };
35936
36023
  const loadAgentState = async (widgetBackendUrl, threadId, agentName) => {
35937
36024
  try {
35938
36025
  const response = await fetch(`${widgetBackendUrl}/api/copilot/${agentName}`, {
@@ -35996,7 +36083,6 @@ const parseAndUpdateChartState = (apiResponse, setChartState) => {
35996
36083
  if (chartData.agent_message) {
35997
36084
  newChartState.agent_message = chartData.agent_message;
35998
36085
  }
35999
- console.log('Chart state updated from API response:', newChartState);
36000
36086
  return newChartState;
36001
36087
  });
36002
36088
  }
@@ -36031,40 +36117,15 @@ const getStyleValues = (styles = {}) => {
36031
36117
  };
36032
36118
  function BarChartComponent({ orientation, barChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
36033
36119
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36120
+ const hasCalledRef = useRef(false);
36034
36121
  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) || [];
36035
36122
  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) || [];
36036
36123
  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) || "";
36037
36124
  values.length > 0 ? Math.max(...values) : 0;
36038
36125
  const isEmpty = labels.length === 0 || values.length === 0;
36039
- const clearChat = async () => {
36040
- if (!widgetBackendUrl || !widgetId)
36041
- return;
36042
- console.log('clearChat called for widgetId:', widgetId);
36043
- try {
36044
- await fetch(`${widgetBackendUrl}/api/clear-chat`, {
36045
- method: 'POST',
36046
- headers: {
36047
- 'Content-Type': 'application/json',
36048
- },
36049
- body: JSON.stringify({
36050
- session_id: widgetId,
36051
- delete_state: true
36052
- }),
36053
- });
36054
- // Clear chart state directly after clearing chat
36055
- console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
36056
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36057
- }
36058
- catch (error) {
36059
- console.error('Failed to clear chat:', error);
36060
- }
36061
- };
36062
36126
  const handleRefresh = async () => {
36063
- if (query) {
36064
- await clearChat();
36065
- // Send trigger event to clear chart state
36066
- console.log('Dispatching clearChartState event for widgetId:', widgetId);
36067
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36127
+ if (query && widgetBackendUrl && widgetId) {
36128
+ await clearChat(widgetBackendUrl, widgetId);
36068
36129
  appendMessage(new TextMessage({
36069
36130
  content: `${query} and render data on a bar chart`,
36070
36131
  role: Role.User,
@@ -36072,10 +36133,12 @@ function BarChartComponent({ orientation, barChartState, styles, appendMessage,
36072
36133
  }
36073
36134
  };
36074
36135
  useEffect(() => {
36075
- if (isEmpty && query && isFirstLoad && !(barChartState === null || barChartState === void 0 ? void 0 : barChartState.agent_message)) {
36136
+ if (isEmpty && query && isFirstLoad && !(barChartState === null || barChartState === void 0 ? void 0 : barChartState.agent_message) && !hasCalledRef.current) {
36137
+ // console.log('calling append message')
36138
+ hasCalledRef.current = true;
36076
36139
  handleRefresh();
36077
36140
  }
36078
- }, [isEmpty, query, isFirstLoad]);
36141
+ }, [isEmpty, query, isFirstLoad, barChartState]);
36079
36142
  // Start timeout when chart is empty and loading
36080
36143
  useEffect(() => {
36081
36144
  if (isEmpty && startLoadingTimeout && !(barChartState === null || barChartState === void 0 ? void 0 : barChartState.agent_message)) {
@@ -36085,12 +36148,11 @@ function BarChartComponent({ orientation, barChartState, styles, appendMessage,
36085
36148
  clearLoadingTimeout();
36086
36149
  }
36087
36150
  }, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
36088
- const colors = ["#E4DCB8", "#DAC46C", "#808080", "#582809", "#A3ADD0", "#398E6F", "#AF123D", "#8C99C4", "#5290AC", "#8C99C4", "#601B07", "#50649D", "#B4A8A0", "#808080", "#6F2587"];
36089
36151
  const finalColors = useMemo(() => {
36090
- return shuffleColors(colors, labels === null || labels === void 0 ? void 0 : labels.length);
36152
+ return shuffleColors(DEFAULT_COLORS, labels === null || labels === void 0 ? void 0 : labels.length);
36091
36153
  }, [labels.length]);
36092
36154
  if (isEmpty) {
36093
- return (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: "Loading chart data..." })] }) }));
36155
+ return createLoadingComponent();
36094
36156
  }
36095
36157
  const transformedData = {
36096
36158
  labels: labels,
@@ -36099,10 +36161,6 @@ function BarChartComponent({ orientation, barChartState, styles, appendMessage,
36099
36161
  label: chartTitle || "Data",
36100
36162
  data: values,
36101
36163
  backgroundColor: finalColors,
36102
- // backgroundColor: labels.map((_, index) => {
36103
- // const colors = ["#60a5fa", "#34d399", "#fbbf24", "#f87171", "#a78bfa", "#fb7185", "#4ade80", "#facc15"];
36104
- // return colors[index % colors.length];
36105
- // }),
36106
36164
  },
36107
36165
  ],
36108
36166
  };
@@ -36110,33 +36168,11 @@ function BarChartComponent({ orientation, barChartState, styles, appendMessage,
36110
36168
  }
36111
36169
  function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
36112
36170
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36171
+ const hasCalledRef = useRef(false);
36113
36172
  const labels = ((_b = (_a = seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.series_bar_chart_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.labels) || ((_e = (_d = (_c = seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.state) === null || _c === void 0 ? void 0 : _c.series_bar_chart_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.labels) || [];
36114
36173
  const series = ((_g = (_f = seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.series_bar_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.series) || ((_k = (_j = (_h = seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.state) === null || _h === void 0 ? void 0 : _h.series_bar_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.series) || [];
36115
36174
  const chartTitle = ((_l = seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.series_bar_chart_data) === null || _l === void 0 ? void 0 : _l.title) || ((_o = (_m = seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.state) === null || _m === void 0 ? void 0 : _m.series_bar_chart_data) === null || _o === void 0 ? void 0 : _o.title) || "";
36116
36175
  const isEmpty = labels.length === 0 || series.length === 0;
36117
- const clearChat = async () => {
36118
- if (!widgetBackendUrl || !widgetId)
36119
- return;
36120
- console.log('clearChat called for widgetId:', widgetId);
36121
- try {
36122
- await fetch(`${widgetBackendUrl}/api/clear-chat`, {
36123
- method: 'POST',
36124
- headers: {
36125
- 'Content-Type': 'application/json',
36126
- },
36127
- body: JSON.stringify({
36128
- session_id: widgetId,
36129
- delete_state: true
36130
- }),
36131
- });
36132
- // Clear chart state directly after clearing chat
36133
- console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
36134
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36135
- }
36136
- catch (error) {
36137
- console.error('Failed to clear chat:', error);
36138
- }
36139
- };
36140
36176
  const handleRefresh = async () => {
36141
36177
  if (query) {
36142
36178
  await clearChat();
@@ -36150,10 +36186,11 @@ function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, app
36150
36186
  }
36151
36187
  };
36152
36188
  useEffect(() => {
36153
- if (isEmpty && query && isFirstLoad && !(seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.agent_message)) {
36189
+ if (isEmpty && query && isFirstLoad && !(seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.agent_message) && !hasCalledRef.current) {
36190
+ hasCalledRef.current = true;
36154
36191
  handleRefresh();
36155
36192
  }
36156
- }, [isEmpty, query, isFirstLoad]);
36193
+ }, [isEmpty, query, isFirstLoad, seriesBarChartState]);
36157
36194
  // Start timeout when chart is empty and loading
36158
36195
  useEffect(() => {
36159
36196
  if (isEmpty && startLoadingTimeout && !(seriesBarChartState === null || seriesBarChartState === void 0 ? void 0 : seriesBarChartState.agent_message)) {
@@ -36163,12 +36200,11 @@ function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, app
36163
36200
  clearLoadingTimeout();
36164
36201
  }
36165
36202
  }, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
36166
- const colors = ["#E4DCB8", "#DAC46C", "#808080", "#582809", "#A3ADD0", "#398E6F", "#AF123D", "#8C99C4", "#5290AC", "#8C99C4", "#601B07", "#50649D", "#B4A8A0", "#808080", "#6F2587"];
36167
36203
  const finalColors = useMemo(() => {
36168
- return shuffleColors(colors, series === null || series === void 0 ? void 0 : series.length);
36204
+ return shuffleColors(DEFAULT_COLORS, series === null || series === void 0 ? void 0 : series.length);
36169
36205
  }, [series.length]);
36170
36206
  if (isEmpty) {
36171
- return (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: "Loading chart data..." })] }) }));
36207
+ return createLoadingComponent();
36172
36208
  }
36173
36209
  const transformedData = {
36174
36210
  labels: labels,
@@ -36182,33 +36218,11 @@ function SeriesBarChartComponent({ orientation, seriesBarChartState, styles, app
36182
36218
  }
36183
36219
  function SeriesLineChartComponent({ orientation, seriesLineChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
36184
36220
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36221
+ const hasCalledRef = useRef(false);
36185
36222
  const labels = ((_b = (_a = seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.series_bar_chart_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.labels) || ((_e = (_d = (_c = seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.state) === null || _c === void 0 ? void 0 : _c.series_bar_chart_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.labels) || [];
36186
36223
  const series = ((_g = (_f = seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.series_bar_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.series) || ((_k = (_j = (_h = seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.state) === null || _h === void 0 ? void 0 : _h.series_bar_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.series) || [];
36187
36224
  const chartTitle = ((_l = seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.series_bar_chart_data) === null || _l === void 0 ? void 0 : _l.title) || ((_o = (_m = seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.state) === null || _m === void 0 ? void 0 : _m.series_bar_chart_data) === null || _o === void 0 ? void 0 : _o.title) || "";
36188
36225
  const isEmpty = labels.length === 0 || series.length === 0;
36189
- const clearChat = async () => {
36190
- if (!widgetBackendUrl || !widgetId)
36191
- return;
36192
- console.log('clearChat called for widgetId:', widgetId);
36193
- try {
36194
- await fetch(`${widgetBackendUrl}/api/clear-chat`, {
36195
- method: 'POST',
36196
- headers: {
36197
- 'Content-Type': 'application/json',
36198
- },
36199
- body: JSON.stringify({
36200
- session_id: widgetId,
36201
- delete_state: true
36202
- }),
36203
- });
36204
- // Clear chart state directly after clearing chat
36205
- console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
36206
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36207
- }
36208
- catch (error) {
36209
- console.error('Failed to clear chat:', error);
36210
- }
36211
- };
36212
36226
  const handleRefresh = async () => {
36213
36227
  if (query) {
36214
36228
  await clearChat();
@@ -36222,10 +36236,11 @@ function SeriesLineChartComponent({ orientation, seriesLineChartState, styles, a
36222
36236
  }
36223
36237
  };
36224
36238
  useEffect(() => {
36225
- if (isEmpty && query && isFirstLoad && !(seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.agent_message)) {
36239
+ if (isEmpty && query && isFirstLoad && !(seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.agent_message) && !hasCalledRef.current) {
36240
+ hasCalledRef.current = true;
36226
36241
  handleRefresh();
36227
36242
  }
36228
- }, [isEmpty, query, isFirstLoad]);
36243
+ }, [isEmpty, query, isFirstLoad, seriesLineChartState]);
36229
36244
  // Start timeout when chart is empty and loading
36230
36245
  useEffect(() => {
36231
36246
  if (isEmpty && startLoadingTimeout && !(seriesLineChartState === null || seriesLineChartState === void 0 ? void 0 : seriesLineChartState.agent_message)) {
@@ -36235,12 +36250,11 @@ function SeriesLineChartComponent({ orientation, seriesLineChartState, styles, a
36235
36250
  clearLoadingTimeout();
36236
36251
  }
36237
36252
  }, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
36238
- const colors = ["#243D84", "#69238B", "#4A959F", "#D0A677", "#B31E47", "#396431", "#E4DCB8", "#DAC46C", "#808080", "#582809", "#A3ADD0", "#398E6F", "#AF123D", "#8C99C4", "#5290AC"];
36239
36253
  const finalColors = useMemo(() => {
36240
- return shuffleColors(colors, series === null || series === void 0 ? void 0 : series.length);
36254
+ return shuffleColors([...LINE_COLORS, ...DEFAULT_COLORS], series === null || series === void 0 ? void 0 : series.length);
36241
36255
  }, [series.length]);
36242
36256
  if (isEmpty) {
36243
- return (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: "Loading chart data..." })] }) }));
36257
+ return createLoadingComponent();
36244
36258
  }
36245
36259
  const transformedData = {
36246
36260
  labels: labels,
@@ -36261,34 +36275,12 @@ function SeriesLineChartComponent({ orientation, seriesLineChartState, styles, a
36261
36275
  }
36262
36276
  function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
36263
36277
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
36278
+ const hasCalledRef = useRef(false);
36264
36279
  const labels = ((_b = (_a = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.pie_chart_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.labels) || ((_e = (_d = (_c = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.state) === null || _c === void 0 ? void 0 : _c.pie_chart_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.labels) || [];
36265
36280
  const values = ((_g = (_f = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.pie_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.values) || ((_k = (_j = (_h = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.state) === null || _h === void 0 ? void 0 : _h.pie_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.values) || [];
36266
36281
  ((_m = (_l = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.pie_chart_data) === null || _l === void 0 ? void 0 : _l.data) === null || _m === void 0 ? void 0 : _m.percentages) || ((_q = (_p = (_o = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.state) === null || _o === void 0 ? void 0 : _o.pie_chart_data) === null || _p === void 0 ? void 0 : _p.data) === null || _q === void 0 ? void 0 : _q.percentages) || [];
36267
36282
  const chartTitle = ((_r = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.pie_chart_data) === null || _r === void 0 ? void 0 : _r.title) || ((_t = (_s = pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.state) === null || _s === void 0 ? void 0 : _s.pie_chart_data) === null || _t === void 0 ? void 0 : _t.title) || "";
36268
36283
  const isEmpty = labels.length === 0 || values.length === 0;
36269
- const clearChat = async () => {
36270
- if (!widgetBackendUrl || !widgetId)
36271
- return;
36272
- console.log('clearChat called for widgetId:', widgetId);
36273
- try {
36274
- await fetch(`${widgetBackendUrl}/api/clear-chat`, {
36275
- method: 'POST',
36276
- headers: {
36277
- 'Content-Type': 'application/json',
36278
- },
36279
- body: JSON.stringify({
36280
- session_id: widgetId,
36281
- delete_state: true
36282
- }),
36283
- });
36284
- // Clear chart state directly after clearing chat
36285
- console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
36286
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36287
- }
36288
- catch (error) {
36289
- console.error('Failed to clear chat:', error);
36290
- }
36291
- };
36292
36284
  const handleRefresh = async () => {
36293
36285
  if (query) {
36294
36286
  await clearChat();
@@ -36302,10 +36294,11 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
36302
36294
  }
36303
36295
  };
36304
36296
  useEffect(() => {
36305
- if (isEmpty && query && isFirstLoad && !(pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.agent_message)) {
36297
+ if (isEmpty && query && isFirstLoad && !(pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.agent_message) && !hasCalledRef.current) {
36298
+ hasCalledRef.current = true;
36306
36299
  handleRefresh();
36307
36300
  }
36308
- }, [isEmpty, query, isFirstLoad]);
36301
+ }, [isEmpty, query, isFirstLoad, pieChartState]);
36309
36302
  // Start timeout when chart is empty and loading
36310
36303
  useEffect(() => {
36311
36304
  if (isEmpty && startLoadingTimeout && !(pieChartState === null || pieChartState === void 0 ? void 0 : pieChartState.agent_message)) {
@@ -36315,23 +36308,12 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
36315
36308
  clearLoadingTimeout();
36316
36309
  }
36317
36310
  }, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
36318
- const palette = ["#E4DCB8", "#DAC46C", "#808080", "#A3ADD0", "#398E6F", "#AF123D", "#8C99C4", "#5290AC", "#601B07", "#50649D", "#B4A8A0", "#808080", "#6F2587"];
36319
36311
  const backgroundColors = useMemo(() => {
36320
- return shuffleColorsWithPriority(palette, labels.length, ["#7B0D3F"]);
36312
+ return shuffleColorsWithPriority(DEFAULT_COLORS, labels.length, ["#7B0D3F"]);
36321
36313
  }, [labels.length]);
36322
36314
  if (isEmpty) {
36323
- return (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: "Loading chart data..." })] }) }));
36324
- }
36325
- // const borderColors = [
36326
- // "rgba(255, 99, 132, 1)",
36327
- // "rgba(54, 162, 235, 1)",
36328
- // "rgba(255, 206, 86, 1)",
36329
- // "rgba(75, 192, 192, 1)",
36330
- // "rgba(153, 102, 255, 1)",
36331
- // "rgba(255, 159, 64, 1)",
36332
- // "rgba(199, 199, 199, 1)",
36333
- // "rgba(83, 102, 255, 1)",
36334
- // ];
36315
+ return createLoadingComponent();
36316
+ }
36335
36317
  const transformedData = {
36336
36318
  labels: labels,
36337
36319
  datasets: [
@@ -36339,7 +36321,6 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
36339
36321
  label: chartTitle || "Data",
36340
36322
  data: values,
36341
36323
  backgroundColor: labels.map((_, index) => backgroundColors[index % backgroundColors.length]),
36342
- // borderColor: labels.map((_, index) => borderColors[index % borderColors.length]),
36343
36324
  borderWidth: 0,
36344
36325
  },
36345
36326
  ],
@@ -36348,40 +36329,15 @@ function PieChartComponent({ pieChartState, styles, appendMessage, query, isFirs
36348
36329
  }
36349
36330
  function LineChartComponent({ lineChartState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
36350
36331
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36332
+ const hasCalledRef = useRef(false);
36351
36333
  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) || [];
36352
36334
  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) || [];
36353
36335
  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) || "";
36354
36336
  values.length > 0 ? Math.max(...values) : 0;
36355
36337
  const isEmpty = labels.length === 0 || values.length === 0;
36356
- const clearChat = async () => {
36357
- if (!widgetBackendUrl || !widgetId)
36358
- return;
36359
- console.log('clearChat called for widgetId:', widgetId);
36360
- try {
36361
- await fetch(`${widgetBackendUrl}/api/clear-chat`, {
36362
- method: 'POST',
36363
- headers: {
36364
- 'Content-Type': 'application/json',
36365
- },
36366
- body: JSON.stringify({
36367
- session_id: widgetId,
36368
- delete_state: true
36369
- }),
36370
- });
36371
- // Clear chart state directly after clearing chat
36372
- console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
36373
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36374
- }
36375
- catch (error) {
36376
- console.error('Failed to clear chat:', error);
36377
- }
36378
- };
36379
36338
  const handleRefresh = async () => {
36380
- if (query) {
36381
- await clearChat();
36382
- // Send trigger event to clear chart state
36383
- console.log('Dispatching clearChartState event for widgetId:', widgetId);
36384
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36339
+ if (query && widgetBackendUrl && widgetId) {
36340
+ await clearChat(widgetBackendUrl, widgetId);
36385
36341
  appendMessage(new TextMessage({
36386
36342
  content: `${query} and render data on a bar chart`,
36387
36343
  role: Role.User,
@@ -36389,10 +36345,11 @@ function LineChartComponent({ lineChartState, styles, appendMessage, query, isFi
36389
36345
  }
36390
36346
  };
36391
36347
  useEffect(() => {
36392
- if (isEmpty && query && isFirstLoad && !(lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.agent_message)) {
36348
+ if (isEmpty && query && isFirstLoad && !(lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.agent_message) && !hasCalledRef.current) {
36349
+ hasCalledRef.current = true;
36393
36350
  handleRefresh();
36394
36351
  }
36395
- }, [isEmpty, query, isFirstLoad]);
36352
+ }, [isEmpty, query, isFirstLoad, lineChartState]);
36396
36353
  // Start timeout when chart is empty and loading
36397
36354
  useEffect(() => {
36398
36355
  if (isEmpty && startLoadingTimeout && !(lineChartState === null || lineChartState === void 0 ? void 0 : lineChartState.agent_message)) {
@@ -36402,19 +36359,11 @@ function LineChartComponent({ lineChartState, styles, appendMessage, query, isFi
36402
36359
  clearLoadingTimeout();
36403
36360
  }
36404
36361
  }, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
36405
- const colors = [
36406
- "#243D84",
36407
- "#69238B",
36408
- "#4A959F",
36409
- "#D0A677",
36410
- "#B31E47",
36411
- "#396431",
36412
- ];
36413
36362
  const lineColor = useMemo(() => {
36414
- return colors[Math.floor(Math.random() * colors.length)];
36363
+ return LINE_COLORS[Math.floor(Math.random() * LINE_COLORS.length)];
36415
36364
  }, [labels.length]);
36416
36365
  if (isEmpty) {
36417
- return (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: "Loading chart data..." })] }) }));
36366
+ return createLoadingComponent();
36418
36367
  }
36419
36368
  const transformedData = {
36420
36369
  labels: labels,
@@ -36436,33 +36385,11 @@ function LineChartComponent({ lineChartState, styles, appendMessage, query, isFi
36436
36385
  }
36437
36386
  function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout }) {
36438
36387
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
36388
+ const hasCalledRef = useRef(false);
36439
36389
  const columns = ((_b = (_a = dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.matrix_grid_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.headers) || ((_e = (_d = (_c = dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.state) === null || _c === void 0 ? void 0 : _c.matrix_grid_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.headers) || [];
36440
36390
  const rows = ((_g = (_f = dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.matrix_grid_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.rows) || ((_k = (_j = (_h = dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.state) === null || _h === void 0 ? void 0 : _h.matrix_grid_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.rows) || [];
36441
36391
  const gridTitle = ((_l = dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.matrix_grid_data) === null || _l === void 0 ? void 0 : _l.title) || ((_o = (_m = dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.state) === null || _m === void 0 ? void 0 : _m.matrix_grid_data) === null || _o === void 0 ? void 0 : _o.title) || "";
36442
36392
  const isEmpty = columns.length === 0 || rows.length === 0;
36443
- const clearChat = async () => {
36444
- if (!widgetBackendUrl || !widgetId)
36445
- return;
36446
- console.log('clearChat called for widgetId:', widgetId);
36447
- try {
36448
- await fetch(`${widgetBackendUrl}/api/clear-chat`, {
36449
- method: 'POST',
36450
- headers: {
36451
- 'Content-Type': 'application/json',
36452
- },
36453
- body: JSON.stringify({
36454
- session_id: widgetId,
36455
- delete_state: true
36456
- }),
36457
- });
36458
- // Clear chart state directly after clearing chat
36459
- console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
36460
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36461
- }
36462
- catch (error) {
36463
- console.error('Failed to clear chat:', error);
36464
- }
36465
- };
36466
36393
  const handleRefresh = async () => {
36467
36394
  if (query) {
36468
36395
  await clearChat();
@@ -36476,10 +36403,11 @@ function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirs
36476
36403
  }
36477
36404
  };
36478
36405
  useEffect(() => {
36479
- if (isEmpty && query && isFirstLoad && !(dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.agent_message)) {
36406
+ if (isEmpty && query && isFirstLoad && !(dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.agent_message) && !hasCalledRef.current) {
36407
+ hasCalledRef.current = true;
36480
36408
  handleRefresh();
36481
36409
  }
36482
- }, [isEmpty, query, isFirstLoad]);
36410
+ }, [isEmpty, query, isFirstLoad, dataGridState]);
36483
36411
  // Start timeout when chart is empty and loading
36484
36412
  useEffect(() => {
36485
36413
  if (isEmpty && startLoadingTimeout && !(dataGridState === null || dataGridState === void 0 ? void 0 : dataGridState.agent_message)) {
@@ -36490,7 +36418,7 @@ function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirs
36490
36418
  }
36491
36419
  }, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
36492
36420
  if (isEmpty) {
36493
- return (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: "Loading table data..." })] }) }));
36421
+ return createLoadingComponent("Loading table data...");
36494
36422
  }
36495
36423
  const transformedData = {
36496
36424
  columns: columns,
@@ -36500,34 +36428,12 @@ function DataGridComponent({ dataGridState, styles, appendMessage, query, isFirs
36500
36428
  }
36501
36429
  function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout, setChartState, widget_ids }) {
36502
36430
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
36431
+ const hasCalledRef = useRef(false);
36503
36432
  const content = ((_b = (_a = summaryState === null || summaryState === void 0 ? void 0 : summaryState.summary_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.content) || ((_e = (_d = (_c = summaryState === null || summaryState === void 0 ? void 0 : summaryState.state) === null || _c === void 0 ? void 0 : _c.summary_data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.content) || "";
36504
36433
  const title = ((_f = summaryState === null || summaryState === void 0 ? void 0 : summaryState.summary_data) === null || _f === void 0 ? void 0 : _f.title) || ((_h = (_g = summaryState === null || summaryState === void 0 ? void 0 : summaryState.state) === null || _g === void 0 ? void 0 : _g.summary_data) === null || _h === void 0 ? void 0 : _h.title) || "";
36505
36434
  const data = ((_j = summaryState === null || summaryState === void 0 ? void 0 : summaryState.summary_data) === null || _j === void 0 ? void 0 : _j.data) || ((_l = (_k = summaryState === null || summaryState === void 0 ? void 0 : summaryState.state) === null || _k === void 0 ? void 0 : _k.summary_data) === null || _l === void 0 ? void 0 : _l.data) || null;
36506
36435
  const metadata = ((_m = summaryState === null || summaryState === void 0 ? void 0 : summaryState.summary_data) === null || _m === void 0 ? void 0 : _m.metadata) || ((_p = (_o = summaryState === null || summaryState === void 0 ? void 0 : summaryState.state) === null || _o === void 0 ? void 0 : _o.summary_data) === null || _p === void 0 ? void 0 : _p.metadata) || null;
36507
36436
  const isEmpty = !content || content.trim() === "";
36508
- const clearChat = async () => {
36509
- if (!widgetBackendUrl || !widgetId)
36510
- return;
36511
- console.log('clearChat called for widgetId:', widgetId);
36512
- try {
36513
- await fetch(`${widgetBackendUrl}/api/clear-chat`, {
36514
- method: 'POST',
36515
- headers: {
36516
- 'Content-Type': 'application/json',
36517
- },
36518
- body: JSON.stringify({
36519
- session_id: widgetId,
36520
- delete_state: true
36521
- }),
36522
- });
36523
- // Clear chart state directly after clearing chat
36524
- console.log('Dispatching clearChartState event from clearChat for widgetId:', widgetId);
36525
- window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId } }));
36526
- }
36527
- catch (error) {
36528
- console.error('Failed to clear chat:', error);
36529
- }
36530
- };
36531
36437
  const handleRefresh = async () => {
36532
36438
  if (query) {
36533
36439
  await clearChat();
@@ -36541,13 +36447,14 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
36541
36447
  }
36542
36448
  };
36543
36449
  useEffect(() => {
36544
- if (isEmpty && query && isFirstLoad && !(summaryState === null || summaryState === void 0 ? void 0 : summaryState.agent_message)) {
36450
+ if (isEmpty && query && isFirstLoad && !(summaryState === null || summaryState === void 0 ? void 0 : summaryState.agent_message) && !hasCalledRef.current) {
36451
+ hasCalledRef.current = true;
36545
36452
  setChartState(prevState => (Object.assign(Object.assign({}, prevState), { widget_ids: widget_ids })));
36546
36453
  setTimeout(() => {
36547
36454
  handleRefresh();
36548
36455
  }, 500);
36549
36456
  }
36550
- }, [isEmpty, query, isFirstLoad]);
36457
+ }, [isEmpty, query, isFirstLoad, summaryState]);
36551
36458
  // Start timeout when summary is empty and loading
36552
36459
  useEffect(() => {
36553
36460
  if (isEmpty && startLoadingTimeout && !(summaryState === null || summaryState === void 0 ? void 0 : summaryState.agent_message)) {
@@ -36558,196 +36465,24 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
36558
36465
  }
36559
36466
  }, [isEmpty, startLoadingTimeout, clearLoadingTimeout]);
36560
36467
  if (isEmpty) {
36561
- return (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-2", children: [jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-blue-500" }), jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: "Loading summary..." })] }) }));
36468
+ return createLoadingComponent("Loading summary...");
36562
36469
  }
36563
36470
  return (jsxRuntimeExports.jsx(SummaryWidget, { title: title, data: data, metadata: metadata, className: "" }));
36564
36471
  }
36565
- function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds, widgetBackendUrl }) {
36566
- 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, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39;
36472
+ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds, widgetBackendUrl, datasetId }) {
36473
+ 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, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
36567
36474
  const agentType = (_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentType;
36568
36475
  const orientation = (_b = widget.config) === null || _b === void 0 ? void 0 : _b.orientation;
36569
36476
  const isFirstLoad = (_c = widget.config) === null || _c === void 0 ? void 0 : _c.isFirstLoad;
36570
36477
  const { threadId, setThreadId } = useCopilotContext();
36571
36478
  const timeoutRef = useRef(null);
36572
36479
  const [isTimeoutTriggered, setIsTimeoutTriggered] = useState(false);
36573
- const [timeoutCount, setTimeoutCount] = useState(0);
36574
36480
  useEffect(() => {
36575
36481
  setThreadId(widget.id);
36576
36482
  }, [widget.id, setThreadId]);
36577
- const getInitialState = () => {
36578
- if (agentType === "Pie Chart Agent") {
36579
- return {
36580
- pie_chart_data: {
36581
- title: "",
36582
- type: "pie",
36583
- chart_type: "financial",
36584
- data: {
36585
- labels: [],
36586
- values: [],
36587
- percentages: [],
36588
- total: 0
36589
- },
36590
- metadata: {
36591
- categories: 0,
36592
- largest_category: "",
36593
- largest_value: 0,
36594
- largest_percentage: 0
36595
- }
36596
- }
36597
- };
36598
- }
36599
- else if (agentType === "Line Chart Agent") {
36600
- return {
36601
- bar_chart_data: {
36602
- title: "",
36603
- type: "line",
36604
- chart_type: "financial",
36605
- orientation: "horizontal",
36606
- data: {
36607
- labels: [],
36608
- values: [],
36609
- total: 0,
36610
- average: 0
36611
- },
36612
- metadata: {
36613
- categories: 0,
36614
- highest_category: "",
36615
- highest_value: 0,
36616
- lowest_category: "",
36617
- lowest_value: 0,
36618
- range: 0
36619
- }
36620
- }
36621
- };
36622
- }
36623
- else if (agentType === "Data Grid Agent") {
36624
- return {
36625
- matrix_grid_data: {
36626
- title: "",
36627
- type: "data_grid",
36628
- data: {
36629
- headers: [],
36630
- rows: [],
36631
- "row_count": 0,
36632
- "column_count": 0
36633
- },
36634
- metadata: {
36635
- total_rows: 0,
36636
- total_columns: 0,
36637
- numeric_columns: []
36638
- }
36639
- }
36640
- };
36641
- }
36642
- else if (agentType === "Bar Chart Agent") {
36643
- return {
36644
- bar_chart_data: {
36645
- title: "",
36646
- type: "bar",
36647
- chart_type: "financial",
36648
- orientation: "vertical",
36649
- data: {
36650
- labels: [],
36651
- values: [],
36652
- total: 0,
36653
- average: 0
36654
- },
36655
- metadata: {
36656
- categories: 0,
36657
- highest_category: "",
36658
- highest_value: 0,
36659
- lowest_category: "",
36660
- lowest_value: 0,
36661
- range: 0
36662
- }
36663
- }
36664
- };
36665
- }
36666
- else if (agentType === "Series Bar Chart Agent") {
36667
- return {
36668
- series_bar_chart_data: {
36669
- title: "",
36670
- type: "series_bar",
36671
- chart_type: "financial",
36672
- orientation: "vertical",
36673
- data: {
36674
- labels: [],
36675
- series: [],
36676
- total: 0,
36677
- average: 0
36678
- },
36679
- metadata: {
36680
- categories: 0,
36681
- series_count: 0,
36682
- highest_category: "",
36683
- highest_value: 0,
36684
- highest_series: "",
36685
- lowest_category: "",
36686
- lowest_value: 0,
36687
- lowest_series: "",
36688
- range: 0,
36689
- series_totals: {},
36690
- series_averages: {}
36691
- }
36692
- }
36693
- };
36694
- }
36695
- else if (agentType === "Series Line Chart Agent") {
36696
- return {
36697
- series_bar_chart_data: {
36698
- title: "",
36699
- type: "series_bar",
36700
- chart_type: "financial",
36701
- orientation: "vertical",
36702
- data: {
36703
- labels: [],
36704
- series: [],
36705
- total: 0,
36706
- average: 0
36707
- },
36708
- metadata: {
36709
- categories: 0,
36710
- series_count: 0,
36711
- highest_category: "",
36712
- highest_value: 0,
36713
- highest_series: "",
36714
- lowest_category: "",
36715
- lowest_value: 0,
36716
- lowest_series: "",
36717
- range: 0,
36718
- series_totals: {},
36719
- series_averages: {}
36720
- }
36721
- }
36722
- };
36723
- }
36724
- else if (agentType === "Summary Agent") {
36725
- return {
36726
- summary_data: {
36727
- title: "",
36728
- type: "summary",
36729
- data: {
36730
- content: "",
36731
- word_count: 0,
36732
- character_count: 0,
36733
- character_count_no_spaces: 0,
36734
- line_count: 0
36735
- },
36736
- metadata: {
36737
- created_at: "",
36738
- content_type: "text",
36739
- is_multiline: false
36740
- }
36741
- }
36742
- };
36743
- }
36744
- else {
36745
- return { widget_ids: widgetIds };
36746
- }
36747
- };
36748
36483
  const { state: chartState, setState: setChartState } = useCoAgent({
36749
36484
  name: (_d = widget.config) === null || _d === void 0 ? void 0 : _d.agentName,
36750
- initialState: getInitialState(),
36485
+ initialState: createInitialChartState(agentType || '', widgetIds, datasetId),
36751
36486
  });
36752
36487
  // Function to handle timeout and call loadAgentState API
36753
36488
  const handleLoadingTimeout = useCallback(async () => {
@@ -36756,7 +36491,6 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36756
36491
  return;
36757
36492
  console.log('Loading timeout triggered for widget:', widget.id);
36758
36493
  setIsTimeoutTriggered(true);
36759
- setTimeoutCount(prev => prev + 1);
36760
36494
  const agentName = ((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName) || "adk-construction-project-agent";
36761
36495
  const apiResponse = await loadAgentState(widgetBackendUrl, widget.id, agentName);
36762
36496
  if (apiResponse && !(chartState === null || chartState === void 0 ? void 0 : chartState.agent_message)) {
@@ -36795,8 +36529,7 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36795
36529
  delete_state: true
36796
36530
  }),
36797
36531
  });
36798
- // Reset chart state based on agent type - call getInitialState from local scope
36799
- setChartState(getInitialState());
36532
+ setChartState(createInitialChartState(agentType || '', widgetIds, datasetId));
36800
36533
  }
36801
36534
  catch (error) {
36802
36535
  console.error('Failed to clear chat and state:', error);
@@ -36810,25 +36543,16 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36810
36543
  }
36811
36544
  };
36812
36545
  }, []);
36813
- const { appendMessage, reset, isLoading } = useCopilotChat();
36546
+ const { appendMessage, reset } = useCopilotChat();
36814
36547
  // Register the reset function with the parent component
36815
36548
  useEffect(() => {
36816
- console.log('onResetReady available:', !!onResetReady, 'reset available:', !!reset, 'widget.id:', widget.id);
36817
36549
  if (onResetReady && reset && widget.id) {
36818
- console.log('Registering reset function for widget:', widget.id);
36819
- // Create a wrapped reset function that also clears chart state
36820
36550
  const wrappedReset = () => {
36821
- console.log('Reset called for widget:', widget.id);
36822
36551
  reset();
36823
- // Clear chart state after reset
36824
- console.log('Dispatching clearChartState event from reset for widgetId:', widget.id);
36825
36552
  window.dispatchEvent(new CustomEvent('clearChartState', { detail: { widgetId: widget.id } }));
36826
36553
  };
36827
36554
  onResetReady(widget.id, wrappedReset);
36828
36555
  }
36829
- else {
36830
- console.log('Not registering reset - missing dependencies');
36831
- }
36832
36556
  }, [reset, widget.id, onResetReady]); // Removed onResetReady from deps to avoid the error
36833
36557
  // Listen for triggerAgent events for this widget
36834
36558
  useEffect(() => {
@@ -36866,183 +36590,10 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36866
36590
  };
36867
36591
  const handleClearChartState = (event) => {
36868
36592
  const { widgetId } = event.detail;
36869
- console.log('Received clearChartState event - widgetId:', widgetId, 'current widget.id:', widget.id);
36870
36593
  if (widgetId === widget.id) {
36871
- console.log('Clearing chart state for widget:', widgetId);
36872
- // Reset chart state based on agent type with explicit initial state
36873
- if (agentType === "Pie Chart Agent") {
36874
- setChartState({
36875
- pie_chart_data: {
36876
- title: "",
36877
- type: "pie",
36878
- chart_type: "financial",
36879
- data: {
36880
- labels: [],
36881
- values: [],
36882
- percentages: [],
36883
- total: 0
36884
- },
36885
- metadata: {
36886
- categories: 0,
36887
- largest_category: "",
36888
- largest_value: 0,
36889
- largest_percentage: 0
36890
- }
36891
- }
36892
- });
36893
- }
36894
- else if (agentType === "Bar Chart Agent") {
36895
- setChartState({
36896
- bar_chart_data: {
36897
- title: "",
36898
- type: "bar",
36899
- chart_type: "financial",
36900
- orientation: "vertical",
36901
- data: {
36902
- labels: [],
36903
- values: [],
36904
- total: 0,
36905
- average: 0
36906
- },
36907
- metadata: {
36908
- categories: 0,
36909
- highest_category: "",
36910
- highest_value: 0,
36911
- lowest_category: "",
36912
- lowest_value: 0,
36913
- range: 0
36914
- }
36915
- }
36916
- });
36917
- }
36918
- else if (agentType === "Series Bar Chart Agent") {
36919
- setChartState({
36920
- series_bar_chart_data: {
36921
- title: "",
36922
- type: "series_bar",
36923
- chart_type: "financial",
36924
- orientation: "vertical",
36925
- data: {
36926
- labels: [],
36927
- series: [],
36928
- total: 0,
36929
- average: 0
36930
- },
36931
- metadata: {
36932
- categories: 0,
36933
- series_count: 0,
36934
- highest_category: "",
36935
- highest_value: 0,
36936
- highest_series: "",
36937
- lowest_category: "",
36938
- lowest_value: 0,
36939
- lowest_series: "",
36940
- range: 0,
36941
- series_totals: {},
36942
- series_averages: {}
36943
- }
36944
- }
36945
- });
36946
- }
36947
- else if (agentType === "Series Line Chart Agent") {
36948
- setChartState({
36949
- series_bar_chart_data: {
36950
- title: "",
36951
- type: "series_bar",
36952
- chart_type: "financial",
36953
- orientation: "vertical",
36954
- data: {
36955
- labels: [],
36956
- series: [],
36957
- total: 0,
36958
- average: 0
36959
- },
36960
- metadata: {
36961
- categories: 0,
36962
- series_count: 0,
36963
- highest_category: "",
36964
- highest_value: 0,
36965
- highest_series: "",
36966
- lowest_category: "",
36967
- lowest_value: 0,
36968
- lowest_series: "",
36969
- range: 0,
36970
- series_totals: {},
36971
- series_averages: {}
36972
- }
36973
- }
36974
- });
36975
- }
36976
- else if (agentType === "Line Chart Agent") {
36977
- setChartState({
36978
- bar_chart_data: {
36979
- title: "",
36980
- type: "line",
36981
- chart_type: "financial",
36982
- orientation: "horizontal",
36983
- data: {
36984
- labels: [],
36985
- values: [],
36986
- total: 0,
36987
- average: 0
36988
- },
36989
- metadata: {
36990
- categories: 0,
36991
- highest_category: "",
36992
- highest_value: 0,
36993
- lowest_category: "",
36994
- lowest_value: 0,
36995
- range: 0
36996
- }
36997
- }
36998
- });
36999
- }
37000
- else if (agentType === "Data Grid Agent") {
37001
- setChartState({
37002
- matrix_grid_data: {
37003
- title: "",
37004
- type: "data_grid",
37005
- grid_type: "",
37006
- data: {
37007
- headers: [],
37008
- rows: [],
37009
- row_count: 0,
37010
- column_count: 0
37011
- },
37012
- metadata: {
37013
- total_rows: 0,
37014
- total_columns: 0,
37015
- numeric_columns: []
37016
- }
37017
- }
37018
- });
37019
- }
37020
- else if (agentType === "Summary Agent") {
37021
- setChartState({
37022
- summary_data: {
37023
- title: "",
37024
- type: "summary",
37025
- data: {
37026
- content: "",
37027
- word_count: 0,
37028
- character_count: 0,
37029
- character_count_no_spaces: 0,
37030
- line_count: 0
37031
- },
37032
- metadata: {
37033
- created_at: "",
37034
- content_type: "text",
37035
- is_multiline: false
37036
- }
37037
- }
37038
- });
37039
- }
37040
- else {
37041
- setChartState({ widget_ids: widgetIds });
37042
- }
36594
+ setChartState(createInitialChartState(agentType || '', widgetIds, datasetId));
37043
36595
  }
37044
36596
  };
37045
- console.log('Setting up event listeners for widget:', widget.id);
37046
36597
  window.addEventListener('triggerAgent', handleTriggerAgent);
37047
36598
  window.addEventListener('clearChartState', handleClearChartState);
37048
36599
  return () => {
@@ -37050,59 +36601,22 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
37050
36601
  window.removeEventListener('clearChartState', handleClearChartState);
37051
36602
  };
37052
36603
  }, [widget.id, appendMessage, agentType, setChartState]);
37053
- // Monitor chartState and add manual clear functionality
37054
- useEffect(() => {
37055
- // Add a global function to manually clear this widget's state
37056
- const clearThisWidget = () => {
37057
- console.log('Manual clear triggered for widget:', widget.id);
37058
- if (agentType === "Pie Chart Agent") {
37059
- setChartState({
37060
- pie_chart_data: {
37061
- title: "",
37062
- type: "pie",
37063
- chart_type: "financial",
37064
- data: {
37065
- labels: [],
37066
- values: [],
37067
- percentages: [],
37068
- total: 0
37069
- },
37070
- metadata: {
37071
- categories: 0,
37072
- largest_category: "",
37073
- largest_value: 0,
37074
- largest_percentage: 0
37075
- }
37076
- }
37077
- });
37078
- }
37079
- // Add other agent types as needed
37080
- };
37081
- // Make it globally accessible for testing
37082
- window[`clearWidget_${widget.id}`] = clearThisWidget;
37083
- return () => {
37084
- delete window[`clearWidget_${widget.id}`];
37085
- };
37086
- }, [widget.id, agentType, setChartState]);
37087
- console.log('agent_message==>', chartState === null || chartState === void 0 ? void 0 : chartState.agent_message);
37088
- console.log('Pie Chart Agent==>', (agentType === "Pie Chart Agent" && (!((_h = (_g = (_f = chartState.pie_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.labels) === null || _h === void 0 ? void 0 : _h.length) || !((_l = (_k = (_j = chartState.pie_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.values) === null || _l === void 0 ? void 0 : _l.length))));
37089
- console.log('chartState.pie_chart_data?.data?.labels?.length==>', (_o = (_m = chartState.pie_chart_data) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.labels);
37090
36604
  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" && (
37091
36605
  // Check if data is empty based on agent type
37092
- (agentType === "Bar Chart Agent" && (!((_r = (_q = (_p = chartState.bar_chart_data) === null || _p === void 0 ? void 0 : _p.data) === null || _q === void 0 ? void 0 : _q.labels) === null || _r === void 0 ? void 0 : _r.length) || !((_u = (_t = (_s = chartState.bar_chart_data) === null || _s === void 0 ? void 0 : _s.data) === null || _t === void 0 ? void 0 : _t.values) === null || _u === void 0 ? void 0 : _u.length))) ||
37093
- (agentType === "Series Bar Chart Agent" && (!((_x = (_w = (_v = chartState.series_bar_chart_data) === null || _v === void 0 ? void 0 : _v.data) === null || _w === void 0 ? void 0 : _w.labels) === null || _x === void 0 ? void 0 : _x.length) || !((_0 = (_z = (_y = chartState.series_bar_chart_data) === null || _y === void 0 ? void 0 : _y.data) === null || _z === void 0 ? void 0 : _z.series) === null || _0 === void 0 ? void 0 : _0.length))) ||
37094
- (agentType === "Series Line Chart Agent" && (!((_3 = (_2 = (_1 = chartState.series_bar_chart_data) === null || _1 === void 0 ? void 0 : _1.data) === null || _2 === void 0 ? void 0 : _2.labels) === null || _3 === void 0 ? void 0 : _3.length) || !((_6 = (_5 = (_4 = chartState.series_bar_chart_data) === null || _4 === void 0 ? void 0 : _4.data) === null || _5 === void 0 ? void 0 : _5.series) === null || _6 === void 0 ? void 0 : _6.length))) ||
37095
- (agentType === "Pie Chart Agent" && (!((_9 = (_8 = (_7 = chartState.pie_chart_data) === null || _7 === void 0 ? void 0 : _7.data) === null || _8 === void 0 ? void 0 : _8.labels) === null || _9 === void 0 ? void 0 : _9.length) || !((_12 = (_11 = (_10 = chartState.pie_chart_data) === null || _10 === void 0 ? void 0 : _10.data) === null || _11 === void 0 ? void 0 : _11.values) === null || _12 === void 0 ? void 0 : _12.length))) ||
37096
- (agentType === "Line Chart Agent" && (!((_15 = (_14 = (_13 = chartState.bar_chart_data) === null || _13 === void 0 ? void 0 : _13.data) === null || _14 === void 0 ? void 0 : _14.labels) === null || _15 === void 0 ? void 0 : _15.length) || !((_18 = (_17 = (_16 = chartState.bar_chart_data) === null || _16 === void 0 ? void 0 : _16.data) === null || _17 === void 0 ? void 0 : _17.values) === null || _18 === void 0 ? void 0 : _18.length))) ||
37097
- (agentType === "Data Grid Agent" && (!((_21 = (_20 = (_19 = chartState.matrix_grid_data) === null || _19 === void 0 ? void 0 : _19.data) === null || _20 === void 0 ? void 0 : _20.headers) === null || _21 === void 0 ? void 0 : _21.length) || !((_24 = (_23 = (_22 = chartState.matrix_grid_data) === null || _22 === void 0 ? void 0 : _22.data) === null || _23 === void 0 ? void 0 : _23.rows) === null || _24 === void 0 ? void 0 : _24.length))) ||
37098
- (agentType === "Summary Agent" && (!((_26 = (_25 = chartState.summary_data) === null || _25 === void 0 ? void 0 : _25.data) === null || _26 === void 0 ? void 0 : _26.content) || ((_29 = (_28 = (_27 = chartState.summary_data) === null || _27 === void 0 ? void 0 : _27.data) === null || _28 === void 0 ? void 0 : _28.content) === null || _29 === void 0 ? void 0 : _29.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 }) }) })) : agentType === "Bar Chart Agent" ? (jsxRuntimeExports.jsx(BarChartComponent, { barChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_30 = widget.config) === null || _30 === void 0 ? void 0 : _30.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Series Bar Chart Agent" ? (jsxRuntimeExports.jsx(SeriesBarChartComponent, { seriesBarChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_31 = widget.config) === null || _31 === void 0 ? void 0 : _31.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: (_32 = widget.config) === null || _32 === void 0 ? void 0 : _32.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: (_33 = widget.config) === null || _33 === void 0 ? void 0 : _33.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Line Chart Agent" ? (jsxRuntimeExports.jsx(LineChartComponent, { lineChartState: chartState, styles: styles, appendMessage: appendMessage, query: (_34 = widget.config) === null || _34 === void 0 ? void 0 : _34.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: (_35 = widget.config) === null || _35 === void 0 ? void 0 : _35.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: (_36 = widget.config) === null || _36 === void 0 ? void 0 : _36.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: {
37099
- title: ((_37 = widget.config) === null || _37 === void 0 ? void 0 : _37.copilotTitle) || widget.title,
37100
- initial: ((_38 = widget.config) === null || _38 === void 0 ? void 0 : _38.copilotInitialMessage) || ((_39 = widget.config) === null || _39 === void 0 ? void 0 : _39.placeholder) || "How can I help you today?"
36606
+ (agentType === "Bar Chart Agent" && (!((_h = (_g = (_f = chartState.bar_chart_data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.labels) === null || _h === void 0 ? void 0 : _h.length) || !((_l = (_k = (_j = chartState.bar_chart_data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.values) === null || _l === void 0 ? void 0 : _l.length))) ||
36607
+ (agentType === "Series Bar Chart Agent" && (!((_p = (_o = (_m = chartState.series_bar_chart_data) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.labels) === null || _p === void 0 ? void 0 : _p.length) || !((_s = (_r = (_q = chartState.series_bar_chart_data) === null || _q === void 0 ? void 0 : _q.data) === null || _r === void 0 ? void 0 : _r.series) === null || _s === void 0 ? void 0 : _s.length))) ||
36608
+ (agentType === "Series Line Chart Agent" && (!((_v = (_u = (_t = chartState.series_bar_chart_data) === null || _t === void 0 ? void 0 : _t.data) === null || _u === void 0 ? void 0 : _u.labels) === null || _v === void 0 ? void 0 : _v.length) || !((_y = (_x = (_w = chartState.series_bar_chart_data) === null || _w === void 0 ? void 0 : _w.data) === null || _x === void 0 ? void 0 : _x.series) === null || _y === void 0 ? void 0 : _y.length))) ||
36609
+ (agentType === "Pie Chart Agent" && (!((_1 = (_0 = (_z = chartState.pie_chart_data) === null || _z === void 0 ? void 0 : _z.data) === null || _0 === void 0 ? void 0 : _0.labels) === null || _1 === void 0 ? void 0 : _1.length) || !((_4 = (_3 = (_2 = chartState.pie_chart_data) === null || _2 === void 0 ? void 0 : _2.data) === null || _3 === void 0 ? void 0 : _3.values) === null || _4 === void 0 ? void 0 : _4.length))) ||
36610
+ (agentType === "Line Chart Agent" && (!((_7 = (_6 = (_5 = chartState.bar_chart_data) === null || _5 === void 0 ? void 0 : _5.data) === null || _6 === void 0 ? void 0 : _6.labels) === null || _7 === void 0 ? void 0 : _7.length) || !((_10 = (_9 = (_8 = chartState.bar_chart_data) === null || _8 === void 0 ? void 0 : _8.data) === null || _9 === void 0 ? void 0 : _9.values) === null || _10 === void 0 ? void 0 : _10.length))) ||
36611
+ (agentType === "Data Grid Agent" && (!((_13 = (_12 = (_11 = chartState.matrix_grid_data) === null || _11 === void 0 ? void 0 : _11.data) === null || _12 === void 0 ? void 0 : _12.headers) === null || _13 === void 0 ? void 0 : _13.length) || !((_16 = (_15 = (_14 = chartState.matrix_grid_data) === null || _14 === void 0 ? void 0 : _14.data) === null || _15 === void 0 ? void 0 : _15.rows) === null || _16 === void 0 ? void 0 : _16.length))) ||
36612
+ (agentType === "Summary Agent" && (!((_18 = (_17 = chartState.summary_data) === null || _17 === void 0 ? void 0 : _17.data) === null || _18 === void 0 ? void 0 : _18.content) || ((_21 = (_20 = (_19 = chartState.summary_data) === null || _19 === void 0 ? void 0 : _19.data) === null || _20 === void 0 ? void 0 : _20.content) === null || _21 === void 0 ? void 0 : _21.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 }) }) })) : agentType === "Bar Chart Agent" ? (jsxRuntimeExports.jsx(BarChartComponent, { barChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_22 = widget.config) === null || _22 === void 0 ? void 0 : _22.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Series Bar Chart Agent" ? (jsxRuntimeExports.jsx(SeriesBarChartComponent, { seriesBarChartState: chartState, styles: styles, orientation: orientation, appendMessage: appendMessage, query: (_23 = widget.config) === null || _23 === void 0 ? void 0 : _23.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: (_24 = widget.config) === null || _24 === void 0 ? void 0 : _24.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: (_25 = widget.config) === null || _25 === void 0 ? void 0 : _25.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout })) : agentType === "Line Chart Agent" ? (jsxRuntimeExports.jsx(LineChartComponent, { lineChartState: chartState, styles: styles, appendMessage: appendMessage, query: (_26 = widget.config) === null || _26 === void 0 ? void 0 : _26.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: (_27 = widget.config) === null || _27 === void 0 ? void 0 : _27.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: (_28 = widget.config) === null || _28 === void 0 ? void 0 : _28.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: {
36613
+ title: ((_29 = widget.config) === null || _29 === void 0 ? void 0 : _29.copilotTitle) || widget.title,
36614
+ 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?"
37101
36615
  }, onSubmitMessage: () => {
37102
36616
  setChartState(prevState => (Object.assign(Object.assign({}, prevState), { widget_ids: widgetIds })));
37103
36617
  } })) })] }));
37104
36618
  }
37105
- function AgentWidget({ widget, showHeader = true, widgetBackendUrl, onResetReady, widgetIds, }) {
36619
+ function AgentWidget({ widget, showHeader = true, widgetBackendUrl, onResetReady, widgetIds, datasetId, }) {
37106
36620
  var _a, _b;
37107
36621
  const styles = getStyleValues((_a = widget.config) === null || _a === void 0 ? void 0 : _a.styles);
37108
36622
  // Construct the runtime URL using the configurable backend URL
@@ -37112,10 +36626,10 @@ function AgentWidget({ widget, showHeader = true, widgetBackendUrl, onResetReady
37112
36626
  const agentName = ((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName) || 'default-agent';
37113
36627
  return `${baseUrl}/api/copilot/${agentName}`;
37114
36628
  };
37115
- return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: jsxRuntimeExports.jsx(CopilotKit, { runtimeUrl: getRuntimeUrl(), showDevConsole: false, agent: ((_b = widget.config) === null || _b === void 0 ? void 0 : _b.agentName) || "widget_assistant", children: jsxRuntimeExports.jsx(CopilotKitAgent, { widget: widget, showHeader: showHeader, styles: styles, onResetReady: onResetReady, widgetIds: widgetIds, widgetBackendUrl: widgetBackendUrl }) }) }));
36629
+ return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: jsxRuntimeExports.jsx(CopilotKit, { runtimeUrl: getRuntimeUrl(), showDevConsole: false, agent: ((_b = widget.config) === null || _b === void 0 ? void 0 : _b.agentName) || "widget_assistant", children: jsxRuntimeExports.jsx(CopilotKitAgent, { widget: widget, showHeader: showHeader, styles: styles, onResetReady: onResetReady, widgetIds: widgetIds, widgetBackendUrl: widgetBackendUrl, datasetId: datasetId }) }) }));
37116
36630
  }
37117
36631
 
37118
- function WidgetRenderer({ widget, isTemplate = false, onConfigUpdate, widgetBackendUrl, onResetReady, widgetIds, }) {
36632
+ function WidgetRenderer({ widget, isTemplate = false, onConfigUpdate, widgetBackendUrl, onResetReady, widgetIds, datasetId, }) {
37119
36633
  const handleConfigUpdate = (config) => {
37120
36634
  if (onConfigUpdate) {
37121
36635
  onConfigUpdate(widget.id, config);
@@ -37138,7 +36652,7 @@ function WidgetRenderer({ widget, isTemplate = false, onConfigUpdate, widgetBack
37138
36652
  return (jsxRuntimeExports.jsx(FacetWidget, { widget: widget, showHeader: false, onConfigUpdate: handleConfigUpdate }));
37139
36653
  case "agent":
37140
36654
  case "chatbot":
37141
- return jsxRuntimeExports.jsx(AgentWidget, { widget: widget, showHeader: false, widgetBackendUrl: widgetBackendUrl, onResetReady: onResetReady, widgetIds: widgetIds });
36655
+ return jsxRuntimeExports.jsx(AgentWidget, { widget: widget, showHeader: false, widgetBackendUrl: widgetBackendUrl, onResetReady: onResetReady, widgetIds: widgetIds, datasetId: datasetId });
37142
36656
  default:
37143
36657
  return (jsxRuntimeExports.jsxs("div", { className: "text-muted-foreground", children: ["Unknown widget type: ", widget.type] }));
37144
36658
  }
@@ -37378,6 +36892,7 @@ const IconMap = {
37378
36892
  };
37379
36893
  function WidgetDashboard({ pageId, isEditing, selectedWidget = null, onWidgetSelect, refreshKey, widgetBackendUrl, onSaveLayoutReady, openWidgetPallete = false, onCloseWidgetPallete, defaultAgentName = "adk-construction-project-agent", userId }) {
37380
36894
  const [widgets, setWidgets] = useState([]);
36895
+ const [datasetId, setDatasetId] = useState('');
37381
36896
  const [availableWidgets, setAvailableWidgets] = useState([]);
37382
36897
  const [isLoading, setIsLoading] = useState(true);
37383
36898
  const [pageData, setPageData] = useState(null);
@@ -37511,6 +37026,7 @@ function WidgetDashboard({ pageId, isEditing, selectedWidget = null, onWidgetSel
37511
37026
  console.log(data);
37512
37027
  setPageData(data);
37513
37028
  setWidgets(data.widgets || []);
37029
+ setDatasetId(data === null || data === void 0 ? void 0 : data.dataset_id);
37514
37030
  }
37515
37031
  catch (err) {
37516
37032
  console.error("Error loading page data:", err);
@@ -37568,9 +37084,15 @@ function WidgetDashboard({ pageId, isEditing, selectedWidget = null, onWidgetSel
37568
37084
  throw new Error("Failed to save layout");
37569
37085
  }
37570
37086
  const savedData = await response.json();
37571
- setPageData(savedData);
37572
- // Update local widgets state to clear isFirstLoad flag
37573
- setWidgets(prevWidgets => prevWidgets.map(widget => (Object.assign(Object.assign({}, widget), { config: Object.assign(Object.assign({}, widget.config), { isFirstLoad: false }) }))));
37087
+ // setPageData(savedData);
37088
+ // // Update local widgets state to clear isFirstLoad flag
37089
+ // setWidgets(prevWidgets => prevWidgets.map(widget => ({
37090
+ // ...widget,
37091
+ // config: {
37092
+ // ...widget.config,
37093
+ // isFirstLoad: false
37094
+ // }
37095
+ // })));
37574
37096
  console.log('Layout saved successfully');
37575
37097
  }
37576
37098
  catch (err) {
@@ -37839,7 +37361,7 @@ function WidgetDashboard({ pageId, isEditing, selectedWidget = null, onWidgetSel
37839
37361
  onCloseWidgetPallete === null || onCloseWidgetPallete === void 0 ? void 0 : onCloseWidgetPallete();
37840
37362
  }, defaultAgentName: defaultAgentName }), jsxRuntimeExports.jsx(EditWidgetDialog, { initialText: editInitialQuery, isOpen: showEditModal, onClose: () => setShowEditModal(false), onSubmit: handleEditSubmit }), jsxRuntimeExports.jsx("div", { className: "min-h-full", onDragOver: (e) => e.preventDefault(), onDrop: handleDrop, onClick: () => setSelectedWidget(null), children: isLoading ? (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntimeExports.jsx(Loader2, { className: "h-8 w-8 animate-spin" }) })) : (jsxRuntimeExports.jsx(RGL, { className: "layout m-0 p-0", layouts: { lg: getLayoutFromWidgets() }, breakpoints: { lg: 1200, md: 996, sm: 768, xs: 480 }, cols: { lg: 12, md: 8, sm: 6, xs: 2 }, rowHeight: 100, isDraggable: isEditing, isResizable: isEditing, draggableHandle: ".drag-icon", onLayoutChange: handleLayoutChange, compactType: "vertical", containerPadding: [0, 0], resizeHandles: ["sw", "nw", "se", "ne"], children: widgets.map((w) => (jsxRuntimeExports.jsxs("div", { style: { borderColor: "rgb(147 197 253 / 1)" }, className: `border border-blue-300 rounded-xl p-4 shadow-lg overflow-hidden ${isEditing ? 'pb-20' : 'pb-14'}`, children: [isEditing &&
37841
37363
  jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-end mb-4 relative", children: [jsxRuntimeExports.jsxs("div", { className: "flex items-center drag-icon cursor-grab absolute left-1/2 -translate-x-1/2", children: [jsxRuntimeExports.jsx(GripHorizontal, { className: "" }), jsxRuntimeExports.jsx(GripHorizontal, { className: "-ml-[3px]" }), jsxRuntimeExports.jsx(GripHorizontal, { className: "-ml-[3px]" })] }), jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 cursor-pointer justify-end", children: [jsxRuntimeExports.jsx(Trash2, { onClick: () => removeWidget(w.id), className: "w-5 h-5 text-red-700" }), jsxRuntimeExports.jsx(Edit, { onClick: () => onClickSettings && onClickSettings(w), className: "w-5 h-5 text-gray-600" })] })] }), jsxRuntimeExports.jsxs("div", { className: "w-full h-full relative", children: [(w === null || w === void 0 ? void 0 : w.type) === "chatbot" &&
37842
- jsxRuntimeExports.jsxs("div", { className: "relative z-50", children: [jsxRuntimeExports.jsx("div", { onClick: () => handleClearChat(w.id), onMouseOver: () => setVisibleClearButton(true), onMouseLeave: () => setVisibleClearButton(false), className: "absolute z-40 flex align-middle justify-center gap-2 text-sm px-4 py-2 border-blue-300 rounded-sm dark:bg-white w-fit bg-gray-900 text-white dark:text-gray-900 cursor-pointer shadow-md transition-all", style: { top: "12px", right: "0", borderTopLeftRadius: "4px", borderBottomLeftRadius: "4px" }, children: jsxRuntimeExports.jsx(MessageCircleX, { className: "w-5 h-5" }) }), jsxRuntimeExports.jsx("span", { className: `absolute z-50 w-max py-1 text-xs px-2 rounded-sm dark:text-gray-900 dark:bg-white text-white bg-gray-900 ${visibleClearButton ? "block" : "hidden"}`, style: { top: "56px", right: "16px", borderRadius: "3px" }, children: "Clear Chat" })] }), jsxRuntimeExports.jsx(WidgetRenderer, { widget: w, widgetBackendUrl: widgetBackendUrl, onResetReady: handleResetReady, widgetIds: widgets.filter(widget => widget.type !== 'chatbot').map(widget => widget.id) })] })] }, w.id))) })) })] }));
37364
+ jsxRuntimeExports.jsxs("div", { className: "relative z-50", children: [jsxRuntimeExports.jsx("div", { onClick: () => handleClearChat(w.id), onMouseOver: () => setVisibleClearButton(true), onMouseLeave: () => setVisibleClearButton(false), className: "absolute z-40 flex align-middle justify-center gap-2 text-sm px-4 py-2 border-blue-300 rounded-sm dark:bg-white w-fit bg-gray-900 text-white dark:text-gray-900 cursor-pointer shadow-md transition-all", style: { top: "12px", right: "0", borderTopLeftRadius: "4px", borderBottomLeftRadius: "4px" }, children: jsxRuntimeExports.jsx(MessageCircleX, { className: "w-5 h-5" }) }), jsxRuntimeExports.jsx("span", { className: `absolute z-50 w-max py-1 text-xs px-2 rounded-sm dark:text-gray-900 dark:bg-white text-white bg-gray-900 ${visibleClearButton ? "block" : "hidden"}`, style: { top: "56px", right: "16px", borderRadius: "3px" }, children: "Clear Chat" })] }), jsxRuntimeExports.jsx(WidgetRenderer, { widget: w, widgetBackendUrl: widgetBackendUrl, onResetReady: handleResetReady, widgetIds: widgets.filter(widget => widget.type !== 'chatbot').map(widget => widget.id), datasetId: datasetId })] })] }, w.id))) })) })] }));
37843
37365
  }
37844
37366
 
37845
37367
  const Checkbox = React.forwardRef((_a, ref) => {