Skip to content

Commit

Permalink
Trackers: limit 3 max + exclude non trackable connectors from watch d…
Browse files Browse the repository at this point in the history
…atasources (#9349)
  • Loading branch information
PopDaph authored Dec 13, 2024
1 parent e4bbb5f commit fa8a10e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
65 changes: 49 additions & 16 deletions front/components/trackers/TrackerBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
TRACKER_FREQUENCY_TYPES,
} from "@dust-tt/types";
import { useRouter } from "next/router";
import { useState } from "react";
import { useMemo, useState } from "react";

import { AdvancedSettings } from "@app/components/assistant_builder/InstructionScreen";
import AppLayout from "@app/components/sparkle/AppLayout";
Expand All @@ -34,6 +34,7 @@ import {
} from "@app/components/sparkle/AppLayoutTitle";
import TrackerBuilderDataSourceModal from "@app/components/trackers/TrackerBuilderDataSourceModal";
import { TrackerDataSourceSelectedTree } from "@app/components/trackers/TrackerDataSourceSelectedTree";
import { isConnectorTypeTrackable } from "@app/lib/document_upsert_hooks/hooks/document_tracker/consts";
import { isEmailValid } from "@app/lib/utils";

export const TrackerBuilder = ({
Expand Down Expand Up @@ -204,6 +205,16 @@ export const TrackerBuilder = ({
});
};

const trackableDataSourcesViews = useMemo(
() =>
dataSourceViews.filter(
(dsv) =>
!dsv.dataSource.connectorProvider ||
isConnectorTypeTrackable(dsv.dataSource.connectorProvider)
),
[dataSourceViews]
);

return (
<AppLayout
owner={owner}
Expand Down Expand Up @@ -238,11 +249,13 @@ export const TrackerBuilder = ({
setOpen={(isOpen) => setShowMaintainedDsModal(isOpen)}
owner={owner}
onSave={async (dsConfigs) => {
setEdited(true);
setTracker((t) => ({
...t,
maintainedDataSources: dsConfigs,
}));
if (!edited) {
setEdited(true);
}
}}
dataSourceViews={dataSourceViews}
initialDataSourceConfigurations={tracker.maintainedDataSources}
Expand All @@ -254,13 +267,15 @@ export const TrackerBuilder = ({
setOpen={(isOpen) => setShowWatchedDataSourcesModal(isOpen)}
owner={owner}
onSave={async (dsConfigs) => {
setEdited(true);
setTracker((t) => ({
...t,
watchedDataSources: dsConfigs,
}));
if (!edited) {
setEdited(true);
}
}}
dataSourceViews={dataSourceViews}
dataSourceViews={trackableDataSourcesViews} // Only show trackable data sources for watching.
initialDataSourceConfigurations={tracker.watchedDataSources}
allowedSpaces={[globalSpace]}
viewType="documents"
Expand Down Expand Up @@ -290,6 +305,9 @@ export const TrackerBuilder = ({
providerId: g.modelSettings.providerId,
temperature: g.temperature,
}));
if (!edited) {
setEdited(true);
}
}}
/>
</div>
Expand All @@ -308,13 +326,16 @@ export const TrackerBuilder = ({
<Input
label="Name"
value={tracker.name || ""}
onChange={(e) =>
onChange={(e) => {
setTracker((t) => ({
...t,
name: e.target.value,
nameError: null,
}))
}
}));
if (!edited) {
setEdited(true);
}
}}
placeholder="Descriptive name."
message={tracker.nameError}
messageStatus={tracker.nameError ? "error" : undefined}
Expand All @@ -324,13 +345,16 @@ export const TrackerBuilder = ({
<Input
label="Description"
value={tracker.description || ""}
onChange={(e) =>
onChange={(e) => {
setTracker((t) => ({
...t,
description: e.target.value,
descriptionError: null,
}))
}
}));
if (!edited) {
setEdited(true);
}
}}
placeholder="Brief description of what you're tracking and why."
message={tracker.descriptionError}
messageStatus={tracker.descriptionError ? "error" : undefined}
Expand Down Expand Up @@ -370,6 +394,9 @@ export const TrackerBuilder = ({
...t,
frequency: f,
}));
if (!edited) {
setEdited(true);
}
}}
/>
))}
Expand All @@ -382,13 +409,16 @@ export const TrackerBuilder = ({
label="Recipients"
placeholder="Enter email addresses (separate multiple addresses with commas)."
value={tracker.recipients}
onChange={(e) =>
onChange={(e) => {
setTracker((t) => ({
...t,
recipients: e.target.value,
recipientsError: null,
}))
}
}));
if (!edited) {
setEdited(true);
}
}}
message={tracker.recipientsError}
messageStatus={tracker.recipientsError ? "error" : undefined}
/>
Expand All @@ -409,13 +439,16 @@ export const TrackerBuilder = ({
<TextArea
placeholder="Describe what changes or updates you want to track (be as specific as possible)."
value={tracker.prompt || ""}
onChange={(e) =>
onChange={(e) => {
setTracker((t) => ({
...t,
prompt: e.target.value,
promptError: null,
}))
}
}));
if (!edited) {
setEdited(true);
}
}}
error={tracker.promptError}
showErrorLabel={!!tracker.promptError}
/>
Expand Down
14 changes: 14 additions & 0 deletions front/pages/api/w/[wId]/spaces/[spaceId]/trackers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ async function handler(
});

case "POST":
const existingTrackers = await TrackerConfigurationResource.listBySpace(
auth,
space
);
if (existingTrackers.length >= 3) {
return apiError(req, res, {
status_code: 400,
api_error: {
type: "invalid_request_error",
message: "You can't have more than 3 trackers in a space.",
},
});
}

const bodyValidation = PostTrackersRequestBodySchema.decode(req.body);

if (isLeft(bodyValidation)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const getServerSideProps = withDefaultUserAuthRequirements<{
}

const flags = await getFeatureFlags(owner);
if (!flags.includes("labs_trackers") && !auth.isAdmin()) {
if (!flags.includes("labs_trackers") || !auth.isAdmin()) {
return {
notFound: true,
};
Expand Down
8 changes: 4 additions & 4 deletions front/pages/w/[wId]/assistant/labs/trackers/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ export const getServerSideProps = withDefaultUserAuthRequirements<{
};
}

const dataSourceViews = await DataSourceViewResource.listBySpaces(auth, [
globalSpace,
]);

const flags = await getFeatureFlags(owner);
if (!flags.includes("labs_trackers") || !auth.isAdmin()) {
return {
notFound: true,
};
}

const dataSourceViews = await DataSourceViewResource.listBySpaces(auth, [
globalSpace,
]);

return {
props: {
baseUrl: config.getClientFacingUrl(),
Expand Down

0 comments on commit fa8a10e

Please sign in to comment.