Skip to content

Commit

Permalink
Rename use-cases around upserts (#10594)
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu authored Feb 6, 2025
1 parent 28129eb commit 8b366bd
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion front/components/data_source/DocumentUploadOrEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const DocumentUploadOrEditModal = ({
});
const fileUploaderService = useFileUploaderService({
owner,
useCase: "folder_document",
useCase: "upsert_document",
});

const [editionStatus, setEditionStatus] = useState({
Expand Down
2 changes: 1 addition & 1 deletion front/components/data_source/MultipleDocumentsUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const MultipleDocumentsUpload = ({
// Used for creating files, with text extraction post-processing
const fileUploaderService = useFileUploaderService({
owner,
useCase: "folder_document",
useCase: "upsert_document",
});

const doUpsertFileAsDataSourceEntry = useUpsertFileAsDatasourceEntry(
Expand Down
2 changes: 1 addition & 1 deletion front/components/data_source/TableUploadOrEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const TableUploadOrEditModal = ({
// Get the processed file content from the file API
const fileUploaderService = useFileUploaderService({
owner,
useCase: "folder_table",
useCase: "upsert_table",
});
const [fileId, setFileId] = useState<string | null>(null);
const doUpsertFileAsDataSourceEntry = useUpsertFileAsDatasourceEntry(
Expand Down
10 changes: 4 additions & 6 deletions front/lib/api/files/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ const getProcessingFunction = ({
if (
[
"conversation",
"folder_document",
"folder_table",
"upsert_document",
"upsert_table",
"tool_output",
].includes(useCase)
) {
Expand All @@ -234,7 +234,7 @@ const getProcessingFunction = ({
case "application/vnd.ms-powerpoint":
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
case "application/pdf":
if (useCase === "conversation" || useCase === "folder_document") {
if (["conversation", "upsert_document"].includes(useCase)) {
return extractTextFromFileAndUpload;
}
break;
Expand Down Expand Up @@ -270,9 +270,7 @@ const getProcessingFunction = ({
case "text/x-perl":
case "text/x-perl-script":
if (
useCase === "conversation" ||
useCase === "folder_document" ||
useCase === "tool_output"
["conversation", "upsert_document", "tool_output"].includes(useCase)
) {
return storeRawText;
}
Expand Down
12 changes: 3 additions & 9 deletions front/lib/api/files/upsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,9 @@ const getProcessingFunction = ({

// Use isSupportedDelimitedTextContentType() everywhere to have a common source of truth
if (isSupportedDelimitedTextContentType(contentType)) {
if (
useCase === "conversation" ||
useCase === "tool_output" ||
useCase === "folder_table"
) {
if (["conversation", "tool_output", "upsert_table"].includes(useCase)) {
return upsertTableToDatasource;
} else if (useCase === "folder_document") {
} else if (useCase === "upsert_document") {
return upsertDocumentToDatasource;
} else {
return undefined;
Expand All @@ -335,9 +331,7 @@ const getProcessingFunction = ({

if (
isSupportedPlainTextContentType(contentType) &&
(useCase === "conversation" ||
useCase === "tool_output" ||
useCase === "folder_document")
["conversation", "tool_output", "upsert_document"].includes(useCase)
) {
return upsertDocumentToDatasource;
}
Expand Down
2 changes: 1 addition & 1 deletion front/lib/resources/file_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class FileResource extends BaseResource<FileModel> {
// Use-case logic

isUpsertUseCase(): boolean {
return ["folder_document", "folder_table"].includes(this.useCase);
return ["upsert_document", "upsert_table"].includes(this.useCase);
}

getBucketForVersion(version: FileVersion) {
Expand Down
2 changes: 1 addition & 1 deletion front/pages/api/w/[wId]/data_sources/[dsId]/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe("POST /api/w/[wId]/data_sources/[dsId]/files", () => {
t
);
const file = await FileFactory.csv(workspace, user, {
useCase: "folder_table",
useCase: "upsert_table",
});

req.query.dsId = dataSourceView.dataSource.sId;
Expand Down
2 changes: 1 addition & 1 deletion front/pages/api/w/[wId]/data_sources/[dsId]/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function handler(
}

// Only folder document and table upserts are supported on this endpoint.
if (!["folder_document", "folder_table"].includes(file.useCase)) {
if (!["upsert_document", "upsert_table"].includes(file.useCase)) {
return apiError(req, res, {
status_code: 400,
api_error: {
Expand Down
4 changes: 2 additions & 2 deletions front/pages/api/w/[wId]/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const FileUploadUrlRequestSchema = t.type({
useCase: t.union([
t.literal("conversation"),
t.literal("avatar"),
t.literal("folder_document"),
t.literal("folder_table"),
t.literal("upsert_document"),
t.literal("upsert_table"),
]),
useCaseMetadata: t.union([t.undefined, t.type({ conversationId: t.string })]),
});
Expand Down
2 changes: 1 addition & 1 deletion sdks/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ const FileTypeStatusSchema = FlexibleEnumSchema<
>();

const FileTypeUseCaseSchema = FlexibleEnumSchema<
"conversation" | "avatar" | "tool_output" | "folder_document" | "folder_table"
"conversation" | "avatar" | "tool_output" | "upsert_document" | "upsert_table"
>();

export const FileTypeSchema = z.object({
Expand Down
4 changes: 2 additions & 2 deletions types/src/front/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type FileUseCase =
| "conversation"
| "avatar"
| "tool_output"
| "folder_document"
| "folder_table";
| "upsert_document"
| "upsert_table";

export type FileUseCaseMetadata = {
conversationId: string;
Expand Down

0 comments on commit 8b366bd

Please sign in to comment.