feat: enrich AI stream with replyToMessageId, sourceGroupName, organizationId + tenant/source filters

- Extract quotedPlatformMsgId from Baileys contextInfo.stanzaId in normalizer
- Thread quotedPlatformMsgId through IngestJobData → ingest processor → Message record
- Widen ingest processor group/tenant selects to include name and organizationId
- Add replyToMessageId, sourceGroupName, organizationId to StreamMessagePayload and XADD
- Update StreamRecord, parseFields, and streamMessages in AI stream service with new fields
- Add optional ?tenant= and ?source= SSE filters; cursor advances for filtered entries
  so Last-Event-ID resume remains accurate across reconnects

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 01:07:42 +05:30
parent 5a0f7aa58f
commit e598073dc7
7 changed files with 39 additions and 15 deletions
+6 -2
View File
@@ -19,7 +19,7 @@ export async function processIngestJob(
// Defensive: drop messages from non-CLAIMED groups
const group = await prisma.group.findUnique({
where: { id: job.sourceGroupId },
select: { claimStatus: true },
select: { claimStatus: true, name: true },
});
if (!group || group.claimStatus !== 'CLAIMED') {
return;
@@ -28,7 +28,7 @@ export async function processIngestJob(
// Safety net: drop if tenant is inactive or paused
const tenant = await prisma.tenant.findUnique({
where: { id: job.tenantId },
select: { isActive: true, isForwardingPaused: true },
select: { isActive: true, isForwardingPaused: true, organizationId: true },
});
if (!tenant || !tenant.isActive || tenant.isForwardingPaused) {
return;
@@ -86,6 +86,7 @@ export async function processIngestJob(
content: job.content,
tags: job.tags,
status: initialStatus,
quotedPlatformMsgId: job.quotedPlatformMsgId,
},
update: {},
});
@@ -100,6 +101,9 @@ export async function processIngestJob(
senderJid: job.senderJid,
senderName: job.senderName,
sourceGroupId: job.sourceGroupId,
sourceGroupName: group.name,
organizationId: tenant.organizationId ?? undefined,
replyToMessageId: job.quotedPlatformMsgId,
tags: job.tags,
effectiveAction: job.effectiveAction ?? null,
timestamp: new Date().toISOString(),