dp-widgets-framework 1.1.2 → 1.1.3

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
@@ -36578,7 +36578,7 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
36578
36578
  return (jsxRuntimeExports.jsx(SummaryWidget, { title: title, data: data, metadata: metadata, className: "" }));
36579
36579
  }
36580
36580
  function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds, widgetBackendUrl, datasetId }) {
36581
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
36581
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32;
36582
36582
  const agentType = (_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentType;
36583
36583
  const orientation = (_b = widget.config) === null || _b === void 0 ? void 0 : _b.orientation;
36584
36584
  const isFirstLoad = (_c = widget.config) === null || _c === void 0 ? void 0 : _c.isFirstLoad;
@@ -36587,6 +36587,8 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36587
36587
  const [isTimeoutTriggered, setIsTimeoutTriggered] = useState(false);
36588
36588
  const [apiCallCount, setApiCallCount] = useState(0);
36589
36589
  const [hasTimeoutError, setHasTimeoutError] = useState(false);
36590
+ const [isAgentTriggered, setIsAgentTriggered] = useState(false);
36591
+ const pollingIntervalRef = useRef(null);
36590
36592
  useEffect(() => {
36591
36593
  setThreadId(widget.id);
36592
36594
  }, [widget.id, setThreadId]);
@@ -36633,6 +36635,58 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36633
36635
  timeoutRef.current = null;
36634
36636
  }
36635
36637
  }, []);
36638
+ // Function to start polling for data availability
36639
+ const startPollingForData = useCallback(() => {
36640
+ var _a;
36641
+ if (!widgetBackendUrl || !((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName))
36642
+ return;
36643
+ setIsAgentTriggered(true);
36644
+ setApiCallCount(0);
36645
+ setHasTimeoutError(false);
36646
+ // Clear any existing polling interval
36647
+ if (pollingIntervalRef.current) {
36648
+ clearInterval(pollingIntervalRef.current);
36649
+ }
36650
+ // Start polling immediately, then every CHART_REFRESH_TIMEOUT
36651
+ const pollForData = async () => {
36652
+ var _a, _b, _c;
36653
+ if (apiCallCount >= 10) {
36654
+ setHasTimeoutError(true);
36655
+ setIsAgentTriggered(false);
36656
+ if (pollingIntervalRef.current) {
36657
+ clearInterval(pollingIntervalRef.current);
36658
+ pollingIntervalRef.current = null;
36659
+ }
36660
+ return;
36661
+ }
36662
+ setApiCallCount(prev => prev + 1);
36663
+ const agentName = ((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName) || "adk-construction-project-agent";
36664
+ const apiResponse = await loadAgentState(widgetBackendUrl, widget.id, agentName);
36665
+ if (apiResponse && ((_c = (_b = apiResponse.data) === null || _b === void 0 ? void 0 : _b.loadAgentState) === null || _c === void 0 ? void 0 : _c.state)) {
36666
+ parseAndUpdateChartState(apiResponse, setChartState);
36667
+ setIsAgentTriggered(false);
36668
+ if (pollingIntervalRef.current) {
36669
+ clearInterval(pollingIntervalRef.current);
36670
+ pollingIntervalRef.current = null;
36671
+ }
36672
+ }
36673
+ };
36674
+ // Poll immediately
36675
+ pollForData();
36676
+ // Then poll every CHART_REFRESH_TIMEOUT
36677
+ pollingIntervalRef.current = setInterval(pollForData, CHART_REFRESH_TIMEOUT);
36678
+ // Set a maximum timeout to stop polling after 10 attempts
36679
+ setTimeout(() => {
36680
+ if (pollingIntervalRef.current) {
36681
+ clearInterval(pollingIntervalRef.current);
36682
+ pollingIntervalRef.current = null;
36683
+ setIsAgentTriggered(false);
36684
+ if (apiCallCount >= 10) {
36685
+ setHasTimeoutError(true);
36686
+ }
36687
+ }
36688
+ }, CHART_REFRESH_TIMEOUT * 10);
36689
+ }, [widgetBackendUrl, (_f = widget.config) === null || _f === void 0 ? void 0 : _f.agentName, widget.id, apiCallCount, setChartState]);
36636
36690
  // Function to clear chat and reset chart state
36637
36691
  useCallback(async (widgetId) => {
36638
36692
  if (!widgetBackendUrl)
@@ -36656,15 +36710,23 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36656
36710
  console.error('Failed to clear chat and state:', error);
36657
36711
  }
36658
36712
  }, [widgetBackendUrl, setChartState, agentType, widgetIds]);
36659
- // Clean up timeout on unmount
36713
+ // Clean up timeout and polling on unmount
36660
36714
  useEffect(() => {
36661
36715
  return () => {
36662
36716
  if (timeoutRef.current) {
36663
36717
  clearTimeout(timeoutRef.current);
36664
36718
  }
36719
+ if (pollingIntervalRef.current) {
36720
+ clearInterval(pollingIntervalRef.current);
36721
+ }
36665
36722
  };
36666
36723
  }, []);
36667
- const { appendMessage, reset } = useCopilotChat();
36724
+ const { appendMessage: originalAppendMessage, reset } = useCopilotChat();
36725
+ // Wrapper function for appendMessage that triggers polling
36726
+ const appendMessage = useCallback((message) => {
36727
+ startPollingForData();
36728
+ return originalAppendMessage(message);
36729
+ }, [originalAppendMessage, startPollingForData]);
36668
36730
  // Register the reset function with the parent component
36669
36731
  useEffect(() => {
36670
36732
  if (onResetReady && reset && widget.id) {
@@ -36726,17 +36788,18 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36726
36788
  }, [widget.id, appendMessage, agentType, setChartState]);
36727
36789
  return (jsxRuntimeExports.jsxs("div", { className: cn("flex flex-col h-full"), children: [showHeader && (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-between pb-2 border-b", children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(Bot, { className: "h-4 w-4" }), jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })] }) })), jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState === null || chartState === void 0 ? void 0 : chartState.agent_message) && agentType !== "chatbot" && (
36728
36790
  // Check if data is empty based on agent type
36729
- (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))) ||
36730
- (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))) ||
36731
- (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))) ||
36732
- (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))) ||
36733
- (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))) ||
36734
- (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))) ||
36735
- (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: {
36736
- title: ((_29 = widget.config) === null || _29 === void 0 ? void 0 : _29.copilotTitle) || widget.title,
36737
- initial: ((_30 = widget.config) === null || _30 === void 0 ? void 0 : _30.copilotInitialMessage) || ((_31 = widget.config) === null || _31 === void 0 ? void 0 : _31.placeholder) || "How can I help you today?"
36791
+ (agentType === "Bar Chart Agent" && (!((_j = (_h = (_g = chartState.bar_chart_data) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.labels) === null || _j === void 0 ? void 0 : _j.length) || !((_m = (_l = (_k = chartState.bar_chart_data) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.values) === null || _m === void 0 ? void 0 : _m.length))) ||
36792
+ (agentType === "Series Bar Chart Agent" && (!((_q = (_p = (_o = chartState.series_bar_chart_data) === null || _o === void 0 ? void 0 : _o.data) === null || _p === void 0 ? void 0 : _p.labels) === null || _q === void 0 ? void 0 : _q.length) || !((_t = (_s = (_r = chartState.series_bar_chart_data) === null || _r === void 0 ? void 0 : _r.data) === null || _s === void 0 ? void 0 : _s.series) === null || _t === void 0 ? void 0 : _t.length))) ||
36793
+ (agentType === "Series Line Chart Agent" && (!((_w = (_v = (_u = chartState.series_bar_chart_data) === null || _u === void 0 ? void 0 : _u.data) === null || _v === void 0 ? void 0 : _v.labels) === null || _w === void 0 ? void 0 : _w.length) || !((_z = (_y = (_x = chartState.series_bar_chart_data) === null || _x === void 0 ? void 0 : _x.data) === null || _y === void 0 ? void 0 : _y.series) === null || _z === void 0 ? void 0 : _z.length))) ||
36794
+ (agentType === "Pie Chart Agent" && (!((_2 = (_1 = (_0 = chartState.pie_chart_data) === null || _0 === void 0 ? void 0 : _0.data) === null || _1 === void 0 ? void 0 : _1.labels) === null || _2 === void 0 ? void 0 : _2.length) || !((_5 = (_4 = (_3 = chartState.pie_chart_data) === null || _3 === void 0 ? void 0 : _3.data) === null || _4 === void 0 ? void 0 : _4.values) === null || _5 === void 0 ? void 0 : _5.length))) ||
36795
+ (agentType === "Line Chart Agent" && (!((_8 = (_7 = (_6 = chartState.bar_chart_data) === null || _6 === void 0 ? void 0 : _6.data) === null || _7 === void 0 ? void 0 : _7.labels) === null || _8 === void 0 ? void 0 : _8.length) || !((_11 = (_10 = (_9 = chartState.bar_chart_data) === null || _9 === void 0 ? void 0 : _9.data) === null || _10 === void 0 ? void 0 : _10.values) === null || _11 === void 0 ? void 0 : _11.length))) ||
36796
+ (agentType === "Data Grid Agent" && (!((_14 = (_13 = (_12 = chartState.matrix_grid_data) === null || _12 === void 0 ? void 0 : _12.data) === null || _13 === void 0 ? void 0 : _13.headers) === null || _14 === void 0 ? void 0 : _14.length) || !((_17 = (_16 = (_15 = chartState.matrix_grid_data) === null || _15 === void 0 ? void 0 : _15.data) === null || _16 === void 0 ? void 0 : _16.rows) === null || _17 === void 0 ? void 0 : _17.length))) ||
36797
+ (agentType === "Summary Agent" && (!((_19 = (_18 = chartState.summary_data) === null || _18 === void 0 ? void 0 : _18.data) === null || _19 === void 0 ? void 0 : _19.content) || ((_22 = (_21 = (_20 = chartState.summary_data) === null || _20 === void 0 ? void 0 : _20.data) === null || _21 === void 0 ? void 0 : _21.content) === null || _22 === void 0 ? void 0 : _22.trim()) === ""))) ? (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) })) : isAgentTriggered ? (createLoadingComponent("Agent processing your request...")) : agentType === "Bar Chart Agent" ? (jsxRuntimeExports.jsx(BarChartComponent, { barChartState: 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 Bar Chart Agent" ? (jsxRuntimeExports.jsx(SeriesBarChartComponent, { seriesBarChartState: 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 === "Series Line Chart Agent" ? (jsxRuntimeExports.jsx(SeriesLineChartComponent, { seriesLineChartState: chartState, styles: styles, orientation: orientation, 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 === "Pie Chart Agent" ? (jsxRuntimeExports.jsx(PieChartComponent, { pieChartState: 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 === "Line Chart Agent" ? (jsxRuntimeExports.jsx(LineChartComponent, { lineChartState: 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 === "Data Grid Agent" ? (jsxRuntimeExports.jsx(DataGridComponent, { dataGridState: chartState, styles: styles, appendMessage: appendMessage, query: (_28 = widget.config) === null || _28 === void 0 ? void 0 : _28.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: (_29 = widget.config) === null || _29 === void 0 ? void 0 : _29.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: {
36798
+ title: ((_30 = widget.config) === null || _30 === void 0 ? void 0 : _30.copilotTitle) || widget.title,
36799
+ initial: ((_31 = widget.config) === null || _31 === void 0 ? void 0 : _31.copilotInitialMessage) || ((_32 = widget.config) === null || _32 === void 0 ? void 0 : _32.placeholder) || "How can I help you today?"
36738
36800
  }, onSubmitMessage: () => {
36739
36801
  setChartState(prevState => (Object.assign(Object.assign({}, prevState), { widget_ids: widgetIds, dataset_id: datasetId })));
36802
+ startPollingForData();
36740
36803
  } })) })] }));
36741
36804
  }
36742
36805
  function AgentWidget({ widget, showHeader = true, widgetBackendUrl, onResetReady, widgetIds, datasetId, }) {
package/dist/index.js CHANGED
@@ -36605,7 +36605,7 @@ function SummaryComponent({ summaryState, styles, appendMessage, query, isFirstL
36605
36605
  return (jsxRuntimeExports.jsx(SummaryWidget, { title: title, data: data, metadata: metadata, className: "" }));
36606
36606
  }
36607
36607
  function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds, widgetBackendUrl, datasetId }) {
36608
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
36608
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32;
36609
36609
  const agentType = (_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentType;
36610
36610
  const orientation = (_b = widget.config) === null || _b === void 0 ? void 0 : _b.orientation;
36611
36611
  const isFirstLoad = (_c = widget.config) === null || _c === void 0 ? void 0 : _c.isFirstLoad;
@@ -36614,6 +36614,8 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36614
36614
  const [isTimeoutTriggered, setIsTimeoutTriggered] = React.useState(false);
36615
36615
  const [apiCallCount, setApiCallCount] = React.useState(0);
36616
36616
  const [hasTimeoutError, setHasTimeoutError] = React.useState(false);
36617
+ const [isAgentTriggered, setIsAgentTriggered] = React.useState(false);
36618
+ const pollingIntervalRef = React.useRef(null);
36617
36619
  React.useEffect(() => {
36618
36620
  setThreadId(widget.id);
36619
36621
  }, [widget.id, setThreadId]);
@@ -36660,6 +36662,58 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36660
36662
  timeoutRef.current = null;
36661
36663
  }
36662
36664
  }, []);
36665
+ // Function to start polling for data availability
36666
+ const startPollingForData = React.useCallback(() => {
36667
+ var _a;
36668
+ if (!widgetBackendUrl || !((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName))
36669
+ return;
36670
+ setIsAgentTriggered(true);
36671
+ setApiCallCount(0);
36672
+ setHasTimeoutError(false);
36673
+ // Clear any existing polling interval
36674
+ if (pollingIntervalRef.current) {
36675
+ clearInterval(pollingIntervalRef.current);
36676
+ }
36677
+ // Start polling immediately, then every CHART_REFRESH_TIMEOUT
36678
+ const pollForData = async () => {
36679
+ var _a, _b, _c;
36680
+ if (apiCallCount >= 10) {
36681
+ setHasTimeoutError(true);
36682
+ setIsAgentTriggered(false);
36683
+ if (pollingIntervalRef.current) {
36684
+ clearInterval(pollingIntervalRef.current);
36685
+ pollingIntervalRef.current = null;
36686
+ }
36687
+ return;
36688
+ }
36689
+ setApiCallCount(prev => prev + 1);
36690
+ const agentName = ((_a = widget.config) === null || _a === void 0 ? void 0 : _a.agentName) || "adk-construction-project-agent";
36691
+ const apiResponse = await loadAgentState(widgetBackendUrl, widget.id, agentName);
36692
+ if (apiResponse && ((_c = (_b = apiResponse.data) === null || _b === void 0 ? void 0 : _b.loadAgentState) === null || _c === void 0 ? void 0 : _c.state)) {
36693
+ parseAndUpdateChartState(apiResponse, setChartState);
36694
+ setIsAgentTriggered(false);
36695
+ if (pollingIntervalRef.current) {
36696
+ clearInterval(pollingIntervalRef.current);
36697
+ pollingIntervalRef.current = null;
36698
+ }
36699
+ }
36700
+ };
36701
+ // Poll immediately
36702
+ pollForData();
36703
+ // Then poll every CHART_REFRESH_TIMEOUT
36704
+ pollingIntervalRef.current = setInterval(pollForData, CHART_REFRESH_TIMEOUT);
36705
+ // Set a maximum timeout to stop polling after 10 attempts
36706
+ setTimeout(() => {
36707
+ if (pollingIntervalRef.current) {
36708
+ clearInterval(pollingIntervalRef.current);
36709
+ pollingIntervalRef.current = null;
36710
+ setIsAgentTriggered(false);
36711
+ if (apiCallCount >= 10) {
36712
+ setHasTimeoutError(true);
36713
+ }
36714
+ }
36715
+ }, CHART_REFRESH_TIMEOUT * 10);
36716
+ }, [widgetBackendUrl, (_f = widget.config) === null || _f === void 0 ? void 0 : _f.agentName, widget.id, apiCallCount, setChartState]);
36663
36717
  // Function to clear chat and reset chart state
36664
36718
  React.useCallback(async (widgetId) => {
36665
36719
  if (!widgetBackendUrl)
@@ -36683,15 +36737,23 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36683
36737
  console.error('Failed to clear chat and state:', error);
36684
36738
  }
36685
36739
  }, [widgetBackendUrl, setChartState, agentType, widgetIds]);
36686
- // Clean up timeout on unmount
36740
+ // Clean up timeout and polling on unmount
36687
36741
  React.useEffect(() => {
36688
36742
  return () => {
36689
36743
  if (timeoutRef.current) {
36690
36744
  clearTimeout(timeoutRef.current);
36691
36745
  }
36746
+ if (pollingIntervalRef.current) {
36747
+ clearInterval(pollingIntervalRef.current);
36748
+ }
36692
36749
  };
36693
36750
  }, []);
36694
- const { appendMessage, reset } = reactCore.useCopilotChat();
36751
+ const { appendMessage: originalAppendMessage, reset } = reactCore.useCopilotChat();
36752
+ // Wrapper function for appendMessage that triggers polling
36753
+ const appendMessage = React.useCallback((message) => {
36754
+ startPollingForData();
36755
+ return originalAppendMessage(message);
36756
+ }, [originalAppendMessage, startPollingForData]);
36695
36757
  // Register the reset function with the parent component
36696
36758
  React.useEffect(() => {
36697
36759
  if (onResetReady && reset && widget.id) {
@@ -36753,17 +36815,18 @@ function CopilotKitAgent({ widget, showHeader, styles, onResetReady, widgetIds,
36753
36815
  }, [widget.id, appendMessage, agentType, setChartState]);
36754
36816
  return (jsxRuntimeExports.jsxs("div", { className: cn("flex flex-col h-full"), children: [showHeader && (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-between pb-2 border-b", children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.Bot, { className: "h-4 w-4" }), jsxRuntimeExports.jsx("h3", { className: "text-sm font-medium", children: widget.title })] }) })), jsxRuntimeExports.jsx("div", { className: "flex-1 h-full", children: (chartState === null || chartState === void 0 ? void 0 : chartState.agent_message) && agentType !== "chatbot" && (
36755
36817
  // Check if data is empty based on agent type
36756
- (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))) ||
36757
- (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))) ||
36758
- (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))) ||
36759
- (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))) ||
36760
- (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))) ||
36761
- (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))) ||
36762
- (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(reactUi.CopilotChat, { className: "h-full text-xs [&_.copilot-chat-message]:text-xs [&_.copilot-chat-input]:text-xs", labels: {
36763
- title: ((_29 = widget.config) === null || _29 === void 0 ? void 0 : _29.copilotTitle) || widget.title,
36764
- initial: ((_30 = widget.config) === null || _30 === void 0 ? void 0 : _30.copilotInitialMessage) || ((_31 = widget.config) === null || _31 === void 0 ? void 0 : _31.placeholder) || "How can I help you today?"
36818
+ (agentType === "Bar Chart Agent" && (!((_j = (_h = (_g = chartState.bar_chart_data) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.labels) === null || _j === void 0 ? void 0 : _j.length) || !((_m = (_l = (_k = chartState.bar_chart_data) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.values) === null || _m === void 0 ? void 0 : _m.length))) ||
36819
+ (agentType === "Series Bar Chart Agent" && (!((_q = (_p = (_o = chartState.series_bar_chart_data) === null || _o === void 0 ? void 0 : _o.data) === null || _p === void 0 ? void 0 : _p.labels) === null || _q === void 0 ? void 0 : _q.length) || !((_t = (_s = (_r = chartState.series_bar_chart_data) === null || _r === void 0 ? void 0 : _r.data) === null || _s === void 0 ? void 0 : _s.series) === null || _t === void 0 ? void 0 : _t.length))) ||
36820
+ (agentType === "Series Line Chart Agent" && (!((_w = (_v = (_u = chartState.series_bar_chart_data) === null || _u === void 0 ? void 0 : _u.data) === null || _v === void 0 ? void 0 : _v.labels) === null || _w === void 0 ? void 0 : _w.length) || !((_z = (_y = (_x = chartState.series_bar_chart_data) === null || _x === void 0 ? void 0 : _x.data) === null || _y === void 0 ? void 0 : _y.series) === null || _z === void 0 ? void 0 : _z.length))) ||
36821
+ (agentType === "Pie Chart Agent" && (!((_2 = (_1 = (_0 = chartState.pie_chart_data) === null || _0 === void 0 ? void 0 : _0.data) === null || _1 === void 0 ? void 0 : _1.labels) === null || _2 === void 0 ? void 0 : _2.length) || !((_5 = (_4 = (_3 = chartState.pie_chart_data) === null || _3 === void 0 ? void 0 : _3.data) === null || _4 === void 0 ? void 0 : _4.values) === null || _5 === void 0 ? void 0 : _5.length))) ||
36822
+ (agentType === "Line Chart Agent" && (!((_8 = (_7 = (_6 = chartState.bar_chart_data) === null || _6 === void 0 ? void 0 : _6.data) === null || _7 === void 0 ? void 0 : _7.labels) === null || _8 === void 0 ? void 0 : _8.length) || !((_11 = (_10 = (_9 = chartState.bar_chart_data) === null || _9 === void 0 ? void 0 : _9.data) === null || _10 === void 0 ? void 0 : _10.values) === null || _11 === void 0 ? void 0 : _11.length))) ||
36823
+ (agentType === "Data Grid Agent" && (!((_14 = (_13 = (_12 = chartState.matrix_grid_data) === null || _12 === void 0 ? void 0 : _12.data) === null || _13 === void 0 ? void 0 : _13.headers) === null || _14 === void 0 ? void 0 : _14.length) || !((_17 = (_16 = (_15 = chartState.matrix_grid_data) === null || _15 === void 0 ? void 0 : _15.data) === null || _16 === void 0 ? void 0 : _16.rows) === null || _17 === void 0 ? void 0 : _17.length))) ||
36824
+ (agentType === "Summary Agent" && (!((_19 = (_18 = chartState.summary_data) === null || _18 === void 0 ? void 0 : _18.data) === null || _19 === void 0 ? void 0 : _19.content) || ((_22 = (_21 = (_20 = chartState.summary_data) === null || _20 === void 0 ? void 0 : _20.data) === null || _21 === void 0 ? void 0 : _21.content) === null || _22 === void 0 ? void 0 : _22.trim()) === ""))) ? (jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-full p-4", children: jsxRuntimeExports.jsx("div", { className: "text-center max-w-md", children: jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700", children: chartState.agent_message }) }) })) : isAgentTriggered ? (createLoadingComponent("Agent processing your request...")) : agentType === "Bar Chart Agent" ? (jsxRuntimeExports.jsx(BarChartComponent, { barChartState: 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 Bar Chart Agent" ? (jsxRuntimeExports.jsx(SeriesBarChartComponent, { seriesBarChartState: 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 === "Series Line Chart Agent" ? (jsxRuntimeExports.jsx(SeriesLineChartComponent, { seriesLineChartState: chartState, styles: styles, orientation: orientation, 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 === "Pie Chart Agent" ? (jsxRuntimeExports.jsx(PieChartComponent, { pieChartState: 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 === "Line Chart Agent" ? (jsxRuntimeExports.jsx(LineChartComponent, { lineChartState: 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 === "Data Grid Agent" ? (jsxRuntimeExports.jsx(DataGridComponent, { dataGridState: chartState, styles: styles, appendMessage: appendMessage, query: (_28 = widget.config) === null || _28 === void 0 ? void 0 : _28.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: (_29 = widget.config) === null || _29 === void 0 ? void 0 : _29.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, widget_ids: widgetIds, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout, setChartState: setChartState })) : (jsxRuntimeExports.jsx(reactUi.CopilotChat, { className: "h-full text-xs [&_.copilot-chat-message]:text-xs [&_.copilot-chat-input]:text-xs", labels: {
36825
+ title: ((_30 = widget.config) === null || _30 === void 0 ? void 0 : _30.copilotTitle) || widget.title,
36826
+ initial: ((_31 = widget.config) === null || _31 === void 0 ? void 0 : _31.copilotInitialMessage) || ((_32 = widget.config) === null || _32 === void 0 ? void 0 : _32.placeholder) || "How can I help you today?"
36765
36827
  }, onSubmitMessage: () => {
36766
36828
  setChartState(prevState => (Object.assign(Object.assign({}, prevState), { widget_ids: widgetIds, dataset_id: datasetId })));
36829
+ startPollingForData();
36767
36830
  } })) })] }));
36768
36831
  }
36769
36832
  function AgentWidget({ widget, showHeader = true, widgetBackendUrl, onResetReady, widgetIds, datasetId, }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dp-widgets-framework",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"