Skip to content

Commit 308063d

Browse files
Merge pull request #238 from Deodat-Lawson/feature/predictive-document-analysis-improvement
fix test
2 parents 6a7954b + 17d829a commit 308063d

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/app/api/agents/predictive-document-analysis/services/analysisEngine.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function createAnalysisPrompt(
162162
163163
If there are no notable insights, return an empty insights array.
164164
165-
${guidanceByType[specification.type] || guidanceByType.general}
165+
${guidanceByType[specification.type] ?? guidanceByType.general}
166166
167167
${analysisInstructions}
168168
@@ -429,12 +429,12 @@ export async function analyzeDocumentChunks(
429429
]);
430430

431431
const llmInsights: DocumentInsight[] = chunkResults.flatMap(
432-
result => (result.insights ?? []) as DocumentInsight[],
432+
result => result.insights ?? [],
433433
);
434434

435435
const combinedResult: PredictiveAnalysisResult = {
436-
missingDocuments: chunkResults.flatMap(result => result.missingDocuments || []),
437-
recommendations: chunkResults.flatMap(result => result.recommendations || []),
436+
missingDocuments: chunkResults.flatMap(result => result.missingDocuments ?? []),
437+
recommendations: chunkResults.flatMap(result => result.recommendations ?? []),
438438
};
439439

440440
combinedResult.missingDocuments = filterNonFindingDocuments(combinedResult.missingDocuments);
@@ -772,13 +772,13 @@ function promoteStrongRecommendations(
772772
const matchesPhrase = PROMOTION_PHRASES.some(p => lower.includes(p));
773773
if (!matchesPhrase) continue;
774774

775-
const nameMatch = rec.match(NAMED_DOC_PATTERN);
775+
const nameMatch = NAMED_DOC_PATTERN.exec(rec);
776776
const docName = (nameMatch?.[1] ?? nameMatch?.[2] ?? '').trim();
777777
if (!docName || docName.length < 3) continue;
778778

779779
if (existingNames.has(docName.toLowerCase())) continue;
780780

781-
const pageMatch = rec.match(PAGE_PATTERN);
781+
const pageMatch = PAGE_PATTERN.exec(rec);
782782
const page = pageMatch ? parseInt(pageMatch[1]!, 10) : 1;
783783

784784
promoted.push({

src/app/api/agents/predictive-document-analysis/utils/insightExtractors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function extractSurroundingSentence(text: string, matchIndex: number, matchLengt
4141

4242
let end = matchIndex + matchLength;
4343
const searchForward = text.slice(end, end + 300);
44-
const fwdMatch = searchForward.match(sentenceBreak);
44+
const fwdMatch = sentenceBreak.exec(searchForward);
4545
if (fwdMatch?.index !== undefined) {
4646
end = end + fwdMatch.index + fwdMatch[0].length;
4747
} else {
@@ -305,7 +305,7 @@ function buildResourceTitle(url: string, context: string, hostname: string): str
305305
return `Watch: Video on ${hostname.replace(/^www\./, '')}`;
306306
}
307307

308-
const actionMatch = context.match(RESOURCE_ACTION_RE);
308+
const actionMatch = RESOURCE_ACTION_RE.exec(context);
309309
if (actionMatch) {
310310
const afterAction = context.slice((actionMatch.index ?? 0) + actionMatch[0].length).trim();
311311
const clean = afterAction.replace(/https?:\/\/[^\s]+/g, '').trim();

src/app/employer/documents/components/DocumentSanityChecker.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function LinkCard({ doc }: { doc: MissingDocument }) {
203203
)}
204204
>
205205
{faviconDomain ? (
206+
/* eslint-disable-next-line @next/next/no-img-element */
206207
<img
207208
src={`https://www.google.com/s2/favicons?sz=32&domain=${faviconDomain}`}
208209
alt=""
@@ -331,6 +332,7 @@ function InsightCard({
331332
className="flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] font-semibold text-blue-600 dark:text-blue-400 bg-blue-50 dark:bg-blue-900/20 hover:bg-blue-100 dark:hover:bg-blue-900/30 transition-all duration-150"
332333
>
333334
{faviconHost ? (
335+
/* eslint-disable-next-line @next/next/no-img-element */
334336
<img
335337
src={`https://www.google.com/s2/favicons?sz=32&domain=${faviconHost}`}
336338
alt=""
@@ -383,7 +385,10 @@ export function DocumentSanityChecker({
383385
return pages.size > 1;
384386
}, [issues]);
385387

386-
const insights = predictiveAnalysis?.analysis.insights ?? [];
388+
const insights = useMemo(
389+
() => predictiveAnalysis?.analysis.insights ?? [],
390+
[predictiveAnalysis?.analysis.insights],
391+
);
387392
const recommendations = predictiveAnalysis?.analysis.recommendations ?? [];
388393
const resolved = predictiveAnalysis?.analysis.resolvedDocuments ?? [];
389394
const webRefs = predictiveAnalysis?.analysis.suggestedRelatedDocuments ?? [];

0 commit comments

Comments
 (0)