-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henry Fontanier
committed
Dec 9, 2024
1 parent
5c6aa4e
commit 24e67bb
Showing
27 changed files
with
310 additions
and
682 deletions.
There are no files selected for viewing
File renamed without changes.
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
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
front/lib/document_upsert_hooks/hooks/document_tracker/consts.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { ConnectorProvider } from "@dust-tt/types"; | ||
import { assertNever } from "@dust-tt/types"; | ||
|
||
export function isConnectorTypeTrackable( | ||
connectorType: ConnectorProvider | ||
): boolean { | ||
switch (connectorType) { | ||
case "google_drive": | ||
case "github": | ||
case "notion": | ||
case "microsoft": | ||
case "confluence": | ||
case "intercom": | ||
case "webcrawler": | ||
case "snowflake": | ||
case "zendesk": | ||
return true; | ||
case "slack": | ||
return false; | ||
default: | ||
assertNever(connectorType); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
front/lib/document_upsert_hooks/hooks/document_tracker/index.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getFeatureFlags } from "@app/lib/auth"; | ||
import type { DocumentUpsertHook } from "@app/lib/document_upsert_hooks/hooks"; | ||
import { launchRunDocumentTrackerWorkflow } from "@app/temporal/document_tracker/client"; | ||
|
||
// this hook is meant to suggest changes to tracked documents | ||
// based on new information that has been added to other documents | ||
// it should run on upserts if the workspace has tracked docs | ||
export const documentTrackerUpsertHook: DocumentUpsertHook = { | ||
type: "document_tracker", | ||
fn: async ({ | ||
auth, | ||
dataSourceId, | ||
documentId, | ||
documentHash, | ||
dataSourceConnectorProvider, | ||
}) => { | ||
const owner = auth.workspace(); | ||
if (!owner) { | ||
return; | ||
} | ||
|
||
const flags = await getFeatureFlags(owner); | ||
if (!flags.includes("document_tracker")) { | ||
return; | ||
} | ||
|
||
await launchRunDocumentTrackerWorkflow({ | ||
workspaceId: owner.sId, | ||
dataSourceId, | ||
documentId, | ||
documentHash, | ||
dataSourceConnectorProvider, | ||
}); | ||
}, | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { ConnectorProvider, UpsertContext } from "@dust-tt/types"; | ||
|
||
import type { Authenticator } from "@app/lib/auth"; | ||
import { documentTrackerUpsertHook } from "@app/lib/document_upsert_hooks/hooks/document_tracker"; | ||
import { wakeLock } from "@app/lib/wake_lock"; | ||
import logger from "@app/logger/logger"; | ||
|
||
const DUST_WORKSPACE = "0ec9852c2f"; | ||
|
||
const _hooks = { | ||
document_tracker_suggest_changes: documentTrackerUpsertHook, | ||
} as const; | ||
|
||
export const DOCUMENT_UPSERT_HOOKS: Array<DocumentUpsertHook> = | ||
Object.values(_hooks); | ||
|
||
export type DocumentUpsertHook = { | ||
type: string; | ||
fn: (params: { | ||
auth: Authenticator; | ||
dataSourceId: string; | ||
documentId: string; | ||
documentHash: string; | ||
dataSourceConnectorProvider: ConnectorProvider | null; | ||
upsertContext?: UpsertContext; | ||
}) => Promise<void>; | ||
}; | ||
|
||
export function runDocumentUpsertHooks( | ||
params: Parameters<DocumentUpsertHook["fn"]>[0] | ||
): void { | ||
// TODO(document-tracker): remove this once we have a way to enable/disable | ||
if (params.auth.workspace()?.sId !== DUST_WORKSPACE) { | ||
return; | ||
} | ||
|
||
for (const hook of DOCUMENT_UPSERT_HOOKS) { | ||
void wakeLock(async () => { | ||
try { | ||
await hook.fn(params); | ||
} catch (error) { | ||
logger.error( | ||
{ hookType: hook.type, error }, | ||
`Error running document upsert hook` | ||
); | ||
} | ||
}); | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
front/lib/documents_post_process_hooks/hooks/document_tracker/consts.ts
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
front/lib/documents_post_process_hooks/hooks/document_tracker/index.ts
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
front/lib/documents_post_process_hooks/hooks/document_tracker/lib.ts
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
front/lib/documents_post_process_hooks/hooks/document_tracker/suggest_changes/index.ts
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
...lib/documents_post_process_hooks/hooks/document_tracker/update_tracked_documents/index.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.