dp-widgets-framework 1.5.5 → 1.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -39327,6 +39327,23 @@ const parseAndUpdateFilterState = (apiResponse, setFilterState) => {
39327
39327
  if (filterData.agent_message) {
39328
39328
  newFilterState.agent_message = filterData.agent_message;
39329
39329
  }
39330
+ // Handle confirmation state
39331
+ if (filterData.status) {
39332
+ newFilterState.status = filterData.status;
39333
+ }
39334
+ if (filterData.ambiguous_columns) {
39335
+ newFilterState.ambiguous_columns = filterData.ambiguous_columns;
39336
+ }
39337
+ if (filterData.message) {
39338
+ newFilterState.message = filterData.message;
39339
+ }
39340
+ if (filterData.filter_columns) {
39341
+ newFilterState.filter_columns = filterData.filter_columns;
39342
+ }
39343
+ if (filterData.resolved_columns) {
39344
+ newFilterState.resolved_columns = filterData.resolved_columns;
39345
+ }
39346
+ console.log('[parseAndUpdateFilterState] Updated filter state:', newFilterState);
39330
39347
  return newFilterState;
39331
39348
  });
39332
39349
  }
@@ -39350,6 +39367,25 @@ const convertFilterStateToGroups = (filterState) => {
39350
39367
  })),
39351
39368
  }));
39352
39369
  };
39370
+ // Component for handling table selection confirmation
39371
+ function TableSelectionConfirmation({ ambiguousColumns, resolvedColumns, message, onConfirm, onCancel, }) {
39372
+ const [selectedTables, setSelectedTables] = useState({});
39373
+ useEffect(() => {
39374
+ // Initialize with first option for each column
39375
+ const initial = {};
39376
+ ambiguousColumns.forEach((col) => {
39377
+ initial[col.column] = col.tables[0];
39378
+ });
39379
+ setSelectedTables(initial);
39380
+ }, [ambiguousColumns]);
39381
+ const handleSubmit = () => {
39382
+ onConfirm(selectedTables);
39383
+ };
39384
+ const allSelected = ambiguousColumns.every((col) => selectedTables[col.column]);
39385
+ return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col h-full p-4 bg-white", children: [jsxRuntimeExports.jsxs("div", { className: "mb-4", children: [jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-800 mb-2", children: "Table Selection Required" }), message && (jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 mb-4 whitespace-pre-line", children: message }))] }), resolvedColumns && resolvedColumns.length > 0 && (jsxRuntimeExports.jsxs("div", { className: "mb-4 p-3 bg-green-50 border border-green-200 rounded-lg", children: [jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-green-800 mb-2", children: "Already Resolved Columns:" }), jsxRuntimeExports.jsx("div", { className: "space-y-1", children: resolvedColumns.map((col) => (jsxRuntimeExports.jsxs("div", { className: "text-sm text-green-700", children: [jsxRuntimeExports.jsx("span", { className: "font-medium", children: col.column }), " \u2192 ", jsxRuntimeExports.jsx("span", { className: "text-green-600", children: col.table_name })] }, col.column))) })] })), jsxRuntimeExports.jsx(ScrollArea, { className: "flex-1 mb-4", children: jsxRuntimeExports.jsx("div", { className: "space-y-4", children: ambiguousColumns.map((col) => (jsxRuntimeExports.jsxs("div", { className: "border border-gray-200 rounded-lg p-3", children: [jsxRuntimeExports.jsx("label", { className: "block mb-2", children: jsxRuntimeExports.jsxs("span", { className: "text-sm font-medium text-gray-700", children: ["Column: ", jsxRuntimeExports.jsx("span", { className: "text-primary-600", children: col.column })] }) }), jsxRuntimeExports.jsxs("select", { value: selectedTables[col.column] || '', onChange: (e) => {
39386
+ setSelectedTables((prev) => (Object.assign(Object.assign({}, prev), { [col.column]: e.target.value })));
39387
+ }, className: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary-500", children: [jsxRuntimeExports.jsx("option", { value: "", children: "Select a table..." }), col.tables.map((table) => (jsxRuntimeExports.jsx("option", { value: table, children: table }, table)))] })] }, col.column))) }) }), jsxRuntimeExports.jsxs("div", { className: "flex gap-2 pt-3 border-t border-gray-200", children: [jsxRuntimeExports.jsx(Button, { onClick: onCancel, variant: "outline", className: "flex-1", children: "Cancel" }), jsxRuntimeExports.jsx(Button, { onClick: handleSubmit, disabled: !allSelected, className: "flex-1 bg-primary-600 hover:bg-primary-700 text-white disabled:bg-gray-400", children: "Confirm Selection" })] })] }));
39388
+ }
39353
39389
  function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout, filterState, onApplyFilters, isEditing = false, }) {
39354
39390
  const hasCalledRef = useRef(false);
39355
39391
  const [expandedGroups, setExpandedGroups] = useState({});
@@ -39458,20 +39494,18 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
39458
39494
  }, className: "py-1.5 text-sm font-medium text-primary-600 hover:text-primary-800 hover:bg-primary-50 rounded-md transition-colors px-2", children: "Clear All Filters" })) : (jsxRuntimeExports.jsx("div", {})), jsxRuntimeExports.jsx(Button, { onClick: () => {
39459
39495
  // Convert option IDs back to original label values
39460
39496
  const filtersWithLabels = {};
39461
- Object.entries(selectedFilters).forEach(([groupId, optionIds]) => {
39462
- const group = filterGroups.find(g => g.id === groupId);
39463
- if (group) {
39464
- filtersWithLabels[groupId] = optionIds.map(optionId => {
39465
- const option = group.options.find(opt => opt.id === optionId);
39466
- return (option === null || option === void 0 ? void 0 : option.label) || optionId;
39467
- });
39468
- }
39497
+ filterGroups.forEach((group) => {
39498
+ const optionIds = selectedFilters[group.id] || [];
39499
+ filtersWithLabels[group.id] = optionIds.map(optionId => {
39500
+ const option = group.options.find(opt => opt.id === optionId);
39501
+ return (option === null || option === void 0 ? void 0 : option.label) || optionId;
39502
+ });
39469
39503
  });
39470
39504
  onApplyFilters === null || onApplyFilters === void 0 ? void 0 : onApplyFilters(filtersWithLabels);
39471
39505
  }, disabled: isEditing, className: `${isEditing ? 'bg-gray-400 cursor-not-allowed' : 'bg-primary-600 hover:bg-primary-700'} text-white`, title: isEditing ? 'Save the layout first to apply filters' : '', children: "Apply Filters" })] }) })] }));
39472
39506
  }
39473
39507
  function CopilotKitFilters({ widget, showHeader, onFilterChange, onResetReady, widgetBackendUrl, datasetId, onApplyFilters, isEditing = false, }) {
39474
- var _a, _b, _c, _d, _e, _f;
39508
+ var _a, _b, _c, _d, _e, _f, _g, _h;
39475
39509
  const isFirstLoad = (_a = widget.config) === null || _a === void 0 ? void 0 : _a.isFirstLoad;
39476
39510
  const widget_data = (_b = widget.widget_data) === null || _b === void 0 ? void 0 : _b.column_values;
39477
39511
  const { setThreadId } = useCopilotContext();
@@ -39575,11 +39609,94 @@ function CopilotKitFilters({ widget, showHeader, onFilterChange, onResetReady, w
39575
39609
  window.removeEventListener('clearFilterState', handleClearFilterState);
39576
39610
  };
39577
39611
  }, [widget.id, appendMessage, setFilterState, startLoadingTimeout]);
39612
+ // Handle confirmation submission
39613
+ const handleConfirmation = useCallback(async (tableMapping) => {
39614
+ var _a, _b, _c;
39615
+ console.log('[FiltersWidget] handleConfirmation called with:', {
39616
+ tableMapping,
39617
+ currentFilterState: filterState,
39618
+ widgetQuery: (_a = widget.config) === null || _a === void 0 ? void 0 : _a.query
39619
+ });
39620
+ // Format table mapping as a JSON string for the agent
39621
+ const tableMappingJson = JSON.stringify(tableMapping);
39622
+ // Get filter columns - try multiple sources
39623
+ let filterColumns = filterState.filter_columns || '';
39624
+ // Fallback: extract from the original query if not in state
39625
+ if (!filterColumns && ((_b = widget.config) === null || _b === void 0 ? void 0 : _b.query)) {
39626
+ const filterColumnsMatch = widget.config.query.match(/(?:filter by|filter)\s+(.+)/i);
39627
+ filterColumns = filterColumnsMatch ? filterColumnsMatch[1].trim() : '';
39628
+ }
39629
+ // Fallback: extract from ambiguous_columns if available
39630
+ if (!filterColumns && filterState.ambiguous_columns) {
39631
+ filterColumns = filterState.ambiguous_columns.map(col => col.column).join(',');
39632
+ }
39633
+ if (!filterColumns) {
39634
+ console.error('[FiltersWidget] No filter_columns found in state, query, or ambiguous_columns', {
39635
+ filterState,
39636
+ query: (_c = widget.config) === null || _c === void 0 ? void 0 : _c.query
39637
+ });
39638
+ return;
39639
+ }
39640
+ console.log('[FiltersWidget] Using filter columns:', filterColumns);
39641
+ // Send a very explicit message for the agent to parse
39642
+ const message = `User confirmed table selection. Call get_tables_columns_values with filter_columns="${filterColumns}" and table_mapping='${tableMappingJson}'`;
39643
+ console.log('[FiltersWidget] Sending table mapping confirmation:', {
39644
+ message,
39645
+ tableMapping,
39646
+ filterColumns,
39647
+ tableMappingJson
39648
+ });
39649
+ // Clear the confirmation state completely, including agent_message
39650
+ const newState = {
39651
+ dashboard_id: datasetId || "",
39652
+ status: undefined, // Don't set to 'processing' as it might block polling
39653
+ ambiguous_columns: undefined,
39654
+ message: undefined,
39655
+ agent_message: undefined, // Clear agent_message to allow polling
39656
+ column_values: [], // Clear column values to show loading
39657
+ filter_columns: undefined, // Clear the stored filter columns
39658
+ };
39659
+ console.log('[FiltersWidget] Clearing confirmation state:', newState);
39660
+ setFilterState(newState);
39661
+ setAgentState(newState);
39662
+ // Send the confirmation message
39663
+ appendMessage(new TextMessage({
39664
+ content: message,
39665
+ role: Role.User,
39666
+ }));
39667
+ // Reset counters and start polling
39668
+ setApiCallCount(0);
39669
+ setHasTimeoutError(false);
39670
+ console.log('[FiltersWidget] Starting polling after confirmation');
39671
+ startLoadingTimeout();
39672
+ }, [filterState.filter_columns, filterState.ambiguous_columns, (_e = widget.config) === null || _e === void 0 ? void 0 : _e.query, datasetId, appendMessage, setFilterState, setAgentState, startLoadingTimeout, setApiCallCount, setHasTimeoutError]);
39673
+ const handleCancelConfirmation = useCallback(() => {
39674
+ // Clear the confirmation state
39675
+ setFilterState((prev) => (Object.assign(Object.assign({}, prev), { status: undefined, ambiguous_columns: undefined, message: undefined })));
39676
+ }, [setFilterState]);
39578
39677
  // Convert filter state to filter groups
39579
39678
  const filterGroups = convertFilterStateToGroups(filterState);
39580
- return (jsxRuntimeExports.jsx("div", { className: cn("flex flex-col h-full"), children: (filterState === null || filterState === void 0 ? void 0 : filterState.agent_message) &&
39581
- (!((_e = filterState.column_values) === null || _e === void 0 ? void 0 : _e.length))
39582
- ? (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: filterState.agent_message }) }) })) : (jsxRuntimeExports.jsx(FiltersContent, { filterGroups: filterGroups, showHeader: showHeader, onFilterChange: onFilterChange, widget: widget, appendMessage: appendMessage, query: (_f = widget.config) === null || _f === void 0 ? void 0 : _f.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout, filterState: filterState, onApplyFilters: onApplyFilters, isEditing: isEditing })) }));
39679
+ // Check if we're waiting for confirmation
39680
+ const isWaitingForConfirmation = filterState.status === 'waiting_for_confirmation' &&
39681
+ filterState.ambiguous_columns &&
39682
+ filterState.ambiguous_columns.length > 0;
39683
+ console.log('[CopilotKitFilters] Filter state check:', {
39684
+ status: filterState.status,
39685
+ hasAmbiguousColumns: !!filterState.ambiguous_columns,
39686
+ ambiguousColumnsLength: ((_f = filterState.ambiguous_columns) === null || _f === void 0 ? void 0 : _f.length) || 0,
39687
+ isWaitingForConfirmation,
39688
+ fullFilterState: filterState
39689
+ });
39690
+ return (jsxRuntimeExports.jsx("div", { className: cn("flex flex-col h-full"), children: isWaitingForConfirmation ? (
39691
+ // Show table selection UI when waiting for user to select tables
39692
+ jsxRuntimeExports.jsx(TableSelectionConfirmation, { ambiguousColumns: filterState.ambiguous_columns || [], resolvedColumns: filterState.resolved_columns, message: filterState.message || filterState.agent_message, onConfirm: handleConfirmation, onCancel: handleCancelConfirmation })) : (filterState === null || filterState === void 0 ? void 0 : filterState.agent_message) &&
39693
+ (!((_g = filterState.column_values) === null || _g === void 0 ? void 0 : _g.length)) &&
39694
+ filterState.status !== 'waiting_for_confirmation'
39695
+ ? (
39696
+ // Show agent message (errors, warnings, etc.)
39697
+ 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 whitespace-pre-line", children: filterState.agent_message }) }) })) : (
39698
+ // Show normal filter UI
39699
+ jsxRuntimeExports.jsx(FiltersContent, { filterGroups: filterGroups, showHeader: showHeader, onFilterChange: onFilterChange, widget: widget, appendMessage: appendMessage, query: (_h = widget.config) === null || _h === void 0 ? void 0 : _h.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout, filterState: filterState, onApplyFilters: onApplyFilters, isEditing: isEditing })) }));
39583
39700
  }
39584
39701
  function FiltersWidget({ widget, showHeader = true, onConfigUpdate, onFilterChange, widgetBackendUrl, onResetReady, datasetId, onApplyFilters, isEditing = false, }) {
39585
39702
  var _a;
package/dist/index.js CHANGED
@@ -39354,6 +39354,23 @@ const parseAndUpdateFilterState = (apiResponse, setFilterState) => {
39354
39354
  if (filterData.agent_message) {
39355
39355
  newFilterState.agent_message = filterData.agent_message;
39356
39356
  }
39357
+ // Handle confirmation state
39358
+ if (filterData.status) {
39359
+ newFilterState.status = filterData.status;
39360
+ }
39361
+ if (filterData.ambiguous_columns) {
39362
+ newFilterState.ambiguous_columns = filterData.ambiguous_columns;
39363
+ }
39364
+ if (filterData.message) {
39365
+ newFilterState.message = filterData.message;
39366
+ }
39367
+ if (filterData.filter_columns) {
39368
+ newFilterState.filter_columns = filterData.filter_columns;
39369
+ }
39370
+ if (filterData.resolved_columns) {
39371
+ newFilterState.resolved_columns = filterData.resolved_columns;
39372
+ }
39373
+ console.log('[parseAndUpdateFilterState] Updated filter state:', newFilterState);
39357
39374
  return newFilterState;
39358
39375
  });
39359
39376
  }
@@ -39377,6 +39394,25 @@ const convertFilterStateToGroups = (filterState) => {
39377
39394
  })),
39378
39395
  }));
39379
39396
  };
39397
+ // Component for handling table selection confirmation
39398
+ function TableSelectionConfirmation({ ambiguousColumns, resolvedColumns, message, onConfirm, onCancel, }) {
39399
+ const [selectedTables, setSelectedTables] = React.useState({});
39400
+ React.useEffect(() => {
39401
+ // Initialize with first option for each column
39402
+ const initial = {};
39403
+ ambiguousColumns.forEach((col) => {
39404
+ initial[col.column] = col.tables[0];
39405
+ });
39406
+ setSelectedTables(initial);
39407
+ }, [ambiguousColumns]);
39408
+ const handleSubmit = () => {
39409
+ onConfirm(selectedTables);
39410
+ };
39411
+ const allSelected = ambiguousColumns.every((col) => selectedTables[col.column]);
39412
+ return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col h-full p-4 bg-white", children: [jsxRuntimeExports.jsxs("div", { className: "mb-4", children: [jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-800 mb-2", children: "Table Selection Required" }), message && (jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 mb-4 whitespace-pre-line", children: message }))] }), resolvedColumns && resolvedColumns.length > 0 && (jsxRuntimeExports.jsxs("div", { className: "mb-4 p-3 bg-green-50 border border-green-200 rounded-lg", children: [jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-green-800 mb-2", children: "Already Resolved Columns:" }), jsxRuntimeExports.jsx("div", { className: "space-y-1", children: resolvedColumns.map((col) => (jsxRuntimeExports.jsxs("div", { className: "text-sm text-green-700", children: [jsxRuntimeExports.jsx("span", { className: "font-medium", children: col.column }), " \u2192 ", jsxRuntimeExports.jsx("span", { className: "text-green-600", children: col.table_name })] }, col.column))) })] })), jsxRuntimeExports.jsx(ScrollArea, { className: "flex-1 mb-4", children: jsxRuntimeExports.jsx("div", { className: "space-y-4", children: ambiguousColumns.map((col) => (jsxRuntimeExports.jsxs("div", { className: "border border-gray-200 rounded-lg p-3", children: [jsxRuntimeExports.jsx("label", { className: "block mb-2", children: jsxRuntimeExports.jsxs("span", { className: "text-sm font-medium text-gray-700", children: ["Column: ", jsxRuntimeExports.jsx("span", { className: "text-primary-600", children: col.column })] }) }), jsxRuntimeExports.jsxs("select", { value: selectedTables[col.column] || '', onChange: (e) => {
39413
+ setSelectedTables((prev) => (Object.assign(Object.assign({}, prev), { [col.column]: e.target.value })));
39414
+ }, className: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary-500", children: [jsxRuntimeExports.jsx("option", { value: "", children: "Select a table..." }), col.tables.map((table) => (jsxRuntimeExports.jsx("option", { value: table, children: table }, table)))] })] }, col.column))) }) }), jsxRuntimeExports.jsxs("div", { className: "flex gap-2 pt-3 border-t border-gray-200", children: [jsxRuntimeExports.jsx(Button, { onClick: onCancel, variant: "outline", className: "flex-1", children: "Cancel" }), jsxRuntimeExports.jsx(Button, { onClick: handleSubmit, disabled: !allSelected, className: "flex-1 bg-primary-600 hover:bg-primary-700 text-white disabled:bg-gray-400", children: "Confirm Selection" })] })] }));
39415
+ }
39380
39416
  function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout, filterState, onApplyFilters, isEditing = false, }) {
39381
39417
  const hasCalledRef = React.useRef(false);
39382
39418
  const [expandedGroups, setExpandedGroups] = React.useState({});
@@ -39485,20 +39521,18 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
39485
39521
  }, className: "py-1.5 text-sm font-medium text-primary-600 hover:text-primary-800 hover:bg-primary-50 rounded-md transition-colors px-2", children: "Clear All Filters" })) : (jsxRuntimeExports.jsx("div", {})), jsxRuntimeExports.jsx(Button, { onClick: () => {
39486
39522
  // Convert option IDs back to original label values
39487
39523
  const filtersWithLabels = {};
39488
- Object.entries(selectedFilters).forEach(([groupId, optionIds]) => {
39489
- const group = filterGroups.find(g => g.id === groupId);
39490
- if (group) {
39491
- filtersWithLabels[groupId] = optionIds.map(optionId => {
39492
- const option = group.options.find(opt => opt.id === optionId);
39493
- return (option === null || option === void 0 ? void 0 : option.label) || optionId;
39494
- });
39495
- }
39524
+ filterGroups.forEach((group) => {
39525
+ const optionIds = selectedFilters[group.id] || [];
39526
+ filtersWithLabels[group.id] = optionIds.map(optionId => {
39527
+ const option = group.options.find(opt => opt.id === optionId);
39528
+ return (option === null || option === void 0 ? void 0 : option.label) || optionId;
39529
+ });
39496
39530
  });
39497
39531
  onApplyFilters === null || onApplyFilters === void 0 ? void 0 : onApplyFilters(filtersWithLabels);
39498
39532
  }, disabled: isEditing, className: `${isEditing ? 'bg-gray-400 cursor-not-allowed' : 'bg-primary-600 hover:bg-primary-700'} text-white`, title: isEditing ? 'Save the layout first to apply filters' : '', children: "Apply Filters" })] }) })] }));
39499
39533
  }
39500
39534
  function CopilotKitFilters({ widget, showHeader, onFilterChange, onResetReady, widgetBackendUrl, datasetId, onApplyFilters, isEditing = false, }) {
39501
- var _a, _b, _c, _d, _e, _f;
39535
+ var _a, _b, _c, _d, _e, _f, _g, _h;
39502
39536
  const isFirstLoad = (_a = widget.config) === null || _a === void 0 ? void 0 : _a.isFirstLoad;
39503
39537
  const widget_data = (_b = widget.widget_data) === null || _b === void 0 ? void 0 : _b.column_values;
39504
39538
  const { setThreadId } = reactCore.useCopilotContext();
@@ -39602,11 +39636,94 @@ function CopilotKitFilters({ widget, showHeader, onFilterChange, onResetReady, w
39602
39636
  window.removeEventListener('clearFilterState', handleClearFilterState);
39603
39637
  };
39604
39638
  }, [widget.id, appendMessage, setFilterState, startLoadingTimeout]);
39639
+ // Handle confirmation submission
39640
+ const handleConfirmation = React.useCallback(async (tableMapping) => {
39641
+ var _a, _b, _c;
39642
+ console.log('[FiltersWidget] handleConfirmation called with:', {
39643
+ tableMapping,
39644
+ currentFilterState: filterState,
39645
+ widgetQuery: (_a = widget.config) === null || _a === void 0 ? void 0 : _a.query
39646
+ });
39647
+ // Format table mapping as a JSON string for the agent
39648
+ const tableMappingJson = JSON.stringify(tableMapping);
39649
+ // Get filter columns - try multiple sources
39650
+ let filterColumns = filterState.filter_columns || '';
39651
+ // Fallback: extract from the original query if not in state
39652
+ if (!filterColumns && ((_b = widget.config) === null || _b === void 0 ? void 0 : _b.query)) {
39653
+ const filterColumnsMatch = widget.config.query.match(/(?:filter by|filter)\s+(.+)/i);
39654
+ filterColumns = filterColumnsMatch ? filterColumnsMatch[1].trim() : '';
39655
+ }
39656
+ // Fallback: extract from ambiguous_columns if available
39657
+ if (!filterColumns && filterState.ambiguous_columns) {
39658
+ filterColumns = filterState.ambiguous_columns.map(col => col.column).join(',');
39659
+ }
39660
+ if (!filterColumns) {
39661
+ console.error('[FiltersWidget] No filter_columns found in state, query, or ambiguous_columns', {
39662
+ filterState,
39663
+ query: (_c = widget.config) === null || _c === void 0 ? void 0 : _c.query
39664
+ });
39665
+ return;
39666
+ }
39667
+ console.log('[FiltersWidget] Using filter columns:', filterColumns);
39668
+ // Send a very explicit message for the agent to parse
39669
+ const message = `User confirmed table selection. Call get_tables_columns_values with filter_columns="${filterColumns}" and table_mapping='${tableMappingJson}'`;
39670
+ console.log('[FiltersWidget] Sending table mapping confirmation:', {
39671
+ message,
39672
+ tableMapping,
39673
+ filterColumns,
39674
+ tableMappingJson
39675
+ });
39676
+ // Clear the confirmation state completely, including agent_message
39677
+ const newState = {
39678
+ dashboard_id: datasetId || "",
39679
+ status: undefined, // Don't set to 'processing' as it might block polling
39680
+ ambiguous_columns: undefined,
39681
+ message: undefined,
39682
+ agent_message: undefined, // Clear agent_message to allow polling
39683
+ column_values: [], // Clear column values to show loading
39684
+ filter_columns: undefined, // Clear the stored filter columns
39685
+ };
39686
+ console.log('[FiltersWidget] Clearing confirmation state:', newState);
39687
+ setFilterState(newState);
39688
+ setAgentState(newState);
39689
+ // Send the confirmation message
39690
+ appendMessage(new TextMessage({
39691
+ content: message,
39692
+ role: Role.User,
39693
+ }));
39694
+ // Reset counters and start polling
39695
+ setApiCallCount(0);
39696
+ setHasTimeoutError(false);
39697
+ console.log('[FiltersWidget] Starting polling after confirmation');
39698
+ startLoadingTimeout();
39699
+ }, [filterState.filter_columns, filterState.ambiguous_columns, (_e = widget.config) === null || _e === void 0 ? void 0 : _e.query, datasetId, appendMessage, setFilterState, setAgentState, startLoadingTimeout, setApiCallCount, setHasTimeoutError]);
39700
+ const handleCancelConfirmation = React.useCallback(() => {
39701
+ // Clear the confirmation state
39702
+ setFilterState((prev) => (Object.assign(Object.assign({}, prev), { status: undefined, ambiguous_columns: undefined, message: undefined })));
39703
+ }, [setFilterState]);
39605
39704
  // Convert filter state to filter groups
39606
39705
  const filterGroups = convertFilterStateToGroups(filterState);
39607
- return (jsxRuntimeExports.jsx("div", { className: cn("flex flex-col h-full"), children: (filterState === null || filterState === void 0 ? void 0 : filterState.agent_message) &&
39608
- (!((_e = filterState.column_values) === null || _e === void 0 ? void 0 : _e.length))
39609
- ? (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: filterState.agent_message }) }) })) : (jsxRuntimeExports.jsx(FiltersContent, { filterGroups: filterGroups, showHeader: showHeader, onFilterChange: onFilterChange, widget: widget, appendMessage: appendMessage, query: (_f = widget.config) === null || _f === void 0 ? void 0 : _f.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout, filterState: filterState, onApplyFilters: onApplyFilters, isEditing: isEditing })) }));
39706
+ // Check if we're waiting for confirmation
39707
+ const isWaitingForConfirmation = filterState.status === 'waiting_for_confirmation' &&
39708
+ filterState.ambiguous_columns &&
39709
+ filterState.ambiguous_columns.length > 0;
39710
+ console.log('[CopilotKitFilters] Filter state check:', {
39711
+ status: filterState.status,
39712
+ hasAmbiguousColumns: !!filterState.ambiguous_columns,
39713
+ ambiguousColumnsLength: ((_f = filterState.ambiguous_columns) === null || _f === void 0 ? void 0 : _f.length) || 0,
39714
+ isWaitingForConfirmation,
39715
+ fullFilterState: filterState
39716
+ });
39717
+ return (jsxRuntimeExports.jsx("div", { className: cn("flex flex-col h-full"), children: isWaitingForConfirmation ? (
39718
+ // Show table selection UI when waiting for user to select tables
39719
+ jsxRuntimeExports.jsx(TableSelectionConfirmation, { ambiguousColumns: filterState.ambiguous_columns || [], resolvedColumns: filterState.resolved_columns, message: filterState.message || filterState.agent_message, onConfirm: handleConfirmation, onCancel: handleCancelConfirmation })) : (filterState === null || filterState === void 0 ? void 0 : filterState.agent_message) &&
39720
+ (!((_g = filterState.column_values) === null || _g === void 0 ? void 0 : _g.length)) &&
39721
+ filterState.status !== 'waiting_for_confirmation'
39722
+ ? (
39723
+ // Show agent message (errors, warnings, etc.)
39724
+ 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 whitespace-pre-line", children: filterState.agent_message }) }) })) : (
39725
+ // Show normal filter UI
39726
+ jsxRuntimeExports.jsx(FiltersContent, { filterGroups: filterGroups, showHeader: showHeader, onFilterChange: onFilterChange, widget: widget, appendMessage: appendMessage, query: (_h = widget.config) === null || _h === void 0 ? void 0 : _h.query, isFirstLoad: isFirstLoad, widgetBackendUrl: widgetBackendUrl, widgetId: widget.id, startLoadingTimeout: startLoadingTimeout, clearLoadingTimeout: clearLoadingTimeout, filterState: filterState, onApplyFilters: onApplyFilters, isEditing: isEditing })) }));
39610
39727
  }
39611
39728
  function FiltersWidget({ widget, showHeader = true, onConfigUpdate, onFilterChange, widgetBackendUrl, onResetReady, datasetId, onApplyFilters, isEditing = false, }) {
39612
39729
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dp-widgets-framework",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"