diff --git a/front/components/assistant_builder/actions/ProcessAction.tsx b/front/components/assistant_builder/actions/ProcessAction.tsx index 626386139879..7ab1aef5e904 100644 --- a/front/components/assistant_builder/actions/ProcessAction.tsx +++ b/front/components/assistant_builder/actions/ProcessAction.tsx @@ -567,7 +567,7 @@ export function ActionProcess({ }} /> setEdited(true)} /> diff --git a/front/components/assistant_builder/actions/RetrievalAction.tsx b/front/components/assistant_builder/actions/RetrievalAction.tsx index 64a48ef49229..267e4f672442 100644 --- a/front/components/assistant_builder/actions/RetrievalAction.tsx +++ b/front/components/assistant_builder/actions/RetrievalAction.tsx @@ -1,3 +1,4 @@ +import { Checkbox } from "@dust-tt/sparkle"; import type { SpaceType, WorkspaceType } from "@dust-tt/types"; import { useEffect, useState } from "react"; @@ -7,6 +8,8 @@ import DataSourceSelectionSection from "@app/components/assistant_builder/DataSo import type { AssistantBuilderActionConfiguration, AssistantBuilderRetrievalConfiguration, + AssistantBuilderRetrievalExhaustiveConfiguration, + AssistantBuilderTimeFrame, } from "@app/components/assistant_builder/types"; import { classNames } from "@app/lib/utils"; @@ -85,18 +88,19 @@ export function hasErrorActionRetrievalExhaustive( ): string | null { return action.type === "RETRIEVAL_EXHAUSTIVE" && Object.keys(action.configuration.dataSourceConfigurations).length > 0 && - !!action.configuration.timeFrame.value + // The time frame is optional for exhaustive retrieval, but if it is set, it must be valid. + (!action.configuration.timeFrame || !!action.configuration.timeFrame.value) ? null - : "Please select at least one data source and set a timeframe"; + : "Please select at least one data source and set a valid timeframe"; } type ActionRetrievalExhaustiveProps = { owner: WorkspaceType; - actionConfiguration: AssistantBuilderRetrievalConfiguration | null; + actionConfiguration: AssistantBuilderRetrievalExhaustiveConfiguration | null; allowedSpaces: SpaceType[]; updateAction: ( setNewAction: ( - previousAction: AssistantBuilderRetrievalConfiguration + previousAction: AssistantBuilderRetrievalExhaustiveConfiguration ) => AssistantBuilderRetrievalConfiguration ) => void; setEdited: (edited: boolean) => void; @@ -112,11 +116,25 @@ export function ActionRetrievalExhaustive({ const [showDataSourcesModal, setShowDataSourcesModal] = useState(false); const [timeFrameError, setTimeFrameError] = useState(null); + const [defaultTimeFrame, setDefaultTimeFrame] = + useState({ + value: 1, + unit: "month", + }); + useEffect(() => { if (actionConfiguration) { - if (!actionConfiguration.timeFrame.value) { + if ( + actionConfiguration.timeFrame && + !actionConfiguration.timeFrame.value + ) { setTimeFrameError("Timeframe must be a number"); } else { + // Set the default time frame to the current time frame if it exists, + // so if the user unchecks the checkbox, it won't reset to initial value + if (actionConfiguration.timeFrame) { + setDefaultTimeFrame(actionConfiguration.timeFrame); + } setTimeFrameError(null); } } @@ -125,6 +143,8 @@ export function ActionRetrievalExhaustive({ if (!actionConfiguration) { return null; } + const timeFrame = actionConfiguration.timeFrame || defaultTimeFrame; + const timeFrameDisabled = !actionConfiguration.timeFrame; return ( <> @@ -157,7 +177,22 @@ export function ActionRetrievalExhaustive({ viewType={"documents"} />
-
+ { + setEdited(true); + updateAction((previousAction) => ({ + ...previousAction, + timeFrame: checked ? defaultTimeFrame : undefined, + })); + }} + /> +
Collect data from the last
{ const value = parseInt(e.target.value, 10); if (!isNaN(value) || !e.target.value) { @@ -178,16 +214,18 @@ export function ActionRetrievalExhaustive({ ...previousAction, timeFrame: { value, - unit: previousAction.timeFrame.unit, + unit: timeFrame.unit, }, })); } }} + disabled={timeFrameDisabled} /> setEdited(true)} + disabled={timeFrameDisabled} />
diff --git a/front/components/assistant_builder/actions/TimeDropdown.tsx b/front/components/assistant_builder/actions/TimeDropdown.tsx index 7651b64f83a9..906353af375c 100644 --- a/front/components/assistant_builder/actions/TimeDropdown.tsx +++ b/front/components/assistant_builder/actions/TimeDropdown.tsx @@ -8,27 +8,29 @@ import { import type { TimeframeUnit } from "@dust-tt/types"; import { TIME_FRAME_UNIT_TO_LABEL } from "@app/components/assistant_builder/shared"; -import type { AssistantBuilderBaseConfiguration } from "@app/components/assistant_builder/types"; +import type { AssistantBuilderTimeFrame } from "@app/components/assistant_builder/types"; -interface TimeUnitDropdownProps { - actionConfiguration: T; +interface TimeUnitDropdownProps< + T extends { timeFrame?: AssistantBuilderTimeFrame }, +> { + timeFrame: AssistantBuilderTimeFrame; + disabled?: boolean; onEdit: () => void; updateAction: (setNewAction: (previousAction: T) => T) => void; } -export function TimeUnitDropdown({ - actionConfiguration, - updateAction, - onEdit, -}: TimeUnitDropdownProps) { +export function TimeUnitDropdown< + T extends { timeFrame?: AssistantBuilderTimeFrame }, +>({ timeFrame, updateAction, onEdit, disabled }: TimeUnitDropdownProps) { return (