Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/llm-error-pages/guidance-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ import {
} from '../utils/report-uploader.js';
import {
generateReportingPeriods,
generatePeriodIdentifier,
getS3Config,
toPathOnly,
SPREADSHEET_COLUMNS,
} from './utils.js';

function derivePeriodFromBrokenLinks(brokenLinks = []) {
const periodRegex = /llm-404-suggestion-(w\d{2}-\d{4})-/;
for (const link of brokenLinks) {
const match = periodRegex.exec(link.suggestionId || '');
if (match && match[1]) {
return match[1];
}
}
return null;
}

/**
* Handles Mystique responses for LLM error pages and updates suggestions with AI data
* @param {Object} message - Message from Mystique with AI suggestions
Expand Down Expand Up @@ -53,8 +63,8 @@ export default async function handler(message, context) {
// Read-modify-write the weekly 404 Excel file in SharePoint
try {
const sharepointClient = await createLLMOSharepointClient(context);
const week = generateReportingPeriods().weeks[0];
const derivedPeriod = generatePeriodIdentifier(week.startDate, week.endDate);
const derivedPeriod = derivePeriodFromBrokenLinks(brokenLinks)
|| generateReportingPeriods(new Date(), [-1]).weeks[0].periodIdentifier;
const llmoFolder = site.getConfig()?.getLlmoDataFolder?.() || s3Config.customerName;
const outputDir = `${llmoFolder}/agentic-traffic`;
const filename = `agentictraffic-errors-404-${derivedPeriod}.xlsx`;
Expand Down
Loading