From 452238c6ceb0653d2b83f59f58323eb2dbbb7fb7 Mon Sep 17 00:00:00 2001 From: Stanislas Polu Date: Fri, 15 Dec 2023 15:30:31 +0100 Subject: [PATCH] ahuna: toggle for workspace asssistants (#2895) * ahuna: toggle for workspace asssistants * remove button * fix nav edit * nit nav * fix wording assistant builder --- .../assistant_builder/AssistantBuilder.tsx | 116 ++++++++------- front/components/sparkle/navigation.tsx | 2 +- front/pages/w/[wId]/assistant/assistants.tsx | 138 +++++++++++++----- .../[wId]/builder/assistants/[aId]/index.tsx | 2 +- .../w/[wId]/builder/assistants/index.tsx | 2 +- .../pages/w/[wId]/builder/assistants/new.tsx | 2 +- 6 files changed, 164 insertions(+), 98 deletions(-) diff --git a/front/components/assistant_builder/AssistantBuilder.tsx b/front/components/assistant_builder/AssistantBuilder.tsx index ab0397b5b7c4..9ca813d4316c 100644 --- a/front/components/assistant_builder/AssistantBuilder.tsx +++ b/front/components/assistant_builder/AssistantBuilder.tsx @@ -185,7 +185,10 @@ export type AssistantBuilderInitialState = { } | null; }; -export const BUILDER_FLOWS = ["workspace_assistants", "my_assistants"] as const; +export const BUILDER_FLOWS = [ + "workspace_assistants", + "personal_assistants", +] as const; export type BuilderFlow = (typeof BUILDER_FLOWS)[number]; type AssistantBuilderProps = { user: UserType; @@ -983,62 +986,63 @@ export default function AssistantBuilder({
Data Sources & Actions
- {configurableDataSources.length === 0 && ( - -
-
- Assistants can incorporate existing company data and - knowledge to formulate answers. -
-
- There are two types of knowledge sources:{" "} - Data Sources (Files you can upload) and{" "} - Connections (Automatically synchronized - with platforms like Notion, Slack, ...). + {configurableDataSources.length === 0 && + Object.keys(builderState.dataSourceConfigurations).length === + 0 && ( + +
+
+ Assistants can incorporate existing company data and + knowledge to formulate answers. +
+
+ There are two types of data sources:{" "} + Folders (Files you can upload) and{" "} + Connections (Automatically synchronized + with platforms like Notion, Slack, ...). +
+ {(() => { + switch (owner.role) { + case "admin": + return ( +
+ + Visit the "Connections" and "Folders" sections + in the Assistants panel to add new data sources. + +
+ ); + case "builder": + return ( +
+ + Only Admins can activate Connections. +
+ You can add Data Sources by visiting "Folders" + in the Assistants panel. +
+
+ ); + case "user": + return ( +
+ + Only Admins and Builders can activate + Connections or create Folders. + +
+ ); + case "none": + return <>; + default: + ((x: never) => { + throw new Error("Unkonwn role " + x); + })(owner.role); + } + })()}
- {(() => { - switch (owner.role) { - case "admin": - return ( -
- - Visit the "Data Sources" and "Connections" - sections in your workspace admin panel to add new - sources of knowledge. - -
- ); - case "builder": - return ( -
- - Only Admins can activate Connections. -
- You can Data Sources by visiting "Data Source" in - your workspace admin panel. -
-
- ); - case "user": - return ( -
- - Only Admins and Builders can activate Connections - and Data Sources. - -
- ); - case "none": - return <>; - default: - ((x: never) => { - throw new Error("Unkonwn role " + x); - })(owner.role); - } - })()} -
- - )} + + )}
You can ask the assistant to perform actions before answering, like{" "} diff --git a/front/components/sparkle/navigation.tsx b/front/components/sparkle/navigation.tsx index ba481c395635..609522803378 100644 --- a/front/components/sparkle/navigation.tsx +++ b/front/components/sparkle/navigation.tsx @@ -142,7 +142,7 @@ export const subNavigationConversations = ({ menus: [ { id: "personal_assistants", - label: "My Assistants", + label: "Assistants", icon: RobotIcon, href: `/w/${owner.sId}/assistant/assistants`, current: current === "personal_assistants", diff --git a/front/pages/w/[wId]/assistant/assistants.tsx b/front/pages/w/[wId]/assistant/assistants.tsx index 779f75baba17..931838f40a62 100644 --- a/front/pages/w/[wId]/assistant/assistants.tsx +++ b/front/pages/w/[wId]/assistant/assistants.tsx @@ -8,19 +8,21 @@ import { PlusIcon, RobotIcon, Searchbar, + SliderToggle, Tab, Tooltip, XMarkIcon, } from "@dust-tt/sparkle"; import { AgentConfigurationType, + AgentUserListStatus, UserType, WorkspaceType, } from "@dust-tt/types"; import { SubscriptionType } from "@dust-tt/types"; import { GetServerSideProps, InferGetServerSidePropsType } from "next"; import Link from "next/link"; -import { useState } from "react"; +import { useContext, useState } from "react"; import { DeleteAssistantDialog, @@ -32,9 +34,11 @@ import { subNavigationAssistants, subNavigationConversations, } from "@app/components/sparkle/navigation"; +import { SendNotificationsContext } from "@app/components/sparkle/Notification"; import { Authenticator, getSession, getUserFromSession } from "@app/lib/auth"; import { useAgentConfigurations } from "@app/lib/swr"; import { classNames, subFilter } from "@app/lib/utils"; +import { PostAgentListStatusRequestBody } from "@app/pages/api/w/[wId]/members/me/agent_list_status"; const { GA_TRACKING_ID = "" } = process.env; @@ -91,7 +95,7 @@ export default function PersonalAssistants({ const { agentConfigurations, mutateAgentConfigurations } = useAgentConfigurations({ workspaceId: owner.sId, - agentsGetView: "list", + agentsGetView: view === "personal" ? "list" : "workspace", }); const [assistantSearch, setAssistantSearch] = useState(""); @@ -127,6 +131,47 @@ export default function PersonalAssistants({ }, ]; + const sendNotification = useContext(SendNotificationsContext); + + const updateAgentUserListStatus = async ( + agentConfiguration: AgentConfigurationType, + listStatus: AgentUserListStatus + ) => { + const body: PostAgentListStatusRequestBody = { + agentId: agentConfiguration.sId, + listStatus, + }; + + const res = await fetch( + `/api/w/${owner.sId}/members/me/agent_list_status`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + } + ); + if (!res.ok) { + const data = await res.json(); + sendNotification({ + title: `Error ${ + listStatus === "in-list" ? "adding" : "removing" + } Assistant`, + description: data.error.message, + type: "error", + }); + } else { + sendNotification({ + title: `Assistant ${ + listStatus === "in-list" ? "added to" : "removed from" + } your list`, + type: "success", + }); + await mutateAgentConfigurations(); + } + }; + return (
- -
+ )} + ) } > @@ -279,7 +341,7 @@ export default function PersonalAssistants({ )} >