-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(doc tracker revival): use vaults (#8143)
Co-authored-by: Henry Fontanier <[email protected]>
- Loading branch information
1 parent
96b5076
commit 8c826cf
Showing
2 changed files
with
26 additions
and
39 deletions.
There are no files selected for viewing
50 changes: 14 additions & 36 deletions
50
front/lib/documents_post_process_hooks/hooks/document_tracker/lib.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,21 @@ | ||
import { DustAPI } from "@dust-tt/client"; | ||
import type { WorkspaceType } from "@dust-tt/types"; | ||
|
||
import config from "@app/lib/api/config"; | ||
import { prodAPICredentialsForOwner } from "@app/lib/auth"; | ||
import type { Authenticator } from "@app/lib/auth"; | ||
import { TRACKABLE_CONNECTOR_TYPES } from "@app/lib/documents_post_process_hooks/hooks/document_tracker/consts"; | ||
import logger from "@app/logger/logger"; | ||
|
||
export async function getTrackableDataSources(owner: WorkspaceType): Promise< | ||
{ | ||
workspace_id: string; | ||
data_source_id: string; | ||
}[] | ||
> { | ||
const prodCredentials = await prodAPICredentialsForOwner(owner); | ||
|
||
const prodAPI = new DustAPI( | ||
config.getDustAPIConfig(), | ||
prodCredentials, | ||
logger | ||
); | ||
import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource"; | ||
import { VaultResource } from "@app/lib/resources/vault_resource"; | ||
|
||
// Fetch data sources | ||
const dsRes = await prodAPI.getDataSources(prodAPI.workspaceId()); | ||
if (dsRes.isErr()) { | ||
throw dsRes.error; | ||
} | ||
const dataSources = dsRes.value; | ||
export async function getTrackableDataSourceViews( | ||
auth: Authenticator | ||
): Promise<DataSourceViewResource[]> { | ||
const globalVault = await VaultResource.fetchWorkspaceGlobalVault(auth); | ||
// TODO(DOC_TRACKER): | ||
const views = await DataSourceViewResource.listByVault(auth, globalVault); | ||
|
||
// Filter data sources to only include trackable ones | ||
const trackableDataSources = dataSources.filter( | ||
(ds) => | ||
ds.connectorProvider && | ||
TRACKABLE_CONNECTOR_TYPES.includes(ds.connectorProvider) | ||
const trackableViews = views.filter( | ||
(view) => | ||
view.dataSource.connectorProvider && | ||
TRACKABLE_CONNECTOR_TYPES.includes(view.dataSource.connectorProvider) | ||
); | ||
|
||
return trackableDataSources.map((ds) => ({ | ||
workspace_id: prodAPI.workspaceId(), | ||
// TODO(GROUPS_INFRA): this should pull the data source views from the global vaults (we need an | ||
// API for that). | ||
data_source_id: ds.sId, | ||
})); | ||
return trackableViews; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters