aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workers/openaiWorker.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/workers/openaiWorker.ts')
-rw-r--r--apps/workers/openaiWorker.ts22
1 files changed, 18 insertions, 4 deletions
diff --git a/apps/workers/openaiWorker.ts b/apps/workers/openaiWorker.ts
index 7b0ae095..c8b2770e 100644
--- a/apps/workers/openaiWorker.ts
+++ b/apps/workers/openaiWorker.ts
@@ -19,6 +19,7 @@ import logger from "@karakeep/shared/logger";
import { buildImagePrompt, buildTextPrompt } from "@karakeep/shared/prompts";
import {
OpenAIQueue,
+ triggerRuleEngineOnEvent,
triggerSearchReindex,
triggerWebhook,
zOpenAIRequestSchema,
@@ -377,19 +378,20 @@ async function connectTags(
}
// Delete old AI tags
- await tx
+ const detachedTags = await tx
.delete(tagsOnBookmarks)
.where(
and(
eq(tagsOnBookmarks.attachedBy, "ai"),
eq(tagsOnBookmarks.bookmarkId, bookmarkId),
),
- );
+ )
+ .returning();
const allTagIds = new Set([...matchedTagIds, ...newTagIds]);
// Attach new ones
- await tx
+ const attachedTags = await tx
.insert(tagsOnBookmarks)
.values(
[...allTagIds].map((tagId) => ({
@@ -398,7 +400,19 @@ async function connectTags(
attachedBy: "ai" as const,
})),
)
- .onConflictDoNothing();
+ .onConflictDoNothing()
+ .returning();
+
+ await triggerRuleEngineOnEvent(bookmarkId, [
+ ...detachedTags.map((t) => ({
+ type: "tagRemoved" as const,
+ tagId: t.tagId,
+ })),
+ ...attachedTags.map((t) => ({
+ type: "tagAdded" as const,
+ tagId: t.tagId,
+ })),
+ ]);
});
}