Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tdraier committed Aug 11, 2024
1 parent 091becf commit 53b782d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
6 changes: 4 additions & 2 deletions front/lib/api/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type LightContentNode = {
lastUpdatedAt: number | null;
};

export type GetDataSourceContentResponseBody = {
export type GetDataSourceOrViewContentResponseBody = {
nodes: LightContentNode[];
};

Expand Down Expand Up @@ -92,7 +92,9 @@ export const getDataSourceCategory = (

export const getContentHandler = async (
req: NextApiRequest,
res: NextApiResponse<WithAPIErrorResponse<GetDataSourceContentResponseBody>>,
res: NextApiResponse<
WithAPIErrorResponse<GetDataSourceOrViewContentResponseBody>
>,
dataSource: DataSourceResource,
rootIds: string[] | null
): Promise<void> => {
Expand Down
60 changes: 46 additions & 14 deletions front/lib/swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useSWR from "swr";
import useSWRInfinite from "swr/infinite";

import type { FetchConversationMessagesResponse } from "@app/lib/api/assistant/messages";
import type { GetDataSourceOrViewContentResponseBody } from "@app/lib/api/vaults";
import { COMMIT_HASH } from "@app/lib/commit-hash";
import type { GetPokePlansResponseBody } from "@app/pages/api/poke/plans";
import type { GetPokeWorkspacesResponseBody } from "@app/pages/api/poke/workspaces";
Expand Down Expand Up @@ -1328,18 +1329,49 @@ export function useVaultDataSourceOrViews({
vaultsDataSourcesFetcher
);

console.log(data, error);
if (data && data.dataSources) {
return {
vaultDataSources: data ? data.dataSources : null,
isVaultDataSourcesLoading: !error && !data,
isVaultDataSourcesError: error,
};
} else {
return {
vaultDataSources: data ? data.dataSourceViews : null,
isVaultDataSourcesLoading: !error && !data,
isVaultDataSourcesError: error,
};
}
const vaultDataSourceOrViews =
type === "data_sources"
? (data as GetVaultDataSourcesResponseBody)?.dataSources
: (data as GetVaultDataSourceViewsResponseBody)?.dataSourceViews;

return {
vaultDataSourceOrViews,
isVaultDataSourceOrViewsLoading: !error && !data,
isVaultDataSourceOrViewsError: error,
};
}

export function useVaultDataSourceOrViewContent({
workspaceId,
vaultId,
type,
dataSourceOrViewId,
viewType,
parentId,
disabled,
}: {
workspaceId: string;
vaultId: string;
type: "data_sources" | "data_source_views";
dataSourceOrViewId: string;
viewType: ContentNodesViewType;
parentId: string | undefined;
disabled?: boolean;
}) {
const vaultsDataSourcesFetcher: Fetcher<GetDataSourceOrViewContentResponseBody> =
fetcher;
const qs =
`?viewType=${viewType}` + (parentId ? `&parentId=${parentId}` : "");
const { data, error } = useSWRWithDefaults(
disabled
? null
: `/api/w/${workspaceId}/vaults/${vaultId}/${type}/${dataSourceOrViewId}/content${qs}`,
vaultsDataSourcesFetcher
);

return {
vaultContent: data?.nodes,
isVaultContentLoading: !error && !data,
isVaultContentError: error,
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { WithAPIErrorResponse } from "@dust-tt/types";
import type { NextApiRequest, NextApiResponse } from "next";

import type { GetDataSourceContentResponseBody } from "@app/lib/api/vaults";
import type { GetDataSourceOrViewContentResponseBody } from "@app/lib/api/vaults";
import { getContentHandler } from "@app/lib/api/vaults";
import { withSessionAuthenticationForWorkspace } from "@app/lib/api/wrappers";
import type { Authenticator } from "@app/lib/auth";
Expand All @@ -10,7 +10,9 @@ import { apiError } from "@app/logger/withlogging";

async function handler(
req: NextApiRequest,
res: NextApiResponse<WithAPIErrorResponse<GetDataSourceContentResponseBody>>,
res: NextApiResponse<
WithAPIErrorResponse<GetDataSourceOrViewContentResponseBody>
>,
auth: Authenticator
): Promise<void> {
const owner = auth.workspace();
Expand All @@ -30,7 +32,7 @@ async function handler(
);

const dataSource = dataSourceView?.dataSource;
const vault = dataSource?.vault;
const vault = dataSourceView?.vault;

if (
!dataSourceView ||
Expand Down
14 changes: 11 additions & 3 deletions types/src/front/api_handlers/public/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const ContentSchema = t.type({

export const PostDataSourceViewSchema = t.type({
name: t.string,
parentsIn: t.array(t.string),
parentsIn: t.union([t.array(t.string), t.null]),
});

export type PostDataSourceViewType = t.TypeOf<typeof PostDataSourceViewSchema>;

export const PatchDataSourceViewSchema = t.type({
parentsIn: t.array(t.string),
parentsIn: t.union([t.array(t.string), t.null]),
});

export type PatchDataSourceViewType = t.TypeOf<
Expand All @@ -41,11 +41,19 @@ export type PatchVaultRequestBodyType = t.TypeOf<
typeof PostVaultRequestBodySchema
>;

export type ResourceCategory = "managed" | "files" | "webfolder" | "apps";
export const RESOURCE_CATEGORIES = [
"managed",
"files",
"webfolder",
"apps",
] as const;

export type ResourceCategory = (typeof RESOURCE_CATEGORIES)[number];

export type ResourceInfo = {
createdAt: number;
sId: string;
name: string;
parentsIn?: string[] | null;
connectorId?: string | null;
connectorProvider?: ConnectorProvider | null;
Expand Down

0 comments on commit 53b782d

Please sign in to comment.