Fix MVP audit evidence pipeline

This commit is contained in:
2026-06-08 08:33:15 +02:00
parent a45b92ea0a
commit ff18fc202e
16 changed files with 771 additions and 52 deletions

View File

@@ -252,32 +252,49 @@ export const getAuditGenerationEvidence = internalQuery({
return null;
}
const runIdFilter = {
table: "by_runId" as const,
value: args.runId,
};
const leadIdFilter = {
table: "by_leadId" as const,
value: lead._id,
};
const latestSuccessfulEnrichmentRun = await ctx.db
.query("agentRuns")
.withIndex("by_type_and_status_and_leadId", (q) =>
q
.eq("type", "website_enrichment")
.eq("status", "succeeded")
.eq("leadId", lead._id),
)
.order("desc")
.take(1);
const enrichmentEvidenceRunId =
latestSuccessfulEnrichmentRun[0]?._id ?? args.runId;
const crawlPagesByRun = await ctx.db
.query("websiteCrawlPages")
.withIndex("by_runId", (q) => q.eq("runId", runIdFilter.value))
.withIndex("by_runId", (q) => q.eq("runId", enrichmentEvidenceRunId))
.order("desc")
.take(40);
const technicalChecksByRun = await ctx.db
.query("websiteTechnicalChecks")
.withIndex("by_runId", (q) => q.eq("runId", runIdFilter.value))
.withIndex("by_runId", (q) => q.eq("runId", enrichmentEvidenceRunId))
.order("desc")
.take(80);
const screenshotsByRun = await ctx.db
const auditCaptureScreenshotsByRun = await ctx.db
.query("websiteCrawlScreenshots")
.withIndex("by_runId", (q) => q.eq("runId", runIdFilter.value))
.withIndex("by_runId", (q) => q.eq("runId", args.runId))
.order("desc")
.take(20);
const enrichmentScreenshotsByRun =
enrichmentEvidenceRunId === args.runId
? []
: await ctx.db
.query("websiteCrawlScreenshots")
.withIndex("by_runId", (q) => q.eq("runId", enrichmentEvidenceRunId))
.order("desc")
.take(20);
const pageSpeedByRun = run.auditId
? await ctx.db
@@ -293,7 +310,7 @@ export const getAuditGenerationEvidence = internalQuery({
const crawlPages = crawlPagesByRun;
const technicalChecks = technicalChecksByRun;
const screenshots = screenshotsByRun;
const screenshots = [...auditCaptureScreenshotsByRun, ...enrichmentScreenshotsByRun];
return {
lead: {