-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add link to maintained document in tracker email (#9944)
Co-authored-by: Henry Fontanier <[email protected]>
- Loading branch information
1 parent
3068af8
commit d857ad6
Showing
5 changed files
with
205 additions
and
40 deletions.
There are no files selected for viewing
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
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,101 @@ | ||
import { sendTrackerWithGenerationEmail } from "@app/lib/api/tracker"; | ||
import { TrackerGenerationModel } from "@app/lib/models/doc_tracker"; | ||
import { frontSequelize } from "@app/lib/resources/storage"; | ||
import { DataSourceModel } from "@app/lib/resources/storage/models/data_source"; | ||
import { isEmailValid } from "@app/lib/utils"; | ||
import { makeScript } from "@app/scripts/helpers"; | ||
|
||
makeScript( | ||
{ | ||
generationIds: { | ||
type: "array", | ||
demandOption: true, | ||
description: "List of generation IDs", | ||
}, | ||
email: { | ||
type: "string", | ||
demandOption: true, | ||
description: "Email address to send to", | ||
}, | ||
}, | ||
async ({ execute, generationIds, email }, logger) => { | ||
try { | ||
// Validate email | ||
if (!isEmailValid(email)) { | ||
throw new Error("Invalid email address"); | ||
} | ||
|
||
// Parse and validate generation IDs | ||
const ids = generationIds.map((id) => parseInt(id)); | ||
if (ids.some((id) => isNaN(id))) { | ||
throw new Error("Invalid generation IDs - must be numbers"); | ||
} | ||
|
||
if (execute) { | ||
// Fetch generations with their data sources | ||
const generations = await TrackerGenerationModel.findAll({ | ||
where: { | ||
id: ids, | ||
}, | ||
include: [ | ||
{ | ||
model: DataSourceModel, | ||
required: true, | ||
}, | ||
{ | ||
model: DataSourceModel, | ||
as: "maintainedDocumentDataSource", | ||
required: false, | ||
}, | ||
], | ||
}); | ||
|
||
if (generations.length === 0) { | ||
throw new Error("No generations found with the provided IDs"); | ||
} | ||
|
||
// Convert to TrackerGenerationToProcess format | ||
const generationsToProcess = generations.map((g) => ({ | ||
id: g.id, | ||
content: g.content, | ||
thinking: g.thinking, | ||
documentId: g.documentId, | ||
dataSource: { | ||
id: g.dataSource.id, | ||
name: g.dataSource.name, | ||
dustAPIProjectId: g.dataSource.dustAPIProjectId, | ||
dustAPIDataSourceId: g.dataSource.dustAPIDataSourceId, | ||
}, | ||
maintainedDocumentId: g.maintainedDocumentId, | ||
maintainedDataSource: g.maintainedDocumentDataSource | ||
? { | ||
id: g.maintainedDocumentDataSource.id, | ||
name: g.maintainedDocumentDataSource.name, | ||
dustAPIProjectId: | ||
g.maintainedDocumentDataSource.dustAPIProjectId, | ||
dustAPIDataSourceId: | ||
g.maintainedDocumentDataSource.dustAPIDataSourceId, | ||
} | ||
: null, | ||
})); | ||
|
||
// Send email | ||
await sendTrackerWithGenerationEmail({ | ||
name: "Manual Generation Email", | ||
recipient: email, | ||
generations: generationsToProcess, | ||
localLogger: logger, | ||
}); | ||
|
||
logger.info({}, "Email sent successfully"); | ||
} else { | ||
logger.info( | ||
{ generationIds: ids, email }, | ||
"Dry run - would send email with these parameters" | ||
); | ||
} | ||
} finally { | ||
await frontSequelize.close(); | ||
} | ||
} | ||
); |
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