dp-widgets-framework 1.6.6 → 1.6.8

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 CHANGED
@@ -43606,6 +43606,24 @@ const loadAgentState$5 = async (widgetBackendUrl, threadId, agentName) => {
43606
43606
  return null;
43607
43607
  }
43608
43608
  };
43609
+ const loadSessionStateDirect$5 = async (widgetBackendUrl, sessionId) => {
43610
+ try {
43611
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
43612
+ method: "GET",
43613
+ headers: {
43614
+ "Content-Type": "application/json"
43615
+ }
43616
+ });
43617
+ if (!response.ok) {
43618
+ throw new Error(`HTTP error! status: ${response.status}`);
43619
+ }
43620
+ const result = await response.json();
43621
+ return result;
43622
+ } catch (error) {
43623
+ console.error("Failed to load session state directly:", error);
43624
+ return null;
43625
+ }
43626
+ };
43609
43627
  const parseAndUpdateChartState$4 = (apiResponse, setChartState) => {
43610
43628
  var _a, _b;
43611
43629
  try {
@@ -44140,6 +44158,8 @@ function CopilotKitAgent({
44140
44158
  const [isTimeoutTriggered, setIsTimeoutTriggered] = useState(false);
44141
44159
  const [apiCallCount, setApiCallCount] = useState(0);
44142
44160
  const [hasTimeoutError, setHasTimeoutError] = useState(false);
44161
+ const hasInitialFetchRef = useRef(false);
44162
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = useState(false);
44143
44163
  useEffect(() => {
44144
44164
  setThreadId(widget.id);
44145
44165
  }, [widget.id, setThreadId]);
@@ -44147,6 +44167,18 @@ function CopilotKitAgent({
44147
44167
  name: (_e = widget.config) == null ? void 0 : _e.agentName,
44148
44168
  initialState: createInitialChartState$4(agentType || "", widgetIds, datasetId)
44149
44169
  });
44170
+ useEffect(() => {
44171
+ const fetchInitialState = async () => {
44172
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
44173
+ hasInitialFetchRef.current = true;
44174
+ const apiResponse = await loadSessionStateDirect$5(widgetBackendUrl, widget.id);
44175
+ if (apiResponse) {
44176
+ parseAndUpdateChartState$4(apiResponse, setChartState);
44177
+ }
44178
+ setIsInitialFetchComplete(true);
44179
+ };
44180
+ fetchInitialState();
44181
+ }, [widgetBackendUrl, widget.id, setChartState]);
44150
44182
  const handleLoadingTimeout = useCallback(async () => {
44151
44183
  var _a2;
44152
44184
  if (!widgetBackendUrl || !widget.id || isTimeoutTriggered || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) return;
@@ -44249,7 +44281,7 @@ function CopilotKitAgent({
44249
44281
  /* @__PURE__ */ jsxRuntimeExports.jsx(Bot, { className: "h-4 w-4" }),
44250
44282
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
44251
44283
  ] }) }),
44252
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && agentType !== "chatbot" && // Check if data is empty based on agent type
44284
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && agentType !== "chatbot" && // Check if data is empty based on agent type
44253
44285
  (agentType === "Bar Chart Agent" && (!((_i = (_h = (_g = chartState.bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.values) == null ? void 0 : _l.length)) || agentType === "Series Bar Chart Agent" && (!((_o = (_n = (_m = chartState.series_bar_chart_data) == null ? void 0 : _m.data) == null ? void 0 : _n.labels) == null ? void 0 : _o.length) || !((_r = (_q = (_p = chartState.series_bar_chart_data) == null ? void 0 : _p.data) == null ? void 0 : _q.series) == null ? void 0 : _r.length)) || agentType === "Series Line Chart Agent" && (!((_u = (_t = (_s = chartState.series_bar_chart_data) == null ? void 0 : _s.data) == null ? void 0 : _t.labels) == null ? void 0 : _u.length) || !((_x = (_w = (_v = chartState.series_bar_chart_data) == null ? void 0 : _v.data) == null ? void 0 : _w.series) == null ? void 0 : _x.length)) || agentType === "Pie Chart Agent" && (!((_A = (_z = (_y = chartState.pie_chart_data) == null ? void 0 : _y.data) == null ? void 0 : _z.labels) == null ? void 0 : _A.length) || !((_D = (_C = (_B = chartState.pie_chart_data) == null ? void 0 : _B.data) == null ? void 0 : _C.values) == null ? void 0 : _D.length)) || agentType === "Line Chart Agent" && (!((_G = (_F = (_E = chartState.bar_chart_data) == null ? void 0 : _E.data) == null ? void 0 : _F.labels) == null ? void 0 : _G.length) || !((_J = (_I = (_H = chartState.bar_chart_data) == null ? void 0 : _H.data) == null ? void 0 : _I.values) == null ? void 0 : _J.length)) || agentType === "Data Grid Agent" && (!((_M = (_L = (_K = chartState.matrix_grid_data) == null ? void 0 : _K.data) == null ? void 0 : _L.headers) == null ? void 0 : _M.length) || !((_P = (_O = (_N = chartState.matrix_grid_data) == null ? void 0 : _N.data) == null ? void 0 : _O.rows) == null ? void 0 : _P.length)) || agentType === "Summary Agent" && (!((_R = (_Q = chartState.summary_data) == null ? void 0 : _Q.data) == null ? void 0 : _R.content) || ((_U = (_T = (_S = chartState.summary_data) == null ? void 0 : _S.data) == null ? void 0 : _T.content) == null ? void 0 : _U.trim()) === "")) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : agentType === "Bar Chart Agent" ? /* @__PURE__ */ jsxRuntimeExports.jsx(
44254
44286
  BarChartComponent,
44255
44287
  {
@@ -44773,6 +44805,24 @@ const loadAgentState$4 = async (widgetBackendUrl, threadId, agentName) => {
44773
44805
  return null;
44774
44806
  }
44775
44807
  };
44808
+ const loadSessionStateDirect$4 = async (widgetBackendUrl, sessionId) => {
44809
+ try {
44810
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
44811
+ method: "GET",
44812
+ headers: {
44813
+ "Content-Type": "application/json"
44814
+ }
44815
+ });
44816
+ if (!response.ok) {
44817
+ throw new Error(`HTTP error! status: ${response.status}`);
44818
+ }
44819
+ const result = await response.json();
44820
+ return result;
44821
+ } catch (error) {
44822
+ console.error("Failed to load session state directly:", error);
44823
+ return null;
44824
+ }
44825
+ };
44776
44826
  const parseAndUpdateFilterState = (apiResponse, setFilterState) => {
44777
44827
  var _a, _b;
44778
44828
  try {
@@ -45236,6 +45286,7 @@ function CopilotKitFilters({
45236
45286
  const timeoutRef = useRef(null);
45237
45287
  const [apiCallCount, setApiCallCount] = useState(0);
45238
45288
  const [hasTimeoutError, setHasTimeoutError] = useState(false);
45289
+ const hasInitialFetchRef = useRef(false);
45239
45290
  useEffect(() => {
45240
45291
  setThreadId(widget.id);
45241
45292
  }, [widget.id, setThreadId]);
@@ -45244,6 +45295,17 @@ function CopilotKitFilters({
45244
45295
  initialState: createInitialFilterState(datasetId, widget_data)
45245
45296
  });
45246
45297
  const [filterState, setFilterState] = useState(createInitialFilterState(datasetId, widget_data));
45298
+ useEffect(() => {
45299
+ const fetchInitialState = async () => {
45300
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
45301
+ hasInitialFetchRef.current = true;
45302
+ const apiResponse = await loadSessionStateDirect$4(widgetBackendUrl, widget.id);
45303
+ if (apiResponse) {
45304
+ parseAndUpdateFilterState(apiResponse, setFilterState);
45305
+ }
45306
+ };
45307
+ fetchInitialState();
45308
+ }, [widgetBackendUrl, widget.id, setFilterState]);
45247
45309
  const handleLoadingTimeout = useCallback(async () => {
45248
45310
  var _a2;
45249
45311
  if (!widgetBackendUrl || !widget.id || (filterState == null ? void 0 : filterState.agent_message) || hasTimeoutError) {
@@ -45574,6 +45636,24 @@ const loadAgentState$3 = async (widgetBackendUrl, threadId, agentName) => {
45574
45636
  return null;
45575
45637
  }
45576
45638
  };
45639
+ const loadSessionStateDirect$3 = async (widgetBackendUrl, sessionId) => {
45640
+ try {
45641
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
45642
+ method: "GET",
45643
+ headers: {
45644
+ "Content-Type": "application/json"
45645
+ }
45646
+ });
45647
+ if (!response.ok) {
45648
+ throw new Error(`HTTP error! status: ${response.status}`);
45649
+ }
45650
+ const result = await response.json();
45651
+ return result;
45652
+ } catch (error) {
45653
+ console.error("Failed to load session state directly:", error);
45654
+ return null;
45655
+ }
45656
+ };
45577
45657
  const parseAndUpdateChartState$3 = (apiResponse, setChartState) => {
45578
45658
  var _a, _b;
45579
45659
  try {
@@ -45707,6 +45787,7 @@ function CopilotKitPieChart({
45707
45787
  const timeoutRef = useRef(null);
45708
45788
  const [apiCallCount, setApiCallCount] = useState(0);
45709
45789
  const [hasTimeoutError, setHasTimeoutError] = useState(false);
45790
+ const hasInitialFetchRef = useRef(false);
45710
45791
  useEffect(() => {
45711
45792
  setThreadId(widget.id);
45712
45793
  }, [widget.id, setThreadId]);
@@ -45715,6 +45796,19 @@ function CopilotKitPieChart({
45715
45796
  initialState: createInitialChartState$3(datasetId, widget_data)
45716
45797
  });
45717
45798
  const [chartState, setChartState] = useState(createInitialChartState$3(datasetId, widget_data));
45799
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = useState(false);
45800
+ useEffect(() => {
45801
+ const fetchInitialState = async () => {
45802
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
45803
+ hasInitialFetchRef.current = true;
45804
+ const apiResponse = await loadSessionStateDirect$3(widgetBackendUrl, widget.id);
45805
+ if (apiResponse) {
45806
+ parseAndUpdateChartState$3(apiResponse, setChartState);
45807
+ }
45808
+ setIsInitialFetchComplete(true);
45809
+ };
45810
+ fetchInitialState();
45811
+ }, [widgetBackendUrl, widget.id, setChartState]);
45718
45812
  const handleLoadingTimeout = useCallback(async () => {
45719
45813
  var _a2;
45720
45814
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -45812,7 +45906,7 @@ function CopilotKitPieChart({
45812
45906
  /* @__PURE__ */ jsxRuntimeExports.jsx(Bot, { className: "h-4 w-4" }),
45813
45907
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
45814
45908
  ] }) }),
45815
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.pie_chart_data) == null ? void 0 : _f.data) == null ? void 0 : _g.labels) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.pie_chart_data) == null ? void 0 : _i.data) == null ? void 0 : _j.values) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
45909
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.pie_chart_data) == null ? void 0 : _f.data) == null ? void 0 : _g.labels) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.pie_chart_data) == null ? void 0 : _i.data) == null ? void 0 : _j.values) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
45816
45910
  PieChartComponent,
45817
45911
  {
45818
45912
  pieChartState: chartState,
@@ -45974,6 +46068,24 @@ const loadAgentState$2 = async (widgetBackendUrl, threadId, agentName) => {
45974
46068
  return null;
45975
46069
  }
45976
46070
  };
46071
+ const loadSessionStateDirect$2 = async (widgetBackendUrl, sessionId) => {
46072
+ try {
46073
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
46074
+ method: "GET",
46075
+ headers: {
46076
+ "Content-Type": "application/json"
46077
+ }
46078
+ });
46079
+ if (!response.ok) {
46080
+ throw new Error(`HTTP error! status: ${response.status}`);
46081
+ }
46082
+ const result = await response.json();
46083
+ return result;
46084
+ } catch (error) {
46085
+ console.error("Failed to load session state directly:", error);
46086
+ return null;
46087
+ }
46088
+ };
45977
46089
  const parseAndUpdateChartState$2 = (apiResponse, setChartState) => {
45978
46090
  var _a, _b;
45979
46091
  try {
@@ -46117,6 +46229,7 @@ function CopilotKitSeriesBarChart$1({
46117
46229
  const timeoutRef = useRef(null);
46118
46230
  const [apiCallCount, setApiCallCount] = useState(0);
46119
46231
  const [hasTimeoutError, setHasTimeoutError] = useState(false);
46232
+ const hasInitialFetchRef = useRef(false);
46120
46233
  useEffect(() => {
46121
46234
  setThreadId(widget.id);
46122
46235
  }, [widget.id, setThreadId]);
@@ -46125,6 +46238,19 @@ function CopilotKitSeriesBarChart$1({
46125
46238
  initialState: createInitialChartState$2(datasetId, widget_data)
46126
46239
  });
46127
46240
  const [chartState, setChartState] = useState(createInitialChartState$2(datasetId, widget_data));
46241
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = useState(false);
46242
+ useEffect(() => {
46243
+ const fetchInitialState = async () => {
46244
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
46245
+ hasInitialFetchRef.current = true;
46246
+ const apiResponse = await loadSessionStateDirect$2(widgetBackendUrl, widget.id);
46247
+ if (apiResponse) {
46248
+ parseAndUpdateChartState$2(apiResponse, setChartState);
46249
+ }
46250
+ setIsInitialFetchComplete(true);
46251
+ };
46252
+ fetchInitialState();
46253
+ }, [widgetBackendUrl, widget.id, setChartState]);
46128
46254
  const handleLoadingTimeout = useCallback(async () => {
46129
46255
  var _a2;
46130
46256
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -46222,7 +46348,7 @@ function CopilotKitSeriesBarChart$1({
46222
46348
  /* @__PURE__ */ jsxRuntimeExports.jsx(Bot, { className: "h-4 w-4" }),
46223
46349
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
46224
46350
  ] }) }),
46225
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46351
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46226
46352
  SeriesBarChartComponent$1,
46227
46353
  {
46228
46354
  orientation,
@@ -46385,6 +46511,24 @@ const loadAgentState$1 = async (widgetBackendUrl, threadId, agentName) => {
46385
46511
  return null;
46386
46512
  }
46387
46513
  };
46514
+ const loadSessionStateDirect$1 = async (widgetBackendUrl, sessionId) => {
46515
+ try {
46516
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
46517
+ method: "GET",
46518
+ headers: {
46519
+ "Content-Type": "application/json"
46520
+ }
46521
+ });
46522
+ if (!response.ok) {
46523
+ throw new Error(`HTTP error! status: ${response.status}`);
46524
+ }
46525
+ const result = await response.json();
46526
+ return result;
46527
+ } catch (error) {
46528
+ console.error("Failed to load session state directly:", error);
46529
+ return null;
46530
+ }
46531
+ };
46388
46532
  const parseAndUpdateChartState$1 = (apiResponse, setChartState) => {
46389
46533
  var _a, _b;
46390
46534
  try {
@@ -46528,6 +46672,7 @@ function CopilotKitSeriesBarChart({
46528
46672
  const timeoutRef = useRef(null);
46529
46673
  const [apiCallCount, setApiCallCount] = useState(0);
46530
46674
  const [hasTimeoutError, setHasTimeoutError] = useState(false);
46675
+ const hasInitialFetchRef = useRef(false);
46531
46676
  useEffect(() => {
46532
46677
  setThreadId(widget.id);
46533
46678
  }, [widget.id, setThreadId]);
@@ -46536,6 +46681,19 @@ function CopilotKitSeriesBarChart({
46536
46681
  initialState: createInitialChartState$1(datasetId, widget_data)
46537
46682
  });
46538
46683
  const [chartState, setChartState] = useState(createInitialChartState$1(datasetId, widget_data));
46684
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = useState(false);
46685
+ useEffect(() => {
46686
+ const fetchInitialState = async () => {
46687
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
46688
+ hasInitialFetchRef.current = true;
46689
+ const apiResponse = await loadSessionStateDirect$1(widgetBackendUrl, widget.id);
46690
+ if (apiResponse) {
46691
+ parseAndUpdateChartState$1(apiResponse, setChartState);
46692
+ }
46693
+ setIsInitialFetchComplete(true);
46694
+ };
46695
+ fetchInitialState();
46696
+ }, [widgetBackendUrl, widget.id, setChartState]);
46539
46697
  const handleLoadingTimeout = useCallback(async () => {
46540
46698
  var _a2;
46541
46699
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -46633,7 +46791,7 @@ function CopilotKitSeriesBarChart({
46633
46791
  /* @__PURE__ */ jsxRuntimeExports.jsx(Bot, { className: "h-4 w-4" }),
46634
46792
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
46635
46793
  ] }) }),
46636
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46794
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46637
46795
  SeriesBarChartComponent,
46638
46796
  {
46639
46797
  orientation,
@@ -46786,6 +46944,24 @@ const loadAgentState = async (widgetBackendUrl, threadId, agentName) => {
46786
46944
  return null;
46787
46945
  }
46788
46946
  };
46947
+ const loadSessionStateDirect = async (widgetBackendUrl, sessionId) => {
46948
+ try {
46949
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
46950
+ method: "GET",
46951
+ headers: {
46952
+ "Content-Type": "application/json"
46953
+ }
46954
+ });
46955
+ if (!response.ok) {
46956
+ throw new Error(`HTTP error! status: ${response.status}`);
46957
+ }
46958
+ const result = await response.json();
46959
+ return result;
46960
+ } catch (error) {
46961
+ console.error("Failed to load session state directly:", error);
46962
+ return null;
46963
+ }
46964
+ };
46789
46965
  const parseAndUpdateChartState = (apiResponse, setChartState) => {
46790
46966
  var _a, _b;
46791
46967
  try {
@@ -46910,6 +47086,7 @@ function CopilotKitDataGrid({
46910
47086
  const timeoutRef = useRef(null);
46911
47087
  const [apiCallCount, setApiCallCount] = useState(0);
46912
47088
  const [hasTimeoutError, setHasTimeoutError] = useState(false);
47089
+ const hasInitialFetchRef = useRef(false);
46913
47090
  useEffect(() => {
46914
47091
  setThreadId(widget.id);
46915
47092
  }, [widget.id, setThreadId]);
@@ -46918,6 +47095,19 @@ function CopilotKitDataGrid({
46918
47095
  initialState: createInitialChartState(datasetId, widget_data)
46919
47096
  });
46920
47097
  const [chartState, setChartState] = useState(createInitialChartState(datasetId, widget_data));
47098
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = useState(false);
47099
+ useEffect(() => {
47100
+ const fetchInitialState = async () => {
47101
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
47102
+ hasInitialFetchRef.current = true;
47103
+ const apiResponse = await loadSessionStateDirect(widgetBackendUrl, widget.id);
47104
+ if (apiResponse) {
47105
+ parseAndUpdateChartState(apiResponse, setChartState);
47106
+ }
47107
+ setIsInitialFetchComplete(true);
47108
+ };
47109
+ fetchInitialState();
47110
+ }, [widgetBackendUrl, widget.id, setChartState]);
46921
47111
  const handleLoadingTimeout = useCallback(async () => {
46922
47112
  var _a2;
46923
47113
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -47015,7 +47205,7 @@ function CopilotKitDataGrid({
47015
47205
  /* @__PURE__ */ jsxRuntimeExports.jsx(Bot, { className: "h-4 w-4" }),
47016
47206
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
47017
47207
  ] }) }),
47018
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.matrix_grid_data) == null ? void 0 : _f.data) == null ? void 0 : _g.headers) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.matrix_grid_data) == null ? void 0 : _i.data) == null ? void 0 : _j.rows) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
47208
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.matrix_grid_data) == null ? void 0 : _f.data) == null ? void 0 : _g.headers) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.matrix_grid_data) == null ? void 0 : _i.data) == null ? void 0 : _j.rows) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
47019
47209
  DataGridComponent,
47020
47210
  {
47021
47211
  dataGridState: chartState,
package/dist/index.js CHANGED
@@ -43634,6 +43634,24 @@ const loadAgentState$5 = async (widgetBackendUrl, threadId, agentName) => {
43634
43634
  return null;
43635
43635
  }
43636
43636
  };
43637
+ const loadSessionStateDirect$5 = async (widgetBackendUrl, sessionId) => {
43638
+ try {
43639
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
43640
+ method: "GET",
43641
+ headers: {
43642
+ "Content-Type": "application/json"
43643
+ }
43644
+ });
43645
+ if (!response.ok) {
43646
+ throw new Error(`HTTP error! status: ${response.status}`);
43647
+ }
43648
+ const result = await response.json();
43649
+ return result;
43650
+ } catch (error) {
43651
+ console.error("Failed to load session state directly:", error);
43652
+ return null;
43653
+ }
43654
+ };
43637
43655
  const parseAndUpdateChartState$4 = (apiResponse, setChartState) => {
43638
43656
  var _a, _b;
43639
43657
  try {
@@ -44168,6 +44186,8 @@ function CopilotKitAgent({
44168
44186
  const [isTimeoutTriggered, setIsTimeoutTriggered] = React.useState(false);
44169
44187
  const [apiCallCount, setApiCallCount] = React.useState(0);
44170
44188
  const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
44189
+ const hasInitialFetchRef = React.useRef(false);
44190
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = React.useState(false);
44171
44191
  React.useEffect(() => {
44172
44192
  setThreadId(widget.id);
44173
44193
  }, [widget.id, setThreadId]);
@@ -44175,6 +44195,18 @@ function CopilotKitAgent({
44175
44195
  name: (_e = widget.config) == null ? void 0 : _e.agentName,
44176
44196
  initialState: createInitialChartState$4(agentType || "", widgetIds, datasetId)
44177
44197
  });
44198
+ React.useEffect(() => {
44199
+ const fetchInitialState = async () => {
44200
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
44201
+ hasInitialFetchRef.current = true;
44202
+ const apiResponse = await loadSessionStateDirect$5(widgetBackendUrl, widget.id);
44203
+ if (apiResponse) {
44204
+ parseAndUpdateChartState$4(apiResponse, setChartState);
44205
+ }
44206
+ setIsInitialFetchComplete(true);
44207
+ };
44208
+ fetchInitialState();
44209
+ }, [widgetBackendUrl, widget.id, setChartState]);
44178
44210
  const handleLoadingTimeout = React.useCallback(async () => {
44179
44211
  var _a2;
44180
44212
  if (!widgetBackendUrl || !widget.id || isTimeoutTriggered || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) return;
@@ -44277,7 +44309,7 @@ function CopilotKitAgent({
44277
44309
  /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.Bot, { className: "h-4 w-4" }),
44278
44310
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
44279
44311
  ] }) }),
44280
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && agentType !== "chatbot" && // Check if data is empty based on agent type
44312
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && agentType !== "chatbot" && // Check if data is empty based on agent type
44281
44313
  (agentType === "Bar Chart Agent" && (!((_i = (_h = (_g = chartState.bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.values) == null ? void 0 : _l.length)) || agentType === "Series Bar Chart Agent" && (!((_o = (_n = (_m = chartState.series_bar_chart_data) == null ? void 0 : _m.data) == null ? void 0 : _n.labels) == null ? void 0 : _o.length) || !((_r = (_q = (_p = chartState.series_bar_chart_data) == null ? void 0 : _p.data) == null ? void 0 : _q.series) == null ? void 0 : _r.length)) || agentType === "Series Line Chart Agent" && (!((_u = (_t = (_s = chartState.series_bar_chart_data) == null ? void 0 : _s.data) == null ? void 0 : _t.labels) == null ? void 0 : _u.length) || !((_x = (_w = (_v = chartState.series_bar_chart_data) == null ? void 0 : _v.data) == null ? void 0 : _w.series) == null ? void 0 : _x.length)) || agentType === "Pie Chart Agent" && (!((_A = (_z = (_y = chartState.pie_chart_data) == null ? void 0 : _y.data) == null ? void 0 : _z.labels) == null ? void 0 : _A.length) || !((_D = (_C = (_B = chartState.pie_chart_data) == null ? void 0 : _B.data) == null ? void 0 : _C.values) == null ? void 0 : _D.length)) || agentType === "Line Chart Agent" && (!((_G = (_F = (_E = chartState.bar_chart_data) == null ? void 0 : _E.data) == null ? void 0 : _F.labels) == null ? void 0 : _G.length) || !((_J = (_I = (_H = chartState.bar_chart_data) == null ? void 0 : _H.data) == null ? void 0 : _I.values) == null ? void 0 : _J.length)) || agentType === "Data Grid Agent" && (!((_M = (_L = (_K = chartState.matrix_grid_data) == null ? void 0 : _K.data) == null ? void 0 : _L.headers) == null ? void 0 : _M.length) || !((_P = (_O = (_N = chartState.matrix_grid_data) == null ? void 0 : _N.data) == null ? void 0 : _O.rows) == null ? void 0 : _P.length)) || agentType === "Summary Agent" && (!((_R = (_Q = chartState.summary_data) == null ? void 0 : _Q.data) == null ? void 0 : _R.content) || ((_U = (_T = (_S = chartState.summary_data) == null ? void 0 : _S.data) == null ? void 0 : _T.content) == null ? void 0 : _U.trim()) === "")) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : agentType === "Bar Chart Agent" ? /* @__PURE__ */ jsxRuntimeExports.jsx(
44282
44314
  BarChartComponent,
44283
44315
  {
@@ -44801,6 +44833,24 @@ const loadAgentState$4 = async (widgetBackendUrl, threadId, agentName) => {
44801
44833
  return null;
44802
44834
  }
44803
44835
  };
44836
+ const loadSessionStateDirect$4 = async (widgetBackendUrl, sessionId) => {
44837
+ try {
44838
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
44839
+ method: "GET",
44840
+ headers: {
44841
+ "Content-Type": "application/json"
44842
+ }
44843
+ });
44844
+ if (!response.ok) {
44845
+ throw new Error(`HTTP error! status: ${response.status}`);
44846
+ }
44847
+ const result = await response.json();
44848
+ return result;
44849
+ } catch (error) {
44850
+ console.error("Failed to load session state directly:", error);
44851
+ return null;
44852
+ }
44853
+ };
44804
44854
  const parseAndUpdateFilterState = (apiResponse, setFilterState) => {
44805
44855
  var _a, _b;
44806
44856
  try {
@@ -45264,6 +45314,7 @@ function CopilotKitFilters({
45264
45314
  const timeoutRef = React.useRef(null);
45265
45315
  const [apiCallCount, setApiCallCount] = React.useState(0);
45266
45316
  const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
45317
+ const hasInitialFetchRef = React.useRef(false);
45267
45318
  React.useEffect(() => {
45268
45319
  setThreadId(widget.id);
45269
45320
  }, [widget.id, setThreadId]);
@@ -45272,6 +45323,17 @@ function CopilotKitFilters({
45272
45323
  initialState: createInitialFilterState(datasetId, widget_data)
45273
45324
  });
45274
45325
  const [filterState, setFilterState] = React.useState(createInitialFilterState(datasetId, widget_data));
45326
+ React.useEffect(() => {
45327
+ const fetchInitialState = async () => {
45328
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
45329
+ hasInitialFetchRef.current = true;
45330
+ const apiResponse = await loadSessionStateDirect$4(widgetBackendUrl, widget.id);
45331
+ if (apiResponse) {
45332
+ parseAndUpdateFilterState(apiResponse, setFilterState);
45333
+ }
45334
+ };
45335
+ fetchInitialState();
45336
+ }, [widgetBackendUrl, widget.id, setFilterState]);
45275
45337
  const handleLoadingTimeout = React.useCallback(async () => {
45276
45338
  var _a2;
45277
45339
  if (!widgetBackendUrl || !widget.id || (filterState == null ? void 0 : filterState.agent_message) || hasTimeoutError) {
@@ -45602,6 +45664,24 @@ const loadAgentState$3 = async (widgetBackendUrl, threadId, agentName) => {
45602
45664
  return null;
45603
45665
  }
45604
45666
  };
45667
+ const loadSessionStateDirect$3 = async (widgetBackendUrl, sessionId) => {
45668
+ try {
45669
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
45670
+ method: "GET",
45671
+ headers: {
45672
+ "Content-Type": "application/json"
45673
+ }
45674
+ });
45675
+ if (!response.ok) {
45676
+ throw new Error(`HTTP error! status: ${response.status}`);
45677
+ }
45678
+ const result = await response.json();
45679
+ return result;
45680
+ } catch (error) {
45681
+ console.error("Failed to load session state directly:", error);
45682
+ return null;
45683
+ }
45684
+ };
45605
45685
  const parseAndUpdateChartState$3 = (apiResponse, setChartState) => {
45606
45686
  var _a, _b;
45607
45687
  try {
@@ -45735,6 +45815,7 @@ function CopilotKitPieChart({
45735
45815
  const timeoutRef = React.useRef(null);
45736
45816
  const [apiCallCount, setApiCallCount] = React.useState(0);
45737
45817
  const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
45818
+ const hasInitialFetchRef = React.useRef(false);
45738
45819
  React.useEffect(() => {
45739
45820
  setThreadId(widget.id);
45740
45821
  }, [widget.id, setThreadId]);
@@ -45743,6 +45824,19 @@ function CopilotKitPieChart({
45743
45824
  initialState: createInitialChartState$3(datasetId, widget_data)
45744
45825
  });
45745
45826
  const [chartState, setChartState] = React.useState(createInitialChartState$3(datasetId, widget_data));
45827
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = React.useState(false);
45828
+ React.useEffect(() => {
45829
+ const fetchInitialState = async () => {
45830
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
45831
+ hasInitialFetchRef.current = true;
45832
+ const apiResponse = await loadSessionStateDirect$3(widgetBackendUrl, widget.id);
45833
+ if (apiResponse) {
45834
+ parseAndUpdateChartState$3(apiResponse, setChartState);
45835
+ }
45836
+ setIsInitialFetchComplete(true);
45837
+ };
45838
+ fetchInitialState();
45839
+ }, [widgetBackendUrl, widget.id, setChartState]);
45746
45840
  const handleLoadingTimeout = React.useCallback(async () => {
45747
45841
  var _a2;
45748
45842
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -45840,7 +45934,7 @@ function CopilotKitPieChart({
45840
45934
  /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.Bot, { className: "h-4 w-4" }),
45841
45935
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
45842
45936
  ] }) }),
45843
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.pie_chart_data) == null ? void 0 : _f.data) == null ? void 0 : _g.labels) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.pie_chart_data) == null ? void 0 : _i.data) == null ? void 0 : _j.values) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
45937
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.pie_chart_data) == null ? void 0 : _f.data) == null ? void 0 : _g.labels) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.pie_chart_data) == null ? void 0 : _i.data) == null ? void 0 : _j.values) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
45844
45938
  PieChartComponent,
45845
45939
  {
45846
45940
  pieChartState: chartState,
@@ -46002,6 +46096,24 @@ const loadAgentState$2 = async (widgetBackendUrl, threadId, agentName) => {
46002
46096
  return null;
46003
46097
  }
46004
46098
  };
46099
+ const loadSessionStateDirect$2 = async (widgetBackendUrl, sessionId) => {
46100
+ try {
46101
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
46102
+ method: "GET",
46103
+ headers: {
46104
+ "Content-Type": "application/json"
46105
+ }
46106
+ });
46107
+ if (!response.ok) {
46108
+ throw new Error(`HTTP error! status: ${response.status}`);
46109
+ }
46110
+ const result = await response.json();
46111
+ return result;
46112
+ } catch (error) {
46113
+ console.error("Failed to load session state directly:", error);
46114
+ return null;
46115
+ }
46116
+ };
46005
46117
  const parseAndUpdateChartState$2 = (apiResponse, setChartState) => {
46006
46118
  var _a, _b;
46007
46119
  try {
@@ -46145,6 +46257,7 @@ function CopilotKitSeriesBarChart$1({
46145
46257
  const timeoutRef = React.useRef(null);
46146
46258
  const [apiCallCount, setApiCallCount] = React.useState(0);
46147
46259
  const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
46260
+ const hasInitialFetchRef = React.useRef(false);
46148
46261
  React.useEffect(() => {
46149
46262
  setThreadId(widget.id);
46150
46263
  }, [widget.id, setThreadId]);
@@ -46153,6 +46266,19 @@ function CopilotKitSeriesBarChart$1({
46153
46266
  initialState: createInitialChartState$2(datasetId, widget_data)
46154
46267
  });
46155
46268
  const [chartState, setChartState] = React.useState(createInitialChartState$2(datasetId, widget_data));
46269
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = React.useState(false);
46270
+ React.useEffect(() => {
46271
+ const fetchInitialState = async () => {
46272
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
46273
+ hasInitialFetchRef.current = true;
46274
+ const apiResponse = await loadSessionStateDirect$2(widgetBackendUrl, widget.id);
46275
+ if (apiResponse) {
46276
+ parseAndUpdateChartState$2(apiResponse, setChartState);
46277
+ }
46278
+ setIsInitialFetchComplete(true);
46279
+ };
46280
+ fetchInitialState();
46281
+ }, [widgetBackendUrl, widget.id, setChartState]);
46156
46282
  const handleLoadingTimeout = React.useCallback(async () => {
46157
46283
  var _a2;
46158
46284
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -46250,7 +46376,7 @@ function CopilotKitSeriesBarChart$1({
46250
46376
  /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.Bot, { className: "h-4 w-4" }),
46251
46377
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
46252
46378
  ] }) }),
46253
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46379
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46254
46380
  SeriesBarChartComponent$1,
46255
46381
  {
46256
46382
  orientation,
@@ -46413,6 +46539,24 @@ const loadAgentState$1 = async (widgetBackendUrl, threadId, agentName) => {
46413
46539
  return null;
46414
46540
  }
46415
46541
  };
46542
+ const loadSessionStateDirect$1 = async (widgetBackendUrl, sessionId) => {
46543
+ try {
46544
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
46545
+ method: "GET",
46546
+ headers: {
46547
+ "Content-Type": "application/json"
46548
+ }
46549
+ });
46550
+ if (!response.ok) {
46551
+ throw new Error(`HTTP error! status: ${response.status}`);
46552
+ }
46553
+ const result = await response.json();
46554
+ return result;
46555
+ } catch (error) {
46556
+ console.error("Failed to load session state directly:", error);
46557
+ return null;
46558
+ }
46559
+ };
46416
46560
  const parseAndUpdateChartState$1 = (apiResponse, setChartState) => {
46417
46561
  var _a, _b;
46418
46562
  try {
@@ -46556,6 +46700,7 @@ function CopilotKitSeriesBarChart({
46556
46700
  const timeoutRef = React.useRef(null);
46557
46701
  const [apiCallCount, setApiCallCount] = React.useState(0);
46558
46702
  const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
46703
+ const hasInitialFetchRef = React.useRef(false);
46559
46704
  React.useEffect(() => {
46560
46705
  setThreadId(widget.id);
46561
46706
  }, [widget.id, setThreadId]);
@@ -46564,6 +46709,19 @@ function CopilotKitSeriesBarChart({
46564
46709
  initialState: createInitialChartState$1(datasetId, widget_data)
46565
46710
  });
46566
46711
  const [chartState, setChartState] = React.useState(createInitialChartState$1(datasetId, widget_data));
46712
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = React.useState(false);
46713
+ React.useEffect(() => {
46714
+ const fetchInitialState = async () => {
46715
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
46716
+ hasInitialFetchRef.current = true;
46717
+ const apiResponse = await loadSessionStateDirect$1(widgetBackendUrl, widget.id);
46718
+ if (apiResponse) {
46719
+ parseAndUpdateChartState$1(apiResponse, setChartState);
46720
+ }
46721
+ setIsInitialFetchComplete(true);
46722
+ };
46723
+ fetchInitialState();
46724
+ }, [widgetBackendUrl, widget.id, setChartState]);
46567
46725
  const handleLoadingTimeout = React.useCallback(async () => {
46568
46726
  var _a2;
46569
46727
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -46661,7 +46819,7 @@ function CopilotKitSeriesBarChart({
46661
46819
  /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.Bot, { className: "h-4 w-4" }),
46662
46820
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
46663
46821
  ] }) }),
46664
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46822
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_i = (_h = (_g = chartState.series_bar_chart_data) == null ? void 0 : _g.data) == null ? void 0 : _h.labels) == null ? void 0 : _i.length) || !((_l = (_k = (_j = chartState.series_bar_chart_data) == null ? void 0 : _j.data) == null ? void 0 : _k.series) == null ? void 0 : _l.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
46665
46823
  SeriesBarChartComponent,
46666
46824
  {
46667
46825
  orientation,
@@ -46814,6 +46972,24 @@ const loadAgentState = async (widgetBackendUrl, threadId, agentName) => {
46814
46972
  return null;
46815
46973
  }
46816
46974
  };
46975
+ const loadSessionStateDirect = async (widgetBackendUrl, sessionId) => {
46976
+ try {
46977
+ const response = await fetch(`${widgetBackendUrl}/api/session/${sessionId}/state`, {
46978
+ method: "GET",
46979
+ headers: {
46980
+ "Content-Type": "application/json"
46981
+ }
46982
+ });
46983
+ if (!response.ok) {
46984
+ throw new Error(`HTTP error! status: ${response.status}`);
46985
+ }
46986
+ const result = await response.json();
46987
+ return result;
46988
+ } catch (error) {
46989
+ console.error("Failed to load session state directly:", error);
46990
+ return null;
46991
+ }
46992
+ };
46817
46993
  const parseAndUpdateChartState = (apiResponse, setChartState) => {
46818
46994
  var _a, _b;
46819
46995
  try {
@@ -46938,6 +47114,7 @@ function CopilotKitDataGrid({
46938
47114
  const timeoutRef = React.useRef(null);
46939
47115
  const [apiCallCount, setApiCallCount] = React.useState(0);
46940
47116
  const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
47117
+ const hasInitialFetchRef = React.useRef(false);
46941
47118
  React.useEffect(() => {
46942
47119
  setThreadId(widget.id);
46943
47120
  }, [widget.id, setThreadId]);
@@ -46946,6 +47123,19 @@ function CopilotKitDataGrid({
46946
47123
  initialState: createInitialChartState(datasetId, widget_data)
46947
47124
  });
46948
47125
  const [chartState, setChartState] = React.useState(createInitialChartState(datasetId, widget_data));
47126
+ const [isInitialFetchComplete, setIsInitialFetchComplete] = React.useState(false);
47127
+ React.useEffect(() => {
47128
+ const fetchInitialState = async () => {
47129
+ if (!widgetBackendUrl || !widget.id || hasInitialFetchRef.current) return;
47130
+ hasInitialFetchRef.current = true;
47131
+ const apiResponse = await loadSessionStateDirect(widgetBackendUrl, widget.id);
47132
+ if (apiResponse) {
47133
+ parseAndUpdateChartState(apiResponse, setChartState);
47134
+ }
47135
+ setIsInitialFetchComplete(true);
47136
+ };
47137
+ fetchInitialState();
47138
+ }, [widgetBackendUrl, widget.id, setChartState]);
46949
47139
  const handleLoadingTimeout = React.useCallback(async () => {
46950
47140
  var _a2;
46951
47141
  if (!widgetBackendUrl || !widget.id || (chartState == null ? void 0 : chartState.agent_message) || hasTimeoutError) {
@@ -47043,7 +47233,7 @@ function CopilotKitDataGrid({
47043
47233
  /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.Bot, { className: "h-4 w-4" }),
47044
47234
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })
47045
47235
  ] }) }),
47046
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.matrix_grid_data) == null ? void 0 : _f.data) == null ? void 0 : _g.headers) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.matrix_grid_data) == null ? void 0 : _i.data) == null ? void 0 : _j.rows) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
47236
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: !isInitialFetchComplete && !isFirstLoad ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntimeExports.jsx(lucideReact.RefreshCw, { className: "h-6 w-6 animate-spin text-gray-400" }) }) : (chartState == null ? void 0 : chartState.agent_message) && (!((_h = (_g = (_f = chartState.matrix_grid_data) == null ? void 0 : _f.data) == null ? void 0 : _g.headers) == null ? void 0 : _h.length) || !((_k = (_j = (_i = chartState.matrix_grid_data) == null ? void 0 : _i.data) == null ? void 0 : _j.rows) == null ? void 0 : _k.length)) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
47047
47237
  DataGridComponent,
47048
47238
  {
47049
47239
  dataGridState: chartState,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dp-widgets-framework",
3
- "version": "1.6.6",
3
+ "version": "1.6.8",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"