Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | 8x 8x 8x 8x 8x 8x 8x 8x 8x 33x 399x 422x 126x 100x 36x 5x 20x 11x 11x 11x 11x 12x 12x 12x 12x 11x 11x 11x 20x 20x 66x 12x 12x 12x 12x 20x 11x 20x 20x 20x 1x 19x 17x 20x 20x 20x 13x 13x 1x 1x 5x 1x 5x 1x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 19x 19x 19x 19x 1x 3x 3x 3x 3x 5x 5x 1x 4x 2x 2x 1x 3x 8x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module Generators/Strategies/CommitteeReportsStrategy
* @description Article strategy for the Committee Reports article type.
* Fetches data for each featured committee in parallel and renders an
* effectiveness and activity overview article.
*/
import type { EuropeanParliamentMCPClient } from '../../mcp/ep-mcp-client.js';
import { ArticleCategory } from '../../types/index.js';
import type { LanguageCode, CommitteeData, EPFeedData } from '../../types/index.js';
import {
COMMITTEE_REPORTS_TITLES,
COMMITTEE_ANALYSIS_CONTENT_STRINGS,
getLocalizedString,
} from '../../constants/languages.js';
import {
computeRollingDateRange,
fetchCommitteeData,
fetchEPFeedData,
} from '../pipeline/fetch-stage.js';
import {
FEATURED_COMMITTEES,
isPlaceholderCommitteeData,
PLACEHOLDER_CHAIR,
PLACEHOLDER_MEMBERS,
} from '../committee-helpers.js';
import { escapeHTML } from '../../utils/file-utils.js';
import { buildDeepAnalysisSection } from '../deep-analysis-content.js';
import {
buildCommitteeAnalysis,
buildCommitteeSwot,
buildCommitteeDashboard,
} from '../analysis-builders.js';
import { buildSwotSection } from '../swot-content.js';
import { buildDashboardSection } from '../dashboard-content.js';
import type { ArticleStrategy, ArticleData, ArticleMetadata } from './article-strategy.js';
import type { ArticleSource } from '../../types/index.js';
/** European Parliament home-page URL used as source reference */
const EP_SOURCE_URL = 'https://www.europarl.europa.eu';
/** European Parliament display name for source titles and article lede */
const EP_DISPLAY_NAME = 'European Parliament';
/** Keywords shared by all Committee Reports articles */
const COMMITTEE_REPORTS_KEYWORDS = ['committee', 'EU Parliament', 'legislation'] as const;
/** Source reference included in every committee reports article */
const COMMITTEE_REPORTS_SOURCES: readonly ArticleSource[] = [
{ title: EP_DISPLAY_NAME, url: EP_SOURCE_URL },
];
// ─── Data payload ─────────────────────────────────────────────────────────────
/** Data fetched and pre-processed by {@link CommitteeReportsStrategy} */
export interface CommitteeReportsArticleData extends ArticleData {
/** Resolved data for each featured committee */
readonly committeeDataList: readonly CommitteeData[];
/** EP feed data for enrichment (when available) */
readonly feedData?: EPFeedData | undefined;
}
// ─── Adopted-texts categorization ─────────────────────────────────────────────
/**
* Narrow union type for the committee theme category keys used when
* grouping and displaying adopted texts.
*/
export type CommitteeTheme = 'ENVI' | 'ECON' | 'AFET' | 'LIBE' | 'AGRI' | 'OTHER';
// Keyword lists are pre-normalized to lowercase so that each call to
// categorizeAdoptedText only needs to lowercase the title once.
//
// LIBE is checked before AFET so that human-rights and human-trafficking
// titles are correctly classified under civil liberties even when the title
// also mentions a country (e.g. "Ukraine") that would match AFET.
// Both LIBE and AFET are checked before AGRI so that person-name false
// positives (e.g. "Bobi Wine" matching the agricultural keyword "wine")
// are avoided.
// AGRI is then checked before ENVI so that titles containing 'agri-food' are
// not incorrectly captured by ENVI's broader 'food' keyword.
/** Lowercase keywords that map an adopted-text title to the AFET theme group */
export const AFET_KEYWORDS: readonly string[] = [
'foreign affairs',
'foreign policy',
'security policy',
'security cooperation',
'defence',
'defense',
'sanctions',
'magnitsky',
'ukraine',
'aggression',
'peace agreement',
'peace process',
'peace mission',
'peace operation',
'post-election',
'opposition leader',
'threats against',
];
/** Lowercase keywords that map an adopted-text title to the LIBE theme group */
export const LIBE_KEYWORDS: readonly string[] = [
'civil liberties',
'civil rights',
'justice and home affairs',
'justice cooperation',
'criminal justice',
'fundamental rights',
'human rights',
'human trafficking',
"workers' rights",
'safe countries',
'safe third',
'asylum',
'migration',
];
/** Lowercase keywords that map an adopted-text title to the AGRI theme group */
export const AGRI_KEYWORDS: readonly string[] = [
'agriculture',
'wine',
'agri-food',
'mercosur',
'rural',
'farming',
'fisheries',
];
/** Lowercase keywords that map an adopted-text title to the ENVI theme group */
export const ENVI_KEYWORDS: readonly string[] = [
'environment',
'climate',
'emission',
'health',
'food',
'medicinal',
'detergent',
'gmo',
'genetically',
'cancer',
];
/** Lowercase keywords that map an adopted-text title to the ECON theme group */
export const ECON_KEYWORDS: readonly string[] = [
'economic',
'financial',
'central bank',
'monetary',
'fiscal',
'28th regime',
];
/**
* Categorize an adopted-text title into a committee theme group.
*
* LIBE is tested before AFET so that human-rights and human-trafficking
* titles are classified under civil liberties even when they also mention
* an AFET country keyword (e.g. "Ukraine"). Both are tested before AGRI
* to avoid person-name false positives (e.g. "Bobi Wine").
*
* @param title - Adopted text title to categorize
* @returns Committee theme key — one of `'ENVI'` | `'ECON'` | `'AFET'` | `'LIBE'` | `'AGRI'` | `'OTHER'`
*/
export function categorizeAdoptedText(title: string): CommitteeTheme {
const t = title.toLowerCase();
if (LIBE_KEYWORDS.some((k) => t.includes(k))) return 'LIBE';
if (AFET_KEYWORDS.some((k) => t.includes(k))) return 'AFET';
if (AGRI_KEYWORDS.some((k) => t.includes(k))) return 'AGRI';
if (ENVI_KEYWORDS.some((k) => t.includes(k))) return 'ENVI';
if (ECON_KEYWORDS.some((k) => t.includes(k))) return 'ECON';
return 'OTHER';
}
// ─── Feed data enrichment ─────────────────────────────────────────────────────
/**
* Build an HTML section from adopted texts feed data.
* Groups texts by thematic area and provides committee-relevant context.
*
* @param feedData - EP feed data with adopted texts
* @param lang - Language code for localized strings
* @returns HTML string, or empty string when no feed data
*/
function buildAdoptedTextsSection(feedData: EPFeedData | undefined, lang: LanguageCode): string {
if (!feedData?.adoptedTexts?.length) return '';
const texts = feedData.adoptedTexts;
const s = getLocalizedString(COMMITTEE_ANALYSIS_CONTENT_STRINGS, lang);
const grouped: Partial<
Record<CommitteeTheme, Array<{ id: string; title: string; date: string }>>
> = {};
for (const text of texts) {
const cat = categorizeAdoptedText(text.title);
const bucket = grouped[cat] ?? [];
bucket.push(text);
grouped[cat] = bucket;
}
const committeeNames: Record<CommitteeTheme, string> = {
ENVI: s.committeeNameENVI,
ECON: s.committeeNameECON,
AFET: s.committeeNameAFET,
LIBE: s.committeeNameLIBE,
AGRI: s.committeeNameAGRI,
OTHER: s.committeeNameOTHER,
};
const sectionLabel = s.adoptedTextsSectionHeading;
const summary =
texts.length === 1
? s.adoptedTextsSummarySingular
: s.adoptedTextsSummary.replace('{count}', String(texts.length));
const displayOrder = ['ENVI', 'ECON', 'AFET', 'LIBE', 'AGRI', 'OTHER'] as const;
const sections = displayOrder
.filter((cat) => grouped[cat]?.length)
.map((cat) => {
const items = grouped[cat]!;
const listItems = items
.map(
(item) =>
`<li class="adopted-text-item"><strong>${escapeHTML(item.title)}</strong> <span class="document-date">(${escapeHTML(item.date)})</span></li>`
)
.join('\n ');
return `
<div class="committee-theme-group">
<h4>${escapeHTML(committeeNames[cat] ?? cat)}</h4>
<ul class="adopted-texts-list">${listItems}</ul>
</div>`;
})
.join('');
Iif (!sections) return '';
return `
<section class="adopted-texts-overview">
<h3>${escapeHTML(sectionLabel)}</h3>
<p>${escapeHTML(summary)}</p>
${sections}
</section>`;
}
// ─── HTML builders ────────────────────────────────────────────────────────────
/**
* Build the HTML body for a committee reports article.
*
* @param committeeDataList - Pre-fetched committee data
* @param lang - Language code for localized strings
* @returns Article HTML body
*/
function buildCommitteeReportsHTML(
committeeDataList: readonly CommitteeData[],
lang: LanguageCode
): string {
const s = getLocalizedString(COMMITTEE_ANALYSIS_CONTENT_STRINGS, lang);
const committeeSections = committeeDataList
.map((committee) => {
// Render an unavailable notice for individual placeholder committee entries
if (
committee.chair === PLACEHOLDER_CHAIR &&
committee.members === PLACEHOLDER_MEMBERS &&
committee.documents.length === 0
) {
return `
<section class="committee-card committee-card--unavailable">
<h3 class="committee-name">${escapeHTML(committee.name)} (${escapeHTML(committee.abbreviation)})</h3>
<p class="committee-metadata-unavailable">${escapeHTML(s.committeeMetadataUnavailable)}</p>
</section>`;
}
const docItems =
committee.documents.length > 0
? committee.documents
.map(
(doc) => `
<li class="document-item">
<span class="document-type">${escapeHTML(doc.type)}</span>
<span class="document-title">${escapeHTML(doc.title)}</span>
${doc.date ? `<span class="document-date">${escapeHTML(doc.date)}</span>` : ''}
</li>`
)
.join('')
: `<li>${escapeHTML(s.noRecentDocs)}</li>`;
const effectivenessHtml = committee.effectiveness
? `<p class="effectiveness-score">${escapeHTML(committee.effectiveness)}</p>`
: '';
return `
<section class="committee-card">
<h3 class="committee-name">${escapeHTML(committee.name)} (${escapeHTML(committee.abbreviation)})</h3>
<div class="committee-meta">
<span class="committee-chair">${escapeHTML(s.chairLabel)} ${escapeHTML(committee.chair)}</span>
<span class="committee-members">${committee.members} ${escapeHTML(s.membersLabel)}</span>
</div>
<section class="recent-activity">
<ul class="document-list">${docItems}</ul>
</section>
<section class="effectiveness-metrics">${effectivenessHtml}</section>
</section>`;
})
.join('');
return `
<div class="article-content">
<section class="committee-overview">
<p class="lede">${escapeHTML(s.lede)}</p>
</section>
<section class="committee-reports">${committeeSections}</section>
</div>`;
}
// ─── Strategy implementation ──────────────────────────────────────────────────
/**
* Article strategy for {@link ArticleCategory.COMMITTEE_REPORTS}.
* Fetches info, documents and effectiveness data for the featured committees
* then renders an activity overview.
*/
export class CommitteeReportsStrategy implements ArticleStrategy<CommitteeReportsArticleData> {
readonly type = ArticleCategory.COMMITTEE_REPORTS;
readonly requiredMCPTools = [
'get_committee_info',
'search_documents',
'analyze_legislative_effectiveness',
'get_committee_documents_feed',
] as const;
/**
* Fetch committee data for all featured committees in parallel.
*
* @param client - MCP client or null
* @param date - ISO 8601 publication date
* @returns Populated committee reports data payload
*/
async fetchData(
client: EuropeanParliamentMCPClient | null,
date: string
): Promise<CommitteeReportsArticleData> {
const feedDateRange = computeRollingDateRange(date, 30, 'committee feed window');
// Fetch individual committee data and EP feeds in parallel
const [committeeDataRaw, feedData] = await Promise.all([
Promise.all(
FEATURED_COMMITTEES.map((abbr) =>
fetchCommitteeData(client, abbr).catch((error: unknown) => {
const message = error instanceof Error ? error.message : String(error);
console.error(` ⚠️ Failed to fetch data for committee ${abbr}:`, message);
return null;
})
)
),
fetchEPFeedData(client, 'one-month', feedDateRange),
]);
const committeeDataList = committeeDataRaw.filter(
(committee): committee is CommitteeData => committee !== null
);
return { date, committeeDataList, feedData };
}
/**
* Build the committee reports HTML body.
*
* @param data - Committee reports data payload
* @param lang - Language code for localized content
* @returns Article HTML body
*/
buildContent(data: CommitteeReportsArticleData, lang: LanguageCode): string {
const base = buildCommitteeReportsHTML(data.committeeDataList, lang);
const feedSection = buildAdoptedTextsSection(data.feedData, lang);
const analysis = buildCommitteeAnalysis(data.committeeDataList, data.date, lang);
const deepSection = buildDeepAnalysisSection(analysis, lang);
const swotData = buildCommitteeSwot(data.committeeDataList, lang);
const swotSection = buildSwotSection(swotData, lang);
const dashboardData = buildCommitteeDashboard(data.committeeDataList, lang);
const dashboardSection = buildDashboardSection(dashboardData, lang);
const injection = feedSection + deepSection + swotSection + dashboardSection;
// Inject before the closing </div> of .article-content
if (injection) {
const closingTag = '</div>';
const lastIdx = base.lastIndexOf(closingTag);
Eif (lastIdx !== -1) {
return base.slice(0, lastIdx) + injection + '\n' + base.slice(lastIdx);
}
}
return base;
}
/**
* Return language-specific metadata for the committee reports article.
*
* @param _data - Committee reports data payload (unused — metadata is data-independent)
* @param lang - Target language code
* @returns Localised metadata
*/
getMetadata(_data: CommitteeReportsArticleData, lang: LanguageCode): ArticleMetadata {
const committeeLabel = FEATURED_COMMITTEES.join(', ');
const titleFn = getLocalizedString(COMMITTEE_REPORTS_TITLES, lang);
const { title, subtitle } = titleFn(committeeLabel);
return {
title,
subtitle,
keywords: [...COMMITTEE_REPORTS_KEYWORDS],
category: ArticleCategory.COMMITTEE_REPORTS,
sources: COMMITTEE_REPORTS_SOURCES,
};
}
/**
* Skip generation when no real data is available.
*
* Skips when:
* - All committee fetches failed (empty committeeDataList), or
* - All fetched committee data is placeholder AND no feed data is available.
* When EP feed data contains adopted texts or other items, the article can still
* provide valuable content even if individual committee metadata is sparse.
*
* @param data - Committee reports data payload
* @returns `true` when there is no usable data at all
*/
shouldSkip(data: CommitteeReportsArticleData): boolean {
const { committeeDataList, feedData } = data;
if (committeeDataList.length === 0) {
return true;
}
// If feed data has any items, generate even with placeholder committees
if (feedData) {
const feedItemCount =
(feedData.adoptedTexts?.length ?? 0) +
(feedData.committeeDocuments?.length ?? 0) +
(feedData.plenaryDocuments?.length ?? 0) +
(feedData.documents?.length ?? 0) +
(feedData.procedures?.length ?? 0);
if (feedItemCount > 0) {
return false;
}
}
return isPlaceholderCommitteeData(committeeDataList);
}
}
/** Singleton instance for use by the strategy registry */
export const committeeReportsStrategy = new CommitteeReportsStrategy();
|