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 | 8x 15x 15x 4x 2x 4x 4x 4x 4x 4x 4x 4x 7x 7x 2x 2x 2x 8x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* @module Generators/Strategies/PropositionsStrategy
* @description Article strategy for the Propositions article type.
* Fetches legislative proposals and active pipeline data from MCP, then
* renders a language-specific legislative overview article.
*/
import type { EuropeanParliamentMCPClient } from '../../mcp/ep-mcp-client.js';
import { ArticleCategory } from '../../types/index.js';
import type { LanguageCode } from '../../types/index.js';
import {
PROPOSITIONS_TITLES,
PROPOSITIONS_STRINGS,
getLocalizedString,
} from '../../constants/languages.js';
import {
fetchProposalsFromMCP,
fetchPipelineFromMCP,
fetchProcedureStatusFromMCP,
} from '../pipeline/fetch-stage.js';
import { buildPropositionsContent } from '../propositions-content.js';
import type { PipelineData } from '../propositions-content.js';
import type { ArticleStrategy, ArticleData, ArticleMetadata } from './article-strategy.js';
/** Keywords shared by all Propositions articles */
const PROPOSITIONS_KEYWORDS = [
'European Parliament',
'legislation',
'proposals',
'procedure',
'OLP',
] as const;
// ─── Data payload ─────────────────────────────────────────────────────────────
/** Data fetched and pre-processed by {@link PropositionsStrategy} */
export interface PropositionsArticleData extends ArticleData {
/** Pre-sanitised HTML for the proposals list section */
readonly proposalsHtml: string;
/** Active legislative pipeline data (null when MCP unavailable) */
readonly pipelineData: PipelineData | null;
/** Pre-sanitised HTML for the tracked procedure section */
readonly procedureHtml: string;
}
// ─── Strategy implementation ──────────────────────────────────────────────────
/**
* Article strategy for {@link ArticleCategory.PROPOSITIONS}.
* Fetches legislative proposals, active pipeline status, and procedure detail
* then renders a language-specific article.
*/
export class PropositionsStrategy implements ArticleStrategy<PropositionsArticleData> {
readonly type = ArticleCategory.PROPOSITIONS;
readonly requiredMCPTools = [
'search_documents',
'monitor_legislative_pipeline',
'track_legislation',
] as const;
/**
* Fetch legislative proposals and pipeline data in parallel.
*
* @param client - MCP client or null
* @param date - ISO 8601 publication date
* @returns Populated propositions data payload
*/
async fetchData(
client: EuropeanParliamentMCPClient | null,
date: string
): Promise<PropositionsArticleData> {
if (client) {
console.log(' 📡 Fetching legislative data from MCP server...');
}
const [proposalsResult, pipelineResult] = await Promise.allSettled([
fetchProposalsFromMCP(client),
fetchPipelineFromMCP(client),
]);
const { html: proposalsHtml, firstProcedureId } =
proposalsResult.status === 'fulfilled'
? proposalsResult.value
: { html: '', firstProcedureId: '' };
const pipelineData = pipelineResult.status === 'fulfilled' ? pipelineResult.value : null;
const procedureHtml = await fetchProcedureStatusFromMCP(client, firstProcedureId);
Eif (!proposalsHtml) {
console.log(' ℹ️ No proposals from MCP — pipeline article will be data-free');
}
return { date, proposalsHtml, pipelineData, procedureHtml };
}
/**
* Build the propositions HTML body using language-specific strings.
*
* @param data - Propositions data payload
* @param lang - Target language code
* @returns Article HTML body
*/
buildContent(data: PropositionsArticleData, lang: LanguageCode): string {
const strings = getLocalizedString(PROPOSITIONS_STRINGS, lang);
return buildPropositionsContent(
data.proposalsHtml,
data.pipelineData,
data.procedureHtml,
strings,
lang
);
}
/**
* Return language-specific metadata for the propositions article.
*
* @param _data - Propositions data payload (unused — metadata is data-independent)
* @param lang - Target language code
* @returns Localised metadata
*/
getMetadata(_data: PropositionsArticleData, lang: LanguageCode): ArticleMetadata {
const titleFn = getLocalizedString(PROPOSITIONS_TITLES, lang);
const { title, subtitle } = titleFn();
return {
title,
subtitle,
keywords: [...PROPOSITIONS_KEYWORDS],
category: ArticleCategory.PROPOSITIONS,
sources: [],
};
}
}
/** Singleton instance for use by the strategy registry */
export const propositionsStrategy = new PropositionsStrategy();
|