From c48476d884f148ec0c35c9dcaff50996aa9d7636 Mon Sep 17 00:00:00 2001 From: Sebastien Flory Date: Fri, 29 Nov 2024 10:06:33 +0100 Subject: [PATCH] Improve keyboard nav with poke search --- front/components/UserMenu.tsx | 22 ++- .../conversation/ConversationTitle.tsx | 20 --- front/components/poke/PokeNavbar.tsx | 96 +++++++---- front/lib/api/assistant/conversation.ts | 152 ---------------- front/lib/development.ts | 6 +- front/lib/poke/conversations.ts | 162 ++++++++++++++++++ front/lib/poke/search.ts | 8 +- front/lib/poke/utils.ts | 49 ++++++ front/lib/resources/data_source_resource.ts | 16 -- .../resources/data_source_view_resource.ts | 17 -- front/lib/resources/membership_resource.ts | 4 +- front/lib/resources/space_resource.ts | 8 - .../[wId]/conversations/[cId]/index.ts | 2 +- .../pages/api/w/[wId]/members/[uId]/index.ts | 4 +- .../data_source_views/[dsvId]/index.tsx | 3 +- .../poke/[wId]/spaces/[spaceId]/index.tsx | 3 +- 16 files changed, 311 insertions(+), 261 deletions(-) create mode 100644 front/lib/poke/conversations.ts create mode 100644 front/lib/poke/utils.ts diff --git a/front/components/UserMenu.tsx b/front/components/UserMenu.tsx index 979ff531dbc2..e8f4fdbc2c93 100644 --- a/front/components/UserMenu.tsx +++ b/front/components/UserMenu.tsx @@ -16,9 +16,11 @@ import { import { useSendNotification } from "@dust-tt/sparkle"; import type { UserType, WorkspaceType } from "@dust-tt/types"; import { isOnlyAdmin, isOnlyBuilder, isOnlyUser } from "@dust-tt/types"; +import { BugIcon } from "lucide-react"; +import { useRouter } from "next/router"; import { useMemo } from "react"; -import { canForceUserRole, forceUserRole } from "@app/lib/development"; +import { forceUserRole, showDebugTools } from "@app/lib/development"; import { useFeatureFlags } from "@app/lib/swr/workspaces"; export function UserMenu({ @@ -28,6 +30,7 @@ export function UserMenu({ user: UserType; owner: WorkspaceType; }) { + const router = useRouter(); const { featureFlags } = useFeatureFlags({ workspaceId: owner.sId }); const hasBetaAccess = featureFlags.some((flag: string) => @@ -92,9 +95,24 @@ export function UserMenu({ )} - {canForceUserRole(owner) && ( + {showDebugTools(owner) && ( <> + {router.route === "/w/[wId]/assistant/[cId]" && ( + { + const regexp = new RegExp(`/w/([^/]+)/assistant/([^/]+)`); + const match = window.location.href.match(regexp); + if (match) { + void router.push( + `/poke/${match[1]}/conversations/${match[2]}` + ); + } + }} + icon={BugIcon} + /> + )} {!isOnlyAdmin(owner) && ( void; }) { - const router = useRouter(); const { mutate } = useSWRConfig(); const [copyLinkSuccess, setCopyLinkSuccess] = useState(false); @@ -194,21 +189,6 @@ export function ConversationTitle({ /> )} - {(isDevelopment() || isADustProdWorkspace(owner)) && ( -
-
- )} ( export default PokeNavbar; export function PokeSearchCommand() { + const router = useRouter(); const [open, setOpen] = useState(false); const [searchTerm, setSearchTerm] = useState(""); + const [isNavigating, setIsNavigating] = useState(false); const { isError, isLoading, results } = usePokeSearch({ // Disable search until the user has typed at least 2 characters. @@ -46,21 +49,38 @@ export function PokeSearchCommand() { search: searchTerm, }); + const navigateTo = useCallback( + async (link: string) => { + setIsNavigating(true); + await router.push(link); + setIsNavigating(false); + }, + [router] + ); + useEffect(() => { const down = (e: KeyboardEvent) => { if (e.key === "k" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); setOpen((open) => !open); + } else if ( + open && + results.length > 0 && + e.key === "Enter" && + results[0].link + ) { + e.preventDefault(); + void navigateTo(results[0].link); } }; document.addEventListener("keydown", down); return () => document.removeEventListener("keydown", down); - }, []); + }, [navigateTo, open, results]); return ( <> setOpen(true)}> - Search + Search (⌘K) - setSearchTerm(value)} - className="border-none focus:outline-none focus:ring-0" - /> - - {isLoading &&
Searching...
} - {searchTerm && - searchTerm.length >= 2 && - !isError && - !isLoading && - results.length === 0 && ( -
No results found.
- )} - {isError &&
Something went wrong.
} - {searchTerm.length < 2 && ( -
Enter at least 2 characters...
- )} + {isNavigating ? ( +
+ +
+ ) : ( + <> + setSearchTerm(value)} + className="border-none focus:outline-none focus:ring-0" + /> + + {isLoading &&
Searching...
} + {searchTerm && + searchTerm.length >= 2 && + !isError && + !isLoading && + results.length === 0 && ( +
No results found.
+ )} + {isError && ( +
Something went wrong.
+ )} + {searchTerm.length < 2 && ( +
+ Enter at least 2 characters... +
+ )} - {results.map(({ id, link, name }) => - link ? ( - - + {results.map(({ id, link, name }) => ( + (link ? navigateTo(link) : null)} + > {name} (id: {id}) - - ) : ( - - {name} (id: {id}) - - ) - )} -
+ ))} +
+ + )}
); diff --git a/front/lib/api/assistant/conversation.ts b/front/lib/api/assistant/conversation.ts index ece1ba6f4ca1..1614a5ebcd98 100644 --- a/front/lib/api/assistant/conversation.ts +++ b/front/lib/api/assistant/conversation.ts @@ -20,7 +20,6 @@ import type { LightAgentConfigurationType, MentionType, PlanType, - PokeConversationType, Result, SupportedContentFragmentType, UserMessageContext, @@ -68,12 +67,6 @@ import { makeMessageRateLimitKeyForWorkspace, } from "@app/lib/api/assistant/rate_limits"; import { Authenticator } from "@app/lib/auth"; -import { AgentBrowseAction } from "@app/lib/models/assistant/actions/browse"; -import { AgentDustAppRunAction } from "@app/lib/models/assistant/actions/dust_app_run"; -import { AgentProcessAction } from "@app/lib/models/assistant/actions/process"; -import { AgentRetrievalAction } from "@app/lib/models/assistant/actions/retrieval"; -import { AgentTablesQueryAction } from "@app/lib/models/assistant/actions/tables_query"; -import { AgentWebsearchAction } from "@app/lib/models/assistant/actions/websearch"; import { AgentMessageContent } from "@app/lib/models/assistant/agent_message_content"; import { AgentMessage, @@ -88,7 +81,6 @@ import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry"; import { ContentFragmentResource } from "@app/lib/resources/content_fragment_resource"; import { GroupResource } from "@app/lib/resources/group_resource"; import { MembershipResource } from "@app/lib/resources/membership_resource"; -import { SpaceResource } from "@app/lib/resources/space_resource"; import { frontSequelize } from "@app/lib/resources/storage"; import { ContentFragmentModel } from "@app/lib/resources/storage/models/content_fragment"; import { @@ -421,150 +413,6 @@ export async function getConversation( }); } -export async function getPokeConversation( - auth: Authenticator, - conversationId: string, - includeDeleted?: boolean -): Promise> { - const conversation = await getConversation( - auth, - conversationId, - includeDeleted - ); - - // Enrich the returned conversation with the apps runs linked to the agent messages - // Decided to do it as a separate step because I didn't want to modify the getConversation to make it more complex based on the use case - // and I still wanted to use the existing getConversation code for rendering. - if (conversation.isOk()) { - const pokeConversation = conversation.value as PokeConversationType; - const globalSpace = await SpaceResource.fetchWorkspaceGlobalSpace(auth); - // Cycle through the message and actions and enrich them with the runId(s) - for (const messages of pokeConversation.content) { - for (const m of messages) { - if (m.type === "agent_message") { - m.runIds = ( - await AgentMessage.findOne({ - where: { id: m.agentMessageId }, - attributes: ["runIds"], - raw: true, - }) - )?.runIds; - - if (m.actions.length > 0) { - { - for (const a of m.actions) { - switch (a.type) { - case "browse_action": { - a.runId = ( - await AgentBrowseAction.findOne({ - where: { id: a.id }, - attributes: ["runId"], - raw: true, - }) - )?.runId; - const app = - DustProdActionRegistry["assistant-v2-browse"].app; - a.appId = app.appId; - a.appSpaceId = app.appSpaceId; - a.appWorkspaceId = app.workspaceId; - break; - } - case "process_action": { - a.runId = ( - await AgentProcessAction.findOne({ - where: { id: a.id }, - attributes: ["runId"], - raw: true, - }) - )?.runId; - const app = - DustProdActionRegistry["assistant-v2-process"].app; - a.appId = app.appId; - a.appSpaceId = app.appSpaceId; - a.appWorkspaceId = app.workspaceId; - break; - } - case "retrieval_action": { - a.runId = ( - await AgentRetrievalAction.findOne({ - where: { id: a.id }, - attributes: ["runId"], - raw: true, - }) - )?.runId; - const app = - DustProdActionRegistry["assistant-v2-retrieval"].app; - a.appId = app.appId; - a.appSpaceId = app.appSpaceId; - a.appWorkspaceId = app.workspaceId; - break; - } - case "tables_query_action": { - a.runId = ( - await AgentTablesQueryAction.findOne({ - where: { id: a.id }, - attributes: ["runId"], - raw: true, - }) - )?.runId; - const app = - DustProdActionRegistry["assistant-v2-query-tables"].app; - a.appId = app.appId; - a.appSpaceId = app.appSpaceId; - a.appWorkspaceId = app.workspaceId; - break; - } - case "websearch_action": { - a.runId = ( - await AgentWebsearchAction.findOne({ - where: { id: a.id }, - attributes: ["runId"], - raw: true, - }) - )?.runId; - const app = - DustProdActionRegistry["assistant-v2-websearch"].app; - a.appId = app.appId; - a.appSpaceId = app.appSpaceId; - a.appWorkspaceId = app.workspaceId; - break; - } - case "dust_app_run_action": { - const runAction = await AgentDustAppRunAction.findOne({ - where: { id: a.id }, - attributes: ["runId", "appWorkspaceId", "appId"], - raw: true, - }); - - if (runAction) { - a.runId = runAction.runId; - a.appWorkspaceId = runAction.appWorkspaceId; - a.appSpaceId = globalSpace.sId; - a.appId = runAction.appId; - } - break; - } - - case "conversation_include_file_action": - case "conversation_list_files_action": - // Theses actions do not call a dust app - break; - - default: - assertNever(a); - } - } - } - } - } - } - } - return new Ok(pokeConversation); - } - - return conversation; -} - export async function getConversationWithoutContent( auth: Authenticator, conversationId: string, diff --git a/front/lib/development.ts b/front/lib/development.ts index df26ef979ecb..6bbe003c74ea 100644 --- a/front/lib/development.ts +++ b/front/lib/development.ts @@ -6,14 +6,14 @@ import { PRODUCTION_DUST_WORKSPACE_ID, } from "@app/lib/registry"; -export function isADustProdWorkspace(owner: LightWorkspaceType) { +function isADustProdWorkspace(owner: LightWorkspaceType) { return ( owner.sId === PRODUCTION_DUST_WORKSPACE_ID || owner.sId === PRODUCTION_DUST_APPS_WORKSPACE_ID ); } -export function canForceUserRole(owner: LightWorkspaceType) { +export function showDebugTools(owner: LightWorkspaceType) { return isDevelopment() || isADustProdWorkspace(owner); } @@ -23,7 +23,7 @@ export async function forceUserRole( role: "user" | "builder" | "admin" ) { // Ideally we should check if the user is dust super user but we don't have this information in the front-end - if (!canForceUserRole(owner)) { + if (!showDebugTools(owner)) { return new Err("Not allowed"); } diff --git a/front/lib/poke/conversations.ts b/front/lib/poke/conversations.ts new file mode 100644 index 000000000000..6a7f29f59e74 --- /dev/null +++ b/front/lib/poke/conversations.ts @@ -0,0 +1,162 @@ +import type { + ConversationError, + PokeConversationType, + Result, +} from "@dust-tt/types"; +import { assertNever, Ok } from "@dust-tt/types"; + +import { getConversation } from "@app/lib/api/assistant/conversation"; +import type { Authenticator } from "@app/lib/auth"; +import { AgentBrowseAction } from "@app/lib/models/assistant/actions/browse"; +import { AgentDustAppRunAction } from "@app/lib/models/assistant/actions/dust_app_run"; +import { AgentProcessAction } from "@app/lib/models/assistant/actions/process"; +import { AgentRetrievalAction } from "@app/lib/models/assistant/actions/retrieval"; +import { AgentTablesQueryAction } from "@app/lib/models/assistant/actions/tables_query"; +import { AgentWebsearchAction } from "@app/lib/models/assistant/actions/websearch"; +import { AgentMessage } from "@app/lib/models/assistant/conversation"; +import { DustProdActionRegistry } from "@app/lib/registry"; +import { SpaceResource } from "@app/lib/resources/space_resource"; + +export async function getPokeConversation( + auth: Authenticator, + conversationId: string, + includeDeleted?: boolean +): Promise> { + const conversation = await getConversation( + auth, + conversationId, + includeDeleted + ); + + // Enrich the returned conversation with the apps runs linked to the agent messages + // Decided to do it as a separate step because I didn't want to modify the getConversation to make it more complex based on the use case + // and I still wanted to use the existing getConversation code for rendering. + if (conversation.isOk()) { + const pokeConversation = conversation.value as PokeConversationType; + const globalSpace = await SpaceResource.fetchWorkspaceGlobalSpace(auth); + // Cycle through the message and actions and enrich them with the runId(s) + for (const messages of pokeConversation.content) { + for (const m of messages) { + if (m.type === "agent_message") { + m.runIds = ( + await AgentMessage.findOne({ + where: { id: m.agentMessageId }, + attributes: ["runIds"], + raw: true, + }) + )?.runIds; + + if (m.actions.length > 0) { + { + for (const a of m.actions) { + switch (a.type) { + case "browse_action": { + a.runId = ( + await AgentBrowseAction.findOne({ + where: { id: a.id }, + attributes: ["runId"], + raw: true, + }) + )?.runId; + const app = + DustProdActionRegistry["assistant-v2-browse"].app; + a.appId = app.appId; + a.appSpaceId = app.appSpaceId; + a.appWorkspaceId = app.workspaceId; + break; + } + case "process_action": { + a.runId = ( + await AgentProcessAction.findOne({ + where: { id: a.id }, + attributes: ["runId"], + raw: true, + }) + )?.runId; + const app = + DustProdActionRegistry["assistant-v2-process"].app; + a.appId = app.appId; + a.appSpaceId = app.appSpaceId; + a.appWorkspaceId = app.workspaceId; + break; + } + case "retrieval_action": { + a.runId = ( + await AgentRetrievalAction.findOne({ + where: { id: a.id }, + attributes: ["runId"], + raw: true, + }) + )?.runId; + const app = + DustProdActionRegistry["assistant-v2-retrieval"].app; + a.appId = app.appId; + a.appSpaceId = app.appSpaceId; + a.appWorkspaceId = app.workspaceId; + break; + } + case "tables_query_action": { + a.runId = ( + await AgentTablesQueryAction.findOne({ + where: { id: a.id }, + attributes: ["runId"], + raw: true, + }) + )?.runId; + const app = + DustProdActionRegistry["assistant-v2-query-tables"].app; + a.appId = app.appId; + a.appSpaceId = app.appSpaceId; + a.appWorkspaceId = app.workspaceId; + break; + } + case "websearch_action": { + a.runId = ( + await AgentWebsearchAction.findOne({ + where: { id: a.id }, + attributes: ["runId"], + raw: true, + }) + )?.runId; + const app = + DustProdActionRegistry["assistant-v2-websearch"].app; + a.appId = app.appId; + a.appSpaceId = app.appSpaceId; + a.appWorkspaceId = app.workspaceId; + break; + } + case "dust_app_run_action": { + const runAction = await AgentDustAppRunAction.findOne({ + where: { id: a.id }, + attributes: ["runId", "appWorkspaceId", "appId"], + raw: true, + }); + + if (runAction) { + a.runId = runAction.runId; + a.appWorkspaceId = runAction.appWorkspaceId; + a.appSpaceId = globalSpace.sId; + a.appId = runAction.appId; + } + break; + } + + case "conversation_include_file_action": + case "conversation_list_files_action": + // Theses actions do not call a dust app + break; + + default: + assertNever(a); + } + } + } + } + } + } + } + return new Ok(pokeConversation); + } + + return conversation; +} diff --git a/front/lib/poke/search.ts b/front/lib/poke/search.ts index 7078dc2298af..c1bcc4c9fb02 100644 --- a/front/lib/poke/search.ts +++ b/front/lib/poke/search.ts @@ -5,6 +5,10 @@ import type { PokeItemBase } from "@dust-tt/types/dist/front/lib/poke"; import config from "@app/lib/api/config"; import { getWorkspaceInfos } from "@app/lib/api/workspace"; import type { Authenticator } from "@app/lib/auth"; +import { + dataSourceToPokeJSON, + dataSourceViewToPokeJSON, +} from "@app/lib/poke/utils"; import { DataSourceResource } from "@app/lib/resources/data_source_resource"; import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource"; import { getResourceNameAndIdFromSId } from "@app/lib/resources/string_ids"; @@ -64,7 +68,7 @@ async function searchPokeResourcesBySId( return []; } - return [await dataSourceView.toPokeJSON()]; + return [await dataSourceViewToPokeJSON(dataSourceView)]; case "data_source": const dataSource = await DataSourceResource.fetchByNameOrId(auth, sId); @@ -72,7 +76,7 @@ async function searchPokeResourcesBySId( return []; } - return [await dataSource.toPokeJSON()]; + return [await dataSourceToPokeJSON(dataSource)]; default: return []; diff --git a/front/lib/poke/utils.ts b/front/lib/poke/utils.ts new file mode 100644 index 000000000000..e51eab076973 --- /dev/null +++ b/front/lib/poke/utils.ts @@ -0,0 +1,49 @@ +import type { + PokeDataSourceType, + PokeDataSourceViewType, + PokeSpaceType, +} from "@dust-tt/types"; + +import config from "@app/lib/api/config"; +import type { DataSourceResource } from "@app/lib/resources/data_source_resource"; +import type { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource"; +import type { SpaceResource } from "@app/lib/resources/space_resource"; +import { getWorkspaceByModelId } from "@app/lib/workspace"; + +export function spaceToPokeJSON(space: SpaceResource): PokeSpaceType { + return { + ...space.toJSON(), + groups: space.groups.map((group) => group.toJSON()), + }; +} + +export async function dataSourceToPokeJSON( + dataSource: DataSourceResource +): Promise { + const workspace = await getWorkspaceByModelId(dataSource.workspaceId); + + return { + ...dataSource.toJSON(), + link: workspace + ? `${config.getClientFacingUrl()}/poke/${workspace.sId}/data_sources/${dataSource.sId}` + : null, + name: `Data Source (${dataSource.name})`, + space: spaceToPokeJSON(dataSource.space), + }; +} + +export async function dataSourceViewToPokeJSON( + dataSourceView: DataSourceViewResource +): Promise { + const workspace = await getWorkspaceByModelId(dataSourceView.workspaceId); + + return { + ...dataSourceView.toJSON(), + dataSource: await dataSourceToPokeJSON(dataSourceView.dataSource), + link: workspace + ? `${config.getClientFacingUrl()}/poke/${workspace.sId}/spaces/${dataSourceView.space.sId}/data_source_views/${dataSourceView.sId}` + : null, + name: `Data Source (${dataSourceView.dataSource.name})`, + space: spaceToPokeJSON(dataSourceView.space), + }; +} diff --git a/front/lib/resources/data_source_resource.ts b/front/lib/resources/data_source_resource.ts index 20856c6f9ae3..b84e98856e79 100644 --- a/front/lib/resources/data_source_resource.ts +++ b/front/lib/resources/data_source_resource.ts @@ -2,7 +2,6 @@ import type { ConnectorProvider, DataSourceType, ModelId, - PokeDataSourceType, Result, } from "@dust-tt/types"; import { formatUserFullName, Ok, removeNulls } from "@dust-tt/types"; @@ -15,7 +14,6 @@ import type { import { Op } from "sequelize"; import { getDataSourceUsage } from "@app/lib/api/agent_data_sources"; -import config from "@app/lib/api/config"; import type { Authenticator } from "@app/lib/auth"; import { AgentDataSourceConfiguration } from "@app/lib/models/assistant/actions/data_sources"; import { AgentTablesQueryConfigurationTable } from "@app/lib/models/assistant/actions/tables_query"; @@ -30,7 +28,6 @@ import { makeSId, } from "@app/lib/resources/string_ids"; import type { ResourceFindOptions } from "@app/lib/resources/types"; -import { getWorkspaceByModelId } from "@app/lib/workspace"; import logger from "@app/logger/logger"; import { DataSourceViewModel } from "./storage/models/data_source_view"; @@ -545,17 +542,4 @@ export class DataSourceResource extends ResourceWithSpace { ...this.makeEditedBy(this.editedByUser, this.editedAt), }; } - - async toPokeJSON(): Promise { - const workspace = await getWorkspaceByModelId(this.workspaceId); - - return { - ...this.toJSON(), - link: workspace - ? `${config.getClientFacingUrl()}/poke/${workspace.sId}/data_sources/${this.sId}` - : null, - name: `Data Source View (${this.name})`, - space: this.space.toPokeJSON(), - }; - } } diff --git a/front/lib/resources/data_source_view_resource.ts b/front/lib/resources/data_source_view_resource.ts index afb6cbc5ea52..0e2024188185 100644 --- a/front/lib/resources/data_source_view_resource.ts +++ b/front/lib/resources/data_source_view_resource.ts @@ -6,7 +6,6 @@ import type { DataSourceViewCategory, DataSourceViewType, ModelId, - PokeDataSourceViewType, Result, } from "@dust-tt/types"; import { formatUserFullName, Ok, removeNulls } from "@dust-tt/types"; @@ -20,7 +19,6 @@ import type { import { Op } from "sequelize"; import { getDataSourceViewUsage } from "@app/lib/api/agent_data_sources"; -import config from "@app/lib/api/config"; import type { Authenticator } from "@app/lib/auth"; import { isFolder, isWebsite } from "@app/lib/data_sources"; import { AgentDataSourceConfiguration } from "@app/lib/models/assistant/actions/data_sources"; @@ -40,7 +38,6 @@ import { makeSId, } from "@app/lib/resources/string_ids"; import type { ResourceFindOptions } from "@app/lib/resources/types"; -import { getWorkspaceByModelId } from "@app/lib/workspace"; const getDataSourceCategory = ( dataSourceResource: DataSourceResource @@ -602,18 +599,4 @@ export class DataSourceViewResource extends ResourceWithSpace { - const workspace = await getWorkspaceByModelId(this.workspaceId); - - return { - ...this.toJSON(), - dataSource: await this.dataSource.toPokeJSON(), - link: workspace - ? `${config.getClientFacingUrl()}/poke/${workspace.sId}/spaces/${this.space.sId}/data_source_views/${this.sId}` - : null, - name: `Data Source (${this.dataSource.name})`, - space: this.space.toPokeJSON(), - }; - } } diff --git a/front/lib/resources/membership_resource.ts b/front/lib/resources/membership_resource.ts index 64fd64622552..0f409bbe2efb 100644 --- a/front/lib/resources/membership_resource.ts +++ b/front/lib/resources/membership_resource.ts @@ -18,7 +18,7 @@ import { Op } from "sequelize"; import type { PaginationParams } from "@app/lib/api/pagination"; import type { Authenticator } from "@app/lib/auth"; -import { canForceUserRole } from "@app/lib/development"; +import { showDebugTools } from "@app/lib/development"; import { BaseResource } from "@app/lib/resources/base_resource"; import { MembershipModel } from "@app/lib/resources/storage/models/membership"; import type { ReadonlyAttributesType } from "@app/lib/resources/storage/types"; @@ -477,7 +477,7 @@ export class MembershipResource extends BaseResource { }); if (adminsCount < 2) { - if (canForceUserRole(workspace)) { + if (showDebugTools(workspace)) { logger.warn( { panic: false, diff --git a/front/lib/resources/space_resource.ts b/front/lib/resources/space_resource.ts index 563ae8479c4d..c3516b75f8ec 100644 --- a/front/lib/resources/space_resource.ts +++ b/front/lib/resources/space_resource.ts @@ -1,6 +1,5 @@ import type { ModelId, - PokeSpaceType, ResourcePermission, Result, SpaceType, @@ -647,11 +646,4 @@ export class SpaceResource extends BaseResource { updatedAt: this.updatedAt.getTime(), }; } - - toPokeJSON(): PokeSpaceType { - return { - ...this.toJSON(), - groups: this.groups.map((group) => group.toJSON()), - }; - } } diff --git a/front/pages/api/poke/workspaces/[wId]/conversations/[cId]/index.ts b/front/pages/api/poke/workspaces/[wId]/conversations/[cId]/index.ts index e90edad1b409..63438be1b2c1 100644 --- a/front/pages/api/poke/workspaces/[wId]/conversations/[cId]/index.ts +++ b/front/pages/api/poke/workspaces/[wId]/conversations/[cId]/index.ts @@ -4,10 +4,10 @@ import type { } from "@dust-tt/types"; import type { NextApiRequest, NextApiResponse } from "next"; -import { getPokeConversation } from "@app/lib/api/assistant/conversation"; import { apiErrorForConversation } from "@app/lib/api/assistant/conversation/helper"; import { withSessionAuthentication } from "@app/lib/api/auth_wrappers"; import { Authenticator, getSession } from "@app/lib/auth"; +import { getPokeConversation } from "@app/lib/poke/conversations"; import { apiError } from "@app/logger/withlogging"; export type GetConversationResponseBody = { diff --git a/front/pages/api/w/[wId]/members/[uId]/index.ts b/front/pages/api/w/[wId]/members/[uId]/index.ts index 222f6feabc2c..beeeb520131a 100644 --- a/front/pages/api/w/[wId]/members/[uId]/index.ts +++ b/front/pages/api/w/[wId]/members/[uId]/index.ts @@ -8,7 +8,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { withSessionAuthenticationForWorkspace } from "@app/lib/api/auth_wrappers"; import { getUserForWorkspace } from "@app/lib/api/user"; import type { Authenticator } from "@app/lib/auth"; -import { canForceUserRole } from "@app/lib/development"; +import { showDebugTools } from "@app/lib/development"; import { MembershipResource } from "@app/lib/resources/membership_resource"; import { ServerSideTracking } from "@app/lib/tracking/server"; import { apiError } from "@app/logger/withlogging"; @@ -27,7 +27,7 @@ async function handler( // Allow Dust Super User to force role for testing const allowForSuperUserTesting = - canForceUserRole(owner) && + showDebugTools(owner) && auth.isDustSuperUser() && req.body.force === "true"; diff --git a/front/pages/poke/[wId]/spaces/[spaceId]/data_source_views/[dsvId]/index.tsx b/front/pages/poke/[wId]/spaces/[spaceId]/data_source_views/[dsvId]/index.tsx index 2798d7248b1e..5d9b2c641e51 100644 --- a/front/pages/poke/[wId]/spaces/[spaceId]/data_source_views/[dsvId]/index.tsx +++ b/front/pages/poke/[wId]/spaces/[spaceId]/data_source_views/[dsvId]/index.tsx @@ -7,6 +7,7 @@ import { DataSourceViewSelector } from "@app/components/data_source_view/DataSou import { ViewDataSourceViewTable } from "@app/components/poke/data_source_views/view"; import { PluginList } from "@app/components/poke/plugins/PluginList"; import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; +import { dataSourceViewToPokeJSON } from "@app/lib/poke/utils"; import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource"; import PokeLayout from "@app/pages/poke/PokeLayout"; import { usePokeDataSourceViewContentNodes } from "@app/poke/swr/data_source_views"; @@ -36,7 +37,7 @@ export const getServerSideProps = withSuperUserAuthRequirements<{ return { props: { owner, - dataSourceView: await dataSourceView.toPokeJSON(), + dataSourceView: await dataSourceViewToPokeJSON(dataSourceView), }, }; }); diff --git a/front/pages/poke/[wId]/spaces/[spaceId]/index.tsx b/front/pages/poke/[wId]/spaces/[spaceId]/index.tsx index 1c5b05036f3d..da044d691ebc 100644 --- a/front/pages/poke/[wId]/spaces/[spaceId]/index.tsx +++ b/front/pages/poke/[wId]/spaces/[spaceId]/index.tsx @@ -10,6 +10,7 @@ import { MembersDataTable } from "@app/components/poke/members/table"; import { ViewSpaceViewTable } from "@app/components/poke/spaces/view"; import { getMembers } from "@app/lib/api/workspace"; import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; +import { spaceToPokeJSON } from "@app/lib/poke/utils"; import { SpaceResource } from "@app/lib/resources/space_resource"; import type { UserResource } from "@app/lib/resources/user_resource"; import PokeLayout from "@app/pages/poke/PokeLayout"; @@ -61,7 +62,7 @@ export const getServerSideProps = withSuperUserAuthRequirements<{ props: { members: userWithWorkspaces, owner, - space: space.toPokeJSON(), + space: spaceToPokeJSON(space), }, }; });