Skip to content

Commit

Permalink
Continued move to dustAPIDataSourceId (#7082)
Browse files Browse the repository at this point in the history
* getDataSourceDocumentVersions

* update document methods

* dataSourceTokenize

* deleteTable, upssertTable, upsertTableRows

* getTable

* getTable

* updateTableParents

* getTableRow

* getTableRows

* deleteTableRow
  • Loading branch information
spolu authored Sep 3, 2024
1 parent f119b69 commit 879b4af
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 104 deletions.
2 changes: 1 addition & 1 deletion front/admin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ const dataSource = async (command: string, args: parseArgs.ParsedArgs) => {
}
const delRes = await coreAPI.deleteDataSourceDocument({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
documentId: args.documentId,
});
if (delRes.isErr()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export async function buildInitialActions({

const coreAPITable = await coreAPI.getTable({
projectId: dataSourceView.dataSource.dustAPIProjectId,
dataSourceName: dataSourceView.dataSource.name,
dataSourceId: dataSourceView.dataSource.dustAPIDataSourceId,
tableId: t.tableId,
});

Expand Down
2 changes: 1 addition & 1 deletion front/lib/api/data_source_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export async function getContentNodesForStaticDataSourceView(
return new Ok(documentsAsContentNodes);
} else {
const tablesRes = await coreAPI.getTables({
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
projectId: dataSource.dustAPIProjectId,
viewFilter: dataSourceView.toViewFilter(),
});
Expand Down
61 changes: 33 additions & 28 deletions front/lib/api/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
CoreAPIRow,
CoreAPIRowValue,
CoreAPITable,
DataSourceType,
Result,
WorkspaceType,
} from "@dust-tt/types";
Expand Down Expand Up @@ -58,26 +59,26 @@ export type TableOperationError =

export async function deleteTable({
owner,
projectId,
dataSourceName,
dataSource,
tableId,
}: {
owner: WorkspaceType;
projectId: string;
dataSourceName: string;
dataSource: DataSourceType;
tableId: string;
}): Promise<Result<null, TableOperationError>> {
const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);

const deleteRes = await coreAPI.deleteTable({
projectId,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
});
if (deleteRes.isErr()) {
logger.error(
{
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
dataSourceName: dataSource.name,
workspaceId: owner.id,
error: deleteRes.error,
},
Expand All @@ -101,7 +102,8 @@ export async function deleteTable({
await AgentTablesQueryConfigurationTable.destroy({
where: {
dataSourceWorkspaceId: owner.sId,
dataSourceId: dataSourceName,
// TODO(DATASOURCE_SID); state storing the datasource name
dataSourceId: dataSource.name,
tableId,
},
});
Expand All @@ -111,8 +113,7 @@ export async function deleteTable({

export async function upsertTableFromCsv({
auth,
projectId,
dataSourceName,
dataSource,
tableName,
tableDescription,
tableId,
Expand All @@ -123,8 +124,7 @@ export async function upsertTableFromCsv({
truncate,
}: {
auth: Authenticator;
projectId: string;
dataSourceName: string;
dataSource: DataSourceType;
tableName: string;
tableDescription: string;
tableId: string;
Expand Down Expand Up @@ -166,10 +166,11 @@ export async function upsertTableFromCsv({
logger.error(
{
...errorDetails,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
dataSourceName: dataSource.name,
tableName,
tableId,
projectId,
},
"CSV parsing error."
);
Expand All @@ -190,10 +191,11 @@ export async function upsertTableFromCsv({
logger.error(
{
...errorDetails,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
dataSourceName: dataSource.name,
tableName,
tableId,
projectId,
},
"CSV input validation error: too many rows."
);
Expand All @@ -202,8 +204,8 @@ export async function upsertTableFromCsv({

const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);
const tableRes = await coreAPI.upsertTable({
projectId,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
name: tableName,
description: tableDescription,
Expand All @@ -221,11 +223,12 @@ export async function upsertTableFromCsv({
logger.error(
{
...errorDetails,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
dataSourceName: dataSource.name,
workspaceId: owner.id,
tableId,
tableName,
projectId,
},
"Error upserting table in CoreAPI."
);
Expand All @@ -234,8 +237,8 @@ export async function upsertTableFromCsv({

if (csvRows) {
const rowsRes = await coreAPI.upsertTableRows({
projectId,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
rows: csvRows,
truncate,
Expand All @@ -250,18 +253,19 @@ export async function upsertTableFromCsv({
logger.error(
{
...errorDetails,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
dataSourceName: dataSource.name,
workspaceId: owner.id,
tableId,
tableName,
projectId,
},
"Error upserting rows in CoreAPI."
);

const delRes = await coreAPI.deleteTable({
projectId,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
});

Expand All @@ -270,11 +274,12 @@ export async function upsertTableFromCsv({
{
type: "internal_server_error",
coreAPIError: delRes.error,
dataSourceName,
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
dataSourceName: dataSource.name,
workspaceId: owner.id,
tableId,
tableName,
projectId,
},
"Failed to delete table after failed row upsert."
);
Expand Down
4 changes: 2 additions & 2 deletions front/lib/document_tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ export async function updateTrackedDocuments(
if (hasExistingTrackedDocs && !hasRemainingTrackedDocs) {
await coreAPI.updateDataSourceDocumentTags({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
removeTags: ["__DUST_TRACKED"],
documentId,
});
} else if (!hasExistingTrackedDocs && hasRemainingTrackedDocs) {
await coreAPI.updateDataSourceDocumentTags({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
addTags: ["__DUST_TRACKED"],
documentId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function getPreviousDocumentVersion({
const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);
const versions = await coreAPI.getDataSourceDocumentVersions({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
documentId: documentId,
limit: 1,
offset: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ async function handler(
// Create document with the Dust internal API.
const upsertRes = await coreAPI.upsertDataSourceDocument({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
documentId: req.query.documentId as string,
tags: bodyValidation.right.tags || [],
parents: bodyValidation.right.parents || [],
Expand Down Expand Up @@ -516,7 +516,7 @@ async function handler(

const delRes = await coreAPI.deleteDataSourceDocument({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
documentId: req.query.documentId as string,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function handler(
const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);
const updateRes = await coreAPI.updateDataSourceDocumentParents({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
documentId: req.query.documentId as string,
parents: req.body.parents,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function handler(
const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);
const tableRes = await coreAPI.getTable({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
});
if (tableRes.isErr()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function handler(
const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);
const updateRes = await coreAPI.updateTableParents({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId: req.query.tId as string,
parents,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async function handler(
case "GET":
const rowRes = await coreAPI.getTableRow({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
rowId,
});
Expand Down Expand Up @@ -201,7 +201,7 @@ async function handler(
case "DELETE":
const deleteRes = await coreAPI.deleteTableRow({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
rowId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async function handler(

const listRes = await coreAPI.getTableRows({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
offset,
limit,
Expand Down Expand Up @@ -317,7 +317,7 @@ async function handler(
});
const upsertRes = await coreAPI.upsertTableRows({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId: tableId,
rows: rowsToUpsert,
truncate,
Expand Down Expand Up @@ -346,7 +346,7 @@ async function handler(
// Upsert is succesful, retrieve the updated table.
const tableRes = await coreAPI.getTable({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
});
if (tableRes.isErr()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async function handler(
case "GET":
const tablesRes = await coreAPI.getTables({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
});

if (tablesRes.isErr()) {
Expand Down Expand Up @@ -230,7 +230,7 @@ async function handler(

const tRes = await coreAPI.getTables({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
});

if (tRes.isErr()) {
Expand Down Expand Up @@ -265,7 +265,7 @@ async function handler(

const upsertRes = await coreAPI.upsertTable({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
name,
description,
Expand Down
2 changes: 1 addition & 1 deletion front/pages/api/v1/w/[wId]/data_sources/[name]/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function handler(
const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);
const coreTokenizeRes = await coreAPI.dataSourceTokenize({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
text,
});
if (coreTokenizeRes.isErr()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async function handler(
// Create document with the Dust internal API.
const upsertRes = await coreAPI.upsertDataSourceDocument({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
documentId: req.query.documentId as string,
tags,
parents: bodyValidation.right.parents || [],
Expand Down Expand Up @@ -283,7 +283,7 @@ async function handler(

const deleteRes = await coreAPI.deleteDataSourceDocument({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
documentId: req.query.documentId as string,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function handler(
const coreAPI = new CoreAPI(config.getCoreAPIConfig(), logger);
const tableRes = await coreAPI.getTable({
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSourceId: dataSource.dustAPIDataSourceId,
tableId,
});
if (tableRes.isErr()) {
Expand Down Expand Up @@ -134,8 +134,7 @@ export async function handleDeleteTableByIdRequest(
) {
const delRes = await deleteTable({
owner,
projectId: dataSource.dustAPIProjectId,
dataSourceName: dataSource.name,
dataSource,
tableId,
});

Expand Down
Loading

0 comments on commit 879b4af

Please sign in to comment.