Skip to content

Commit

Permalink
ahuna: toggle for workspace asssistants (#2895)
Browse files Browse the repository at this point in the history
* ahuna: toggle for workspace asssistants

* remove button

* fix nav edit

* nit nav

* fix wording assistant builder
  • Loading branch information
spolu authored Dec 15, 2023
1 parent 69f8145 commit 452238c
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 98 deletions.
116 changes: 60 additions & 56 deletions front/components/assistant_builder/AssistantBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -983,62 +986,63 @@ export default function AssistantBuilder({
<div className="text-2xl font-bold text-element-900">
Data Sources & Actions
</div>
{configurableDataSources.length === 0 && (
<ContentMessage title="You don't have any active data source or connection">
<div className="flex flex-col gap-y-3">
<div>
Assistants can incorporate existing company data and
knowledge to formulate answers.
</div>
<div>
There are two types of knowledge sources:{" "}
<strong>Data Sources</strong> (Files you can upload) and{" "}
<strong>Connections</strong> (Automatically synchronized
with platforms like Notion, Slack, ...).
{configurableDataSources.length === 0 &&
Object.keys(builderState.dataSourceConfigurations).length ===
0 && (
<ContentMessage title="You don't have any active data source">
<div className="flex flex-col gap-y-3">
<div>
Assistants can incorporate existing company data and
knowledge to formulate answers.
</div>
<div>
There are two types of data sources:{" "}
<strong>Folders</strong> (Files you can upload) and{" "}
<strong>Connections</strong> (Automatically synchronized
with platforms like Notion, Slack, ...).
</div>
{(() => {
switch (owner.role) {
case "admin":
return (
<div>
<strong>
Visit the "Connections" and "Folders" sections
in the Assistants panel to add new data sources.
</strong>
</div>
);
case "builder":
return (
<div>
<strong>
Only Admins can activate Connections.
<br />
You can add Data Sources by visiting "Folders"
in the Assistants panel.
</strong>
</div>
);
case "user":
return (
<div>
<strong>
Only Admins and Builders can activate
Connections or create Folders.
</strong>
</div>
);
case "none":
return <></>;
default:
((x: never) => {
throw new Error("Unkonwn role " + x);
})(owner.role);
}
})()}
</div>
{(() => {
switch (owner.role) {
case "admin":
return (
<div>
<strong>
Visit the "Data Sources" and "Connections"
sections in your workspace admin panel to add new
sources of knowledge.
</strong>
</div>
);
case "builder":
return (
<div>
<strong>
Only Admins can activate Connections.
<br />
You can Data Sources by visiting "Data Source" in
your workspace admin panel.
</strong>
</div>
);
case "user":
return (
<div>
<strong>
Only Admins and Builders can activate Connections
and Data Sources.
</strong>
</div>
);
case "none":
return <></>;
default:
((x: never) => {
throw new Error("Unkonwn role " + x);
})(owner.role);
}
})()}
</div>
</ContentMessage>
)}
</ContentMessage>
)}
<div>
You can ask the assistant to perform actions before answering,
like{" "}
Expand Down
2 changes: 1 addition & 1 deletion front/components/sparkle/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
138 changes: 100 additions & 38 deletions front/pages/w/[wId]/assistant/assistants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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<string>("");
Expand Down Expand Up @@ -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 (
<AppLayout
subscription={subscription}
Expand Down Expand Up @@ -200,19 +245,21 @@ export default function PersonalAssistants({
</div>
</div>
<Button.List>
<Link
href={`/w/${owner.sId}/assistant/gallery?flow=personal_add`}
>
<Button
variant="primary"
icon={BookOpenIcon}
label="Add from gallery"
/>
</Link>
{view !== "workspace" && (
<Link
href={`/w/${owner.sId}/assistant/gallery?flow=personal_add`}
>
<Button
variant="primary"
icon={BookOpenIcon}
label="Add from gallery"
/>
</Link>
)}
{view !== "workspace" && viewAssistants.length > 0 && (
<Tooltip label="Create your own assistant">
<Link
href={`/w/${owner.sId}/builder/assistants/new?flow=my_assistants`}
href={`/w/${owner.sId}/builder/assistants/new?flow=personal_assistants`}
>
<Button variant="primary" icon={PlusIcon} label="New" />
</Link>
Expand All @@ -235,32 +282,47 @@ export default function PersonalAssistants({
}
action={
agent.scope !== "global" && (
<div className="flex gap-2">
<Link
href={`/w/${owner.sId}/builder/assistants/${agent.sId}?flow=my_assistants`}
>
<Button
variant="tertiary"
icon={PencilSquareIcon}
label="Edit"
size="xs"
disabled={agent.scope === "workspace"}
<>
{agent.scope !== "workspace" ? (
<Button.List>
<Link
href={`/w/${owner.sId}/builder/assistants/${agent.sId}?flow=personal_assistants`}
>
<Button
variant="tertiary"
icon={PencilSquareIcon}
label="Edit"
size="xs"
/>
</Link>
<Button
variant="tertiary"
icon={XMarkIcon}
label="Remove from my list"
labelVisible={false}
onClick={() => {
agent.scope === "private"
? setShowDeletionModal(agent)
: setShowRemovalModal(agent);
}}
size="xs"
/>
</Button.List>
) : (
<SliderToggle
size="sm"
onClick={async () => {
await updateAgentUserListStatus(
agent,
agent.userListStatus === "in-list"
? "not-in-list"
: "in-list"
);
}}
selected={agent.userListStatus === "in-list"}
/>
</Link>

<Button
variant="tertiary"
icon={XMarkIcon}
label="Remove from my list"
labelVisible={false}
onClick={() => {
agent.scope === "private"
? setShowDeletionModal(agent)
: setShowRemovalModal(agent);
}}
size="xs"
/>
</div>
)}
</>
)
}
>
Expand All @@ -279,7 +341,7 @@ export default function PersonalAssistants({
)}
>
<Link
href={`/w/${owner.sId}/builder/assistants/new?flow=my_assistants`}
href={`/w/${owner.sId}/builder/assistants/new?flow=personal_assistants`}
>
<Button
size="sm"
Expand Down
2 changes: 1 addition & 1 deletion front/pages/w/[wId]/builder/assistants/[aId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const getServerSideProps: GetServerSideProps<{
context.query.flow as BuilderFlow
)
? (context.query.flow as BuilderFlow)
: "my_assistants";
: "personal_assistants";

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion front/pages/w/[wId]/builder/assistants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default function WorkspaceAssistants({
action={
<Button.List>
<Link
href={`/w/${owner.sId}/builder/assistants/${agent.sId}`}
href={`/w/${owner.sId}/builder/assistants/${agent.sId}?flow=workspace_assistants`}
>
<Button
variant="tertiary"
Expand Down
2 changes: 1 addition & 1 deletion front/pages/w/[wId]/builder/assistants/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getServerSideProps: GetServerSideProps<{
context.query.flow as BuilderFlow
)
? (context.query.flow as BuilderFlow)
: "my_assistants";
: "personal_assistants";

return {
props: {
Expand Down

0 comments on commit 452238c

Please sign in to comment.