diff --git a/README.md b/README.md index d941578..05d0fa1 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,13 @@ Scalable multi-domain sports news platform — Astro 5 SSR frontend, Fastify bri ``` news-platform/ - frontend/ # Astro 5 SSR frontend application - bridge/ # Fastify bridge (WordPress REST API cache + normalizer) - wordpress/ # WordPress config, themes, plugins - config/domains/ # Per-domain configuration files - docs/ # Architecture and runbooks - deploy/ # LXC provisioning and deploy scripts + frontend/ # Astro 5 SSR frontend application + bridge/ # Fastify bridge (WordPress REST API cache + normalizer) + writer-pipeline/ # RSS aggregator store, metrics, optional WP drafts (andebol.net) + wordpress/ # WordPress config, themes, plugins + config/domains/ # Per-domain configuration files + docs/ # Architecture and runbooks + deploy/ # LXC provisioning and deploy scripts ``` ## Quick Start diff --git a/docs/WRITER_PIPELINE_ANDEBOL.md b/docs/WRITER_PIPELINE_ANDEBOL.md new file mode 100644 index 0000000..67b12be --- /dev/null +++ b/docs/WRITER_PIPELINE_ANDEBOL.md @@ -0,0 +1,58 @@ +# Writer pipeline — andebol.net (aggregator-first) + +**Scope:** `writer-pipeline/` in this repo. **Parent:** aggregator epic (Paperclip **BIT-709**); delivery tracked under **BIT-713**. + +## What it does + +1. **Ingest** — Pulls RSS sources from `writer-pipeline/config/andebol.net.sources.json` into a local JSON store (`writer-pipeline/var/aggregated-items.json`, gitignored). +2. **Shortlist** — Newest items that are not yet drafted in WordPress and not skipped. +3. **Read path (aggregator-first)** — Before any LLM *reading* step, the writer uses only structured fields from the store (`title`, `summary`, `url`, `sourceFeedId`). No full-page fetch is required for the primary path. +4. **Metrics** — Each cycle appends one JSON line to `writer-pipeline/var/metrics.jsonl` with estimated **read-phase** tokens for: + - **Aggregator path:** `aggregatorReadContext()` (title + summary + URL + instruction block). + - **Legacy path:** full HTML text fetch per shortlisted URL (for comparison only). If a fetch fails, that item falls back to summary-sized estimate so the cycle still completes. +5. **Publish** — Optional: creates **WordPress drafts** from the shortlist using Application Passwords (never required for metrics-only runs). + +## Fallback behaviour + +- **Per feed:** a failing RSS URL is logged in `metrics.errors`; other feeds still run. +- **Per URL (legacy comparison):** failed HTML fetch does not block the cycle; aggregator metrics still apply for production reads. +- **WP publish:** if credentials are missing, the cycle completes with a clear error string and **no** draft creation. + +## Commands + +```bash +cd writer-pipeline +npm install +npm run build + +# Ingest + metrics + optional legacy comparison (no WP) +node dist/run-cycle.js --site andebol.net --dry-run --shortlist 10 + +# Create up to N drafts (needs ANDEBOL_WP_* env) +node dist/run-cycle.js --site andebol.net --publish-max 1 --shortlist 10 +``` + +**Aggregator HTTP API** (optional, for cron or external tools): + +```bash +npm run aggregator +# GET /health +# GET /shortlist?site=andebol.net&limit=10 +# POST /ingest?site=andebol.net +``` + +## Sample outcome (2026-04-02, dry-run, 5-item shortlist) + +| Metric | Value | +|--------|------| +| `tokensReadAggregatorPath` | ~675 | +| `tokensReadLegacyPath` | ~6.2k | +| Ratio (legacy ÷ aggregator) | ~9× | + +Pricing reference in code uses **USD 0.15 / 1M input tokens** (`token-metrics.ts`) for *read-phase* estimates only — adjust when the production model changes. + +## Next steps + +- Add more `feeds[]` entries (competition sites, press rooms) and tune dedup via canonical URLs. +- Plug a real LLM **generation** step that receives only `aggregatorReadContext(item)` — no full HTML in the prompt unless a human toggles a break-glass flag. +- Run `npm run aggregator` under systemd on the LXC with periodic `POST /ingest` and a single `run-cycle` cron for drafts. diff --git a/writer-pipeline/.env.example b/writer-pipeline/.env.example new file mode 100644 index 0000000..840b6fc --- /dev/null +++ b/writer-pipeline/.env.example @@ -0,0 +1,8 @@ +# Optional: create WordPress drafts from the aggregator shortlist (andebol.net WP on :8081). +# ANDEBOL_WP_BASE=http://127.0.0.1:8081/wp-json +# ANDEBOL_WP_USER=editor_username +# ANDEBOL_WP_APP_PASSWORD=xxxx xxxx xxxx xxxx + +# Optional: aggregator HTTP service (default 127.0.0.1:3310) +# AGGREGATOR_PORT=3310 +# AGGREGATOR_STORE_PATH=/opt/bitreport/news-platform/writer-pipeline/var/aggregated-items.json diff --git a/writer-pipeline/.gitignore b/writer-pipeline/.gitignore new file mode 100644 index 0000000..b947077 --- /dev/null +++ b/writer-pipeline/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ diff --git a/writer-pipeline/config/andebol.net.sources.json b/writer-pipeline/config/andebol.net.sources.json new file mode 100644 index 0000000..f72f3a7 --- /dev/null +++ b/writer-pipeline/config/andebol.net.sources.json @@ -0,0 +1,11 @@ +{ + "site": "andebol.net", + "feeds": [ + { + "id": "fpa_portal_main", + "url": "https://portal.fpa.pt/feed/", + "enabled": true, + "note": "FPA portal WordPress main feed (category /noticias/feed is empty). Add more feeds as needed; failures are skipped per source." + } + ] +} diff --git a/writer-pipeline/package-lock.json b/writer-pipeline/package-lock.json new file mode 100644 index 0000000..8fe9433 --- /dev/null +++ b/writer-pipeline/package-lock.json @@ -0,0 +1,1142 @@ +{ + "name": "news-writer-pipeline", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "news-writer-pipeline", + "version": "1.0.0", + "dependencies": { + "fastify": "^4.28.1", + "rss-parser": "^3.13.0" + }, + "devDependencies": { + "@types/node": "^20.14.0", + "tsx": "^4.15.0", + "typescript": "^5.4.5" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.5.tgz", + "integrity": "sha512-nGsF/4C7uzUj+Nj/4J+Zt0bYQ6bz33Phz8Lb2N80Mti1HjGclTJdXZ+9APC4kLvONbjxN1zfvYNd8FEcbBK/MQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.5.tgz", + "integrity": "sha512-Cv781jd0Rfj/paoNrul1/r4G0HLvuFKYh7C9uHZ2Pl8YXstzvCyyeWENTFR9qFnRzNMCjXmsulZuvosDg10Mog==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.5.tgz", + "integrity": "sha512-Oeghq+XFgh1pUGd1YKs4DDoxzxkoUkvko+T/IVKwlghKLvvjbGFB3ek8VEDBmNvqhwuL0CQS3cExdzpmUyIrgA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.5.tgz", + "integrity": "sha512-nQD7lspbzerlmtNOxYMFAGmhxgzn8Z7m9jgFkh6kpkjsAhZee1w8tJW3ZlW+N9iRePz0oPUDrYrXidCPSImD0Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.5.tgz", + "integrity": "sha512-I+Ya/MgC6rr8oRWGRDF3BXDfP8K1BVUggHqN6VI2lUZLdDi1IM1v2cy0e3lCPbP+pVcK3Tv8cgUhHse1kaNZZw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.5.tgz", + "integrity": "sha512-MCjQUtC8wWJn/pIPM7vQaO69BFgwPD1jriEdqwTCKzWjGgkMbcg+M5HzrOhPhuYe1AJjXlHmD142KQf+jnYj8A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.5.tgz", + "integrity": "sha512-X6xVS+goSH0UelYXnuf4GHLwpOdc8rgK/zai+dKzBMnncw7BTQIwquOodE7EKvY2UVUetSqyAfyZC1D+oqLQtg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.5.tgz", + "integrity": "sha512-233X1FGo3a8x1ekLB6XT69LfZ83vqz+9z3TSEQCTYfMNY880A97nr81KbPcAMl9rmOFp11wO0dP+eB18KU/Ucg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.5.tgz", + "integrity": "sha512-0wkVrYHG4sdCCN/bcwQ7yYMXACkaHc3UFeaEOwSVW6e5RycMageYAFv+JS2bKLwHyeKVUvtoVH+5/RHq0fgeFw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.5.tgz", + "integrity": "sha512-euKkilsNOv7x/M1NKsx5znyprbpsRFIzTV6lWziqJch7yWYayfLtZzDxDTl+LSQDJYAjd9TVb/Kt5UKIrj2e4A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.5.tgz", + "integrity": "sha512-hVRQX4+P3MS36NxOy24v/Cdsimy/5HYePw+tmPqnNN1fxV0bPrFWR6TMqwXPwoTM2VzbkA+4lbHWUKDd5ZDA/w==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.5.tgz", + "integrity": "sha512-mKqqRuOPALI8nDzhOBmIS0INvZOOFGGg5n1osGIXAx8oersceEbKd4t1ACNTHM3sJBXGFAlEgqM+svzjPot+ZQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.5.tgz", + "integrity": "sha512-EE/QXH9IyaAj1qeuIV5+/GZkBTipgGO782Ff7Um3vPS9cvLhJJeATy4Ggxikz2inZ46KByamMn6GqtqyVjhenA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.5.tgz", + "integrity": "sha512-0V2iF1RGxBf1b7/BjurA5jfkl7PtySjom1r6xOK2q9KWw/XCpAdtB6KNMO+9xx69yYfSCRR9FE0TyKfHA2eQMw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.5.tgz", + "integrity": "sha512-rYxThBx6G9HN6tFNuvB/vykeLi4VDsm5hE5pVwzqbAjZEARQrWu3noZSfbEnPZ/CRXP3271GyFk/49up2W190g==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.5.tgz", + "integrity": "sha512-uEP2q/4qgd8goEUc4QIdU/1P2NmEtZ/zX5u3OpLlCGhJIuBIv0s0wr7TB2nBrd3/A5XIdEkkS5ZLF0ULuvaaYQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.5.tgz", + "integrity": "sha512-+Gq47Wqq6PLOOZuBzVSII2//9yyHNKZLuwfzCemqexqOQCSz0zy0O26kIzyp9EMNMK+nZ0tFHBZrCeVUuMs/ew==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.5.tgz", + "integrity": "sha512-3F/5EG8VHfN/I+W5cO1/SV2H9Q/5r7vcHabMnBqhHK2lTWOh3F8vixNzo8lqxrlmBtZVFpW8pmITHnq54+Tq4g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.5.tgz", + "integrity": "sha512-28t+Sj3CPN8vkMOlZotOmDgilQwVvxWZl7b8rxpn73Tt/gCnvrHxQUMng4uu3itdFvrtba/1nHejvxqz8xgEMA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.5.tgz", + "integrity": "sha512-Doz/hKtiuVAi9hMsBMpwBANhIZc8l238U2Onko3t2xUp8xtM0ZKdDYHMnm/qPFVthY8KtxkXaocwmMh6VolzMA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.5.tgz", + "integrity": "sha512-WfGVaa1oz5A7+ZFPkERIbIhKT4olvGl1tyzTRaB5yoZRLqC0KwaO95FeZtOdQj/oKkjW57KcVF944m62/0GYtA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.5.tgz", + "integrity": "sha512-Xh+VRuh6OMh3uJ0JkCjI57l+DVe7VRGBYymen8rFPnTVgATBwA6nmToxM2OwTlSvrnWpPKkrQUj93+K9huYC6A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.5.tgz", + "integrity": "sha512-aC1gpJkkaUADHuAdQfuVTnqVUTLqqUNhAvEwHwVWcnVVZvNlDPGA0UveZsfXJJ9T6k9Po4eHi3c02gbdwO3g6w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.5.tgz", + "integrity": "sha512-0UNx2aavV0fk6UpZcwXFLztA2r/k9jTUa7OW7SAea1VYUhkug99MW1uZeXEnPn5+cHOd0n8myQay6TlFnBR07w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.5.tgz", + "integrity": "sha512-5nlJ3AeJWCTSzR7AEqVjT/faWyqKU86kCi1lLmxVqmNR+j4HrYdns+eTGjS/vmrzCIe8inGQckUadvS0+JkKdQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.5.tgz", + "integrity": "sha512-PWypQR+d4FLfkhBIV+/kHsUELAnMpx1bRvvsn3p+/sAERbnCzFrtDRG2Xw5n+2zPxBK2+iaP+vetsRl4Ti7WgA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@fastify/ajv-compiler": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@fastify/ajv-compiler/-/ajv-compiler-3.6.0.tgz", + "integrity": "sha512-LwdXQJjmMD+GwLOkP7TVC68qa+pSSogeWWmznRJ/coyTcfe9qA05AHFSe1eZFwK6q+xVRpChnvFUkf1iYaSZsQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.11.0", + "ajv-formats": "^2.1.1", + "fast-uri": "^2.0.0" + } + }, + "node_modules/@fastify/error": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/@fastify/error/-/error-3.4.1.tgz", + "integrity": "sha512-wWSvph+29GR783IhmvdwWnN4bUxTD01Vm5Xad4i7i1VuAOItLvbPAb69sb0IQ2N57yprvhNIwAP5B6xfKTmjmQ==", + "license": "MIT" + }, + "node_modules/@fastify/fast-json-stringify-compiler": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@fastify/fast-json-stringify-compiler/-/fast-json-stringify-compiler-4.3.0.tgz", + "integrity": "sha512-aZAXGYo6m22Fk1zZzEUKBvut/CIIQe/BapEORnxiD5Qr0kPHqqI69NtEMCme74h+at72sPhbkb4ZrLd1W3KRLA==", + "license": "MIT", + "dependencies": { + "fast-json-stringify": "^5.7.0" + } + }, + "node_modules/@fastify/merge-json-schemas": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@fastify/merge-json-schemas/-/merge-json-schemas-0.1.1.tgz", + "integrity": "sha512-fERDVz7topgNjtXsJTTW1JKLy0rhuLRcquYqNR9rF7OcVpCa2OVW49ZPDIhaRRCaUuvVxI+N416xUoF76HNSXA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3" + } + }, + "node_modules/@pinojs/redact": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@pinojs/redact/-/redact-0.4.0.tgz", + "integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==", + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "20.19.37", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.37.tgz", + "integrity": "sha512-8kzdPJ3FsNsVIurqBs7oodNnCEVbni9yUEkaHbgptDACOPW04jimGagZ51E6+lXUwJjgnBw+hyko/lkFWCldqw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/abstract-logging": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.1.tgz", + "integrity": "sha512-2BjRTZxTPvheOvGbBslFSYOUkr+SjPtOnrLP33f+VIWLzezQpZcqVg7ja3L4dBXmzzgwT+a029jRx5PCi3JuiA==", + "license": "MIT" + }, + "node_modules/ajv": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/ajv/node_modules/fast-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", + "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/atomic-sleep": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", + "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/avvio": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/avvio/-/avvio-8.4.0.tgz", + "integrity": "sha512-CDSwaxINFy59iNwhYnkvALBwZiTydGkOecZyPkqBpABYR1KqGEsET0VOOYDwtleZSUIdeY36DC2bSZ24CO1igA==", + "license": "MIT", + "dependencies": { + "@fastify/error": "^3.3.0", + "fastq": "^1.17.1" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/entities": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz", + "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==", + "license": "BSD-2-Clause", + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/esbuild": { + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.5.tgz", + "integrity": "sha512-zdQoHBjuDqKsvV5OPaWansOwfSQ0Js+Uj9J85TBvj3bFW1JjWTSULMRwdQAc8qMeIScbClxeMK0jlrtB9linhA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.5", + "@esbuild/android-arm": "0.27.5", + "@esbuild/android-arm64": "0.27.5", + "@esbuild/android-x64": "0.27.5", + "@esbuild/darwin-arm64": "0.27.5", + "@esbuild/darwin-x64": "0.27.5", + "@esbuild/freebsd-arm64": "0.27.5", + "@esbuild/freebsd-x64": "0.27.5", + "@esbuild/linux-arm": "0.27.5", + "@esbuild/linux-arm64": "0.27.5", + "@esbuild/linux-ia32": "0.27.5", + "@esbuild/linux-loong64": "0.27.5", + "@esbuild/linux-mips64el": "0.27.5", + "@esbuild/linux-ppc64": "0.27.5", + "@esbuild/linux-riscv64": "0.27.5", + "@esbuild/linux-s390x": "0.27.5", + "@esbuild/linux-x64": "0.27.5", + "@esbuild/netbsd-arm64": "0.27.5", + "@esbuild/netbsd-x64": "0.27.5", + "@esbuild/openbsd-arm64": "0.27.5", + "@esbuild/openbsd-x64": "0.27.5", + "@esbuild/openharmony-arm64": "0.27.5", + "@esbuild/sunos-x64": "0.27.5", + "@esbuild/win32-arm64": "0.27.5", + "@esbuild/win32-ia32": "0.27.5", + "@esbuild/win32-x64": "0.27.5" + } + }, + "node_modules/fast-content-type-parse": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-1.1.0.tgz", + "integrity": "sha512-fBHHqSTFLVnR61C+gltJuE5GkVQMV0S2nqUO8TJ+5Z3qAKG8vAx4FKai1s5jq/inV1+sREynIWSuQ6HgoSXpDQ==", + "license": "MIT" + }, + "node_modules/fast-decode-uri-component": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/fast-decode-uri-component/-/fast-decode-uri-component-1.0.1.tgz", + "integrity": "sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==", + "license": "MIT" + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-json-stringify": { + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.16.1.tgz", + "integrity": "sha512-KAdnLvy1yu/XrRtP+LJnxbBGrhN+xXu+gt3EUvZhYGKCr3lFHq/7UFJHHFgmJKoqlh6B40bZLEv7w46B0mqn1g==", + "license": "MIT", + "dependencies": { + "@fastify/merge-json-schemas": "^0.1.0", + "ajv": "^8.10.0", + "ajv-formats": "^3.0.1", + "fast-deep-equal": "^3.1.3", + "fast-uri": "^2.1.0", + "json-schema-ref-resolver": "^1.0.1", + "rfdc": "^1.2.0" + } + }, + "node_modules/fast-json-stringify/node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/fast-querystring": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/fast-querystring/-/fast-querystring-1.1.2.tgz", + "integrity": "sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg==", + "license": "MIT", + "dependencies": { + "fast-decode-uri-component": "^1.0.1" + } + }, + "node_modules/fast-uri": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-2.4.0.tgz", + "integrity": "sha512-ypuAmmMKInk5q7XcepxlnUWDLWv4GFtaJqAzWKqn62IpQ3pejtr5dTVbt3vwqVaMKmkNR55sTT+CqUKIaT21BA==", + "license": "MIT" + }, + "node_modules/fastify": { + "version": "4.29.1", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.29.1.tgz", + "integrity": "sha512-m2kMNHIG92tSNWv+Z3UeTR9AWLLuo7KctC7mlFPtMEVrfjIhmQhkQnT9v15qA/BfVq3vvj134Y0jl9SBje3jXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/ajv-compiler": "^3.5.0", + "@fastify/error": "^3.4.0", + "@fastify/fast-json-stringify-compiler": "^4.3.0", + "abstract-logging": "^2.0.1", + "avvio": "^8.3.0", + "fast-content-type-parse": "^1.1.0", + "fast-json-stringify": "^5.8.0", + "find-my-way": "^8.0.0", + "light-my-request": "^5.11.0", + "pino": "^9.0.0", + "process-warning": "^3.0.0", + "proxy-addr": "^2.0.7", + "rfdc": "^1.3.0", + "secure-json-parse": "^2.7.0", + "semver": "^7.5.4", + "toad-cache": "^3.3.0" + } + }, + "node_modules/fastq": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.1.tgz", + "integrity": "sha512-GGToxJ/w1x32s/D2EKND7kTil4n8OVk/9mycTc4VDza13lOvpUZTGX3mFSCtV9ksdGBVzvsyAVLM6mHFThxXxw==", + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/find-my-way": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-8.2.2.tgz", + "integrity": "sha512-Dobi7gcTEq8yszimcfp/R7+owiT4WncAJ7VTTgFH1jYJ5GaG1FbhjwDG820hptN0QDFvzVY3RfCzdInvGPGzjA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-querystring": "^1.0.0", + "safe-regex2": "^3.1.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-tsconfig": { + "version": "4.13.7", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.7.tgz", + "integrity": "sha512-7tN6rFgBlMgpBML5j8typ92BKFi2sFQvIdpAqLA2beia5avZDrMs0FLZiM5etShWq5irVyGcGMEA1jcDaK7A/Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/json-schema-ref-resolver": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-schema-ref-resolver/-/json-schema-ref-resolver-1.0.1.tgz", + "integrity": "sha512-EJAj1pgHc1hxF6vo2Z3s69fMjO1INq6eGHXZ8Z6wCQeldCuwxGK9Sxf4/cScGn3FZubCVUehfWtcDM/PLteCQw==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/light-my-request": { + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-5.14.0.tgz", + "integrity": "sha512-aORPWntbpH5esaYpGOOmri0OHDOe3wC5M2MQxZ9dvMLZm6DnaAn0kJlcbU9hwsQgLzmZyReKwFwwPkR+nHu5kA==", + "license": "BSD-3-Clause", + "dependencies": { + "cookie": "^0.7.0", + "process-warning": "^3.0.0", + "set-cookie-parser": "^2.4.1" + } + }, + "node_modules/on-exit-leak-free": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", + "integrity": "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/pino": { + "version": "9.14.0", + "resolved": "https://registry.npmjs.org/pino/-/pino-9.14.0.tgz", + "integrity": "sha512-8OEwKp5juEvb/MjpIc4hjqfgCNysrS94RIOMXYvpYCdm/jglrKEiAYmiumbmGhCvs+IcInsphYDFwqrjr7398w==", + "license": "MIT", + "dependencies": { + "@pinojs/redact": "^0.4.0", + "atomic-sleep": "^1.0.0", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^2.0.0", + "pino-std-serializers": "^7.0.0", + "process-warning": "^5.0.0", + "quick-format-unescaped": "^4.0.3", + "real-require": "^0.2.0", + "safe-stable-stringify": "^2.3.1", + "sonic-boom": "^4.0.1", + "thread-stream": "^3.0.0" + }, + "bin": { + "pino": "bin.js" + } + }, + "node_modules/pino-abstract-transport": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-2.0.0.tgz", + "integrity": "sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw==", + "license": "MIT", + "dependencies": { + "split2": "^4.0.0" + } + }, + "node_modules/pino-std-serializers": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-7.1.0.tgz", + "integrity": "sha512-BndPH67/JxGExRgiX1dX0w1FvZck5Wa4aal9198SrRhZjH3GxKQUKIBnYJTdj2HDN3UQAS06HlfcSbQj2OHmaw==", + "license": "MIT" + }, + "node_modules/pino/node_modules/process-warning": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz", + "integrity": "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, + "node_modules/process-warning": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-3.0.0.tgz", + "integrity": "sha512-mqn0kFRl0EoqhnL0GQ0veqFHyIN1yig9RHh/InzORTUiZHFRAur+aMtRkELNwGs9aNwKS6tg/An4NYBPGwvtzQ==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/quick-format-unescaped": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==", + "license": "MIT" + }, + "node_modules/real-require": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", + "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "license": "MIT", + "engines": { + "node": ">= 12.13.0" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, + "node_modules/ret": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/ret/-/ret-0.4.3.tgz", + "integrity": "sha512-0f4Memo5QP7WQyUEAYUO3esD/XjOc3Zjjg5CPsAq1p8sIu0XPeMbHJemKA0BO7tV0X7+A0FoEpbmHXWxPyD3wQ==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/reusify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", + "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/rfdc": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "license": "MIT" + }, + "node_modules/rss-parser": { + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/rss-parser/-/rss-parser-3.13.0.tgz", + "integrity": "sha512-7jWUBV5yGN3rqMMj7CZufl/291QAhvrrGpDNE4k/02ZchL0npisiYYqULF71jCEKoIiHvK/Q2e6IkDwPziT7+w==", + "license": "MIT", + "dependencies": { + "entities": "^2.0.3", + "xml2js": "^0.5.0" + } + }, + "node_modules/safe-regex2": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/safe-regex2/-/safe-regex2-3.1.0.tgz", + "integrity": "sha512-RAAZAGbap2kBfbVhvmnTFv73NWLMvDGOITFYTZBAaY8eR+Ir4ef7Up/e7amo+y1+AH+3PtLkrt9mvcTsG9LXug==", + "license": "MIT", + "dependencies": { + "ret": "~0.4.0" + } + }, + "node_modules/safe-stable-stringify": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.5.0.tgz", + "integrity": "sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/sax": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.0.tgz", + "integrity": "sha512-6R3J5M4AcbtLUdZmRv2SygeVaM7IhrLXu9BmnOGmmACak8fiUtOsYNWUS4uK7upbmHIBbLBeFeI//477BKLBzA==", + "license": "BlueOak-1.0.0", + "engines": { + "node": ">=11.0.0" + } + }, + "node_modules/secure-json-parse": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", + "integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==", + "license": "BSD-3-Clause" + }, + "node_modules/semver": { + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/set-cookie-parser": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz", + "integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==", + "license": "MIT" + }, + "node_modules/sonic-boom": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.1.tgz", + "integrity": "sha512-w6AxtubXa2wTXAUsZMMWERrsIRAdrK0Sc+FUytWvYAhBJLyuI4llrMIC1DtlNSdI99EI86KZum2MMq3EAZlF9Q==", + "license": "MIT", + "dependencies": { + "atomic-sleep": "^1.0.0" + } + }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, + "node_modules/thread-stream": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-3.1.0.tgz", + "integrity": "sha512-OqyPZ9u96VohAyMfJykzmivOrY2wfMSf3C5TtFJVgN+Hm6aj+voFhlK+kZEIv2FBh1X6Xp3DlnCOfEQ3B2J86A==", + "license": "MIT", + "dependencies": { + "real-require": "^0.2.0" + } + }, + "node_modules/toad-cache": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.7.0.tgz", + "integrity": "sha512-/m8M+2BJUpoJdgAHoG+baCwBT+tf2VraSfkBgl0Y00qIWt41DJ8R5B8nsEw0I58YwF5IZH6z24/2TobDKnqSWw==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/tsx": { + "version": "4.21.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", + "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.27.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/xml2js": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz", + "integrity": "sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==", + "license": "MIT", + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "license": "MIT", + "engines": { + "node": ">=4.0" + } + } + } +} diff --git a/writer-pipeline/package.json b/writer-pipeline/package.json new file mode 100644 index 0000000..a3195e4 --- /dev/null +++ b/writer-pipeline/package.json @@ -0,0 +1,24 @@ +{ + "name": "news-writer-pipeline", + "version": "1.0.0", + "private": true, + "type": "module", + "description": "Aggregator-first writer pipeline for andebol.net (shortlist, token metrics, WP drafts)", + "scripts": { + "build": "tsc", + "typecheck": "tsc --noEmit", + "aggregator": "node dist/aggregator-server.js", + "aggregator:dev": "tsx src/aggregator-server.ts", + "cycle": "node dist/run-cycle.js", + "cycle:dev": "tsx src/run-cycle.ts" + }, + "dependencies": { + "fastify": "^4.28.1", + "rss-parser": "^3.13.0" + }, + "devDependencies": { + "@types/node": "^20.14.0", + "tsx": "^4.15.0", + "typescript": "^5.4.5" + } +} diff --git a/writer-pipeline/src/aggregator-server.ts b/writer-pipeline/src/aggregator-server.ts new file mode 100644 index 0000000..73d1627 --- /dev/null +++ b/writer-pipeline/src/aggregator-server.ts @@ -0,0 +1,59 @@ +import Fastify from 'fastify'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { readSourcesConfig } from './config-load.js'; +import { ingestSiteFeeds, sourcesConfigPath } from './rss-ingest.js'; +import { DEFAULT_STORE_PATH, loadStore, saveStore, shortlist } from './store.js'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const PKG_ROOT = path.resolve(__dirname, '..'); +const DEFAULT_CONFIG_DIR = path.join(PKG_ROOT, 'config'); + +async function buildServer() { + const storePath = process.env.AGGREGATOR_STORE_PATH ?? DEFAULT_STORE_PATH; + const configDir = process.env.AGGREGATOR_CONFIG_DIR ?? DEFAULT_CONFIG_DIR; + const host = process.env.AGGREGATOR_HOST ?? '127.0.0.1'; + const port = parseInt(process.env.AGGREGATOR_PORT ?? '3310', 10); + + const app = Fastify({ logger: true }); + + app.get('/health', async () => ({ ok: true, storePath })); + + app.get<{ + Querystring: { site?: string; limit?: string }; + }>('/shortlist', async (req) => { + const site = req.query.site ?? 'andebol.net'; + const limit = Math.min(50, Math.max(1, parseInt(req.query.limit ?? '10', 10))); + const store = await loadStore(storePath); + const items = shortlist(store, site, limit); + return { site, limit, count: items.length, items }; + }); + + app.post<{ + Querystring: { site?: string }; + }>('/ingest', async (req, reply) => { + const site = req.query.site ?? 'andebol.net'; + const cfgPath = sourcesConfigPath(site, configDir); + const sources = await readSourcesConfig(cfgPath); + let store = await loadStore(storePath); + const result = await ingestSiteFeeds(store, sources); + store = result.store; + await saveStore(storePath, store); + return reply.send({ + site, + attempted: result.attempted, + succeeded: result.succeeded, + failed: result.failed, + newItems: result.newItems, + errors: result.errors, + }); + }); + + await app.listen({ host, port }); + app.log.info(`Aggregator listening on http://${host}:${port}`); +} + +buildServer().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/writer-pipeline/src/config-load.ts b/writer-pipeline/src/config-load.ts new file mode 100644 index 0000000..b5b4469 --- /dev/null +++ b/writer-pipeline/src/config-load.ts @@ -0,0 +1,11 @@ +import { readFile } from 'node:fs/promises'; +import type { SiteSourcesConfig } from './types.js'; + +export async function readSourcesConfig(filePath: string): Promise { + const raw = await readFile(filePath, 'utf8'); + const data = JSON.parse(raw) as SiteSourcesConfig; + if (!data?.site || !Array.isArray(data.feeds)) { + throw new Error(`Invalid sources config: ${filePath}`); + } + return data; +} diff --git a/writer-pipeline/src/legacy-fetch.ts b/writer-pipeline/src/legacy-fetch.ts new file mode 100644 index 0000000..be49a12 --- /dev/null +++ b/writer-pipeline/src/legacy-fetch.ts @@ -0,0 +1,23 @@ +/** + * Optional legacy read path: full HTML fetch for token comparison. + * Not used for publishing when aggregator data is present. + */ +export async function fetchArticleText(url: string, timeoutMs = 10000): Promise { + try { + const res = await fetch(url, { + headers: { 'User-Agent': 'BitReport-news-writer-pipeline/1.0 (metrics)' }, + signal: AbortSignal.timeout(timeoutMs), + }); + if (!res.ok) return null; + const html = await res.text(); + return html + .replace(//gi, ' ') + .replace(//gi, ' ') + .replace(/<[^>]+>/g, ' ') + .replace(/\s+/g, ' ') + .trim() + .slice(0, 120_000); + } catch { + return null; + } +} diff --git a/writer-pipeline/src/rss-ingest.ts b/writer-pipeline/src/rss-ingest.ts new file mode 100644 index 0000000..0de7423 --- /dev/null +++ b/writer-pipeline/src/rss-ingest.ts @@ -0,0 +1,93 @@ +import Parser from 'rss-parser'; +import type { AggregatedItem, SiteSourcesConfig, StoreFile } from './types.js'; +import { canonicalUrl, itemId, upsertItem } from './store.js'; + +const parser = new Parser(); + +async function parseFeedUrl(url: string) { + const res = await fetch(url, { + redirect: 'follow', + headers: { + 'User-Agent': 'BitReport-news-writer-pipeline/1.0', + Accept: 'application/rss+xml, application/xml, text/xml, */*', + }, + signal: AbortSignal.timeout(15000), + }); + if (!res.ok) throw new Error(`HTTP ${res.status}`); + const xml = await res.text(); + return parser.parseString(xml); +} + +function pickSummary(entry: { contentSnippet?: string; content?: string; summary?: string }): string { + const s = entry.contentSnippet || entry.summary || ''; + if (s) return s.replace(/\s+/g, ' ').trim().slice(0, 2000); + const c = entry.content || ''; + return c.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 2000); +} + +export interface IngestResult { + store: StoreFile; + attempted: number; + succeeded: number; + failed: number; + newItems: number; + errors: string[]; +} + +export async function ingestSiteFeeds( + store: StoreFile, + config: SiteSourcesConfig, +): Promise { + const errors: string[] = []; + let current = store; + let attempted = 0; + let succeeded = 0; + let failed = 0; + let newItems = 0; + const now = new Date().toISOString(); + + for (const feed of config.feeds) { + if (!feed.enabled) continue; + attempted += 1; + try { + const parsed = await parseFeedUrl(feed.url); + succeeded += 1; + const items = parsed.items ?? []; + for (const entry of items) { + const link = entry.link?.trim(); + if (!link) continue; + const url = canonicalUrl(link); + const id = itemId(url); + const title = (entry.title || 'Sem título').replace(/\s+/g, ' ').trim(); + const summary = pickSummary(entry); + const publishedAt = + entry.isoDate || entry.pubDate || entry.date || now; + + const agg: AggregatedItem = { + id, + site: config.site, + sourceFeedId: feed.id, + url, + title, + summary, + publishedAt, + ingestedAt: now, + }; + const { store: next, isNew } = upsertItem(current, agg); + current = next; + if (isNew) newItems += 1; + } + } catch (e) { + failed += 1; + const msg = e instanceof Error ? e.message : String(e); + errors.push(`feed ${feed.id} (${feed.url}): ${msg}`); + } + } + + return { store: current, attempted, succeeded, failed, newItems, errors }; +} + +/** Resolve config path for a site key (e.g. andebol.net). */ +export function sourcesConfigPath(site: string, configDir: string): string { + return `${configDir}/${site}.sources.json`; +} diff --git a/writer-pipeline/src/run-cycle.ts b/writer-pipeline/src/run-cycle.ts new file mode 100644 index 0000000..8270137 --- /dev/null +++ b/writer-pipeline/src/run-cycle.ts @@ -0,0 +1,141 @@ +#!/usr/bin/env node +import { appendFile, mkdir } from 'node:fs/promises'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { randomUUID } from 'node:crypto'; +import { readSourcesConfig } from './config-load.js'; +import { fetchArticleText } from './legacy-fetch.js'; +import { ingestSiteFeeds, sourcesConfigPath } from './rss-ingest.js'; +import { + DEFAULT_STORE_PATH, + loadStore, + saveStore, + shortlist, + upsertItem, +} from './store.js'; +import { + aggregatorReadContext, + estimateTokens, + estimatedInputCostUsd, +} from './token-metrics.js'; +import type { AggregatedItem, CycleMetrics } from './types.js'; +import { createDraftFromAggregatedItem } from './wp-publish.js'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const PKG_ROOT = path.resolve(__dirname, '..'); +const DEFAULT_CONFIG_DIR = path.join(PKG_ROOT, 'config'); + +function argValue(name: string, argv: string[]): string | undefined { + const i = argv.indexOf(name); + if (i >= 0 && argv[i + 1]) return argv[i + 1]; + return undefined; +} + +function hasFlag(name: string, argv: string[]): boolean { + return argv.includes(name); +} + +async function appendMetrics(metricsPath: string, m: CycleMetrics): Promise { + await mkdir(path.dirname(metricsPath), { recursive: true }); + await appendFile(metricsPath, `${JSON.stringify(m)}\n`, 'utf8'); +} + +async function main(): Promise { + const argv = process.argv.slice(2); + const site = argValue('--site', argv) ?? 'andebol.net'; + const dryRun = hasFlag('--dry-run', argv); + const publishMax = Math.max(0, parseInt(argValue('--publish-max', argv) ?? '0', 10)); + const shortlistLimit = Math.max(1, parseInt(argValue('--shortlist', argv) ?? '10', 10)); + const storePath = argValue('--store', argv) ?? DEFAULT_STORE_PATH; + const configDir = argValue('--config-dir', argv) ?? DEFAULT_CONFIG_DIR; + const metricsPath = + argValue('--metrics-file', argv) ?? path.join(PKG_ROOT, 'var', 'metrics.jsonl'); + + const cfgPath = sourcesConfigPath(site, configDir); + const sources = await readSourcesConfig(cfgPath); + + const startedAt = new Date().toISOString(); + const cycleId = randomUUID(); + let store = await loadStore(storePath); + + const ingest = await ingestSiteFeeds(store, sources); + store = ingest.store; + await saveStore(storePath, store); + + const list = shortlist(store, site, shortlistLimit); + let tokensAgg = 0; + let tokensLegacy = 0; + let legacyUsed = 0; + + for (const item of list) { + tokensAgg += estimateTokens(aggregatorReadContext(item)); + const legacyText = await fetchArticleText(item.url); + if (legacyText && legacyText.length > 200) { + tokensLegacy += estimateTokens(legacyText); + legacyUsed += 1; + } else { + /** If legacy fetch fails, production still proceeds with aggregator-only read; legacy tokens N/A for that item */ + tokensLegacy += estimateTokens(item.summary); + } + } + + const errors = [...ingest.errors]; + let draftsCreated = 0; + + const wpBase = process.env.ANDEBOL_WP_BASE ?? 'http://127.0.0.1:8081/wp-json'; + const wpUser = process.env.ANDEBOL_WP_USER ?? ''; + const wpPass = process.env.ANDEBOL_WP_APP_PASSWORD ?? ''; + + if (!dryRun && publishMax > 0 && wpUser && wpPass) { + const toPublish = list.slice(0, publishMax); + for (const item of toPublish) { + try { + const { id } = await createDraftFromAggregatedItem(item, { + wpBase, + username: wpUser, + appPassword: wpPass, + }); + draftsCreated += 1; + const updated: AggregatedItem = { ...item, wpDraftId: id }; + store = upsertItem(store, updated).store; + } catch (e) { + errors.push(`draft ${item.url}: ${e instanceof Error ? e.message : String(e)}`); + } + } + await saveStore(storePath, store); + } else if (!dryRun && publishMax > 0) { + errors.push( + 'Skipping WP publish: set ANDEBOL_WP_USER and ANDEBOL_WP_APP_PASSWORD (optional ANDEBOL_WP_BASE)', + ); + } + + const finishedAt = new Date().toISOString(); + const metrics: CycleMetrics = { + cycleId, + site, + startedAt, + finishedAt, + feedsAttempted: ingest.attempted, + feedsSucceeded: ingest.succeeded, + feedsFailed: ingest.failed, + newItemsIngested: ingest.newItems, + shortlistSize: list.length, + tokensReadAggregatorPath: tokensAgg, + tokensReadLegacyPath: tokensLegacy, + estimatedReadCostUsdAggregator: estimatedInputCostUsd(tokensAgg), + estimatedReadCostUsdLegacy: estimatedInputCostUsd(tokensLegacy), + draftsCreated, + dryRun, + fallbackLegacyFetchUsed: legacyUsed, + errors, + }; + + await appendMetrics(metricsPath, metrics); + console.log(JSON.stringify(metrics, null, 2)); + if (errors.length) process.exitCode = 1; +} + +main().catch((e) => { + console.error(e); + process.exit(1); +}); diff --git a/writer-pipeline/src/store.ts b/writer-pipeline/src/store.ts new file mode 100644 index 0000000..b79d04e --- /dev/null +++ b/writer-pipeline/src/store.ts @@ -0,0 +1,73 @@ +import { createHash } from 'node:crypto'; +import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import type { AggregatedItem, StoreFile } from './types.js'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +export const DEFAULT_STORE_PATH = path.resolve(__dirname, '../var/aggregated-items.json'); + +export function canonicalUrl(raw: string): string { + try { + const u = new URL(raw); + for (const key of [...u.searchParams.keys()]) { + if (key.toLowerCase().startsWith('utm_')) u.searchParams.delete(key); + } + return u.toString(); + } catch { + return raw.trim(); + } +} + +export function itemId(canonical: string): string { + return createHash('sha256').update(canonical).digest('hex').slice(0, 20); +} + +async function ensureDir(filePath: string): Promise { + await mkdir(path.dirname(filePath), { recursive: true }); +} + +export async function loadStore(storePath: string): Promise { + try { + const raw = await readFile(storePath, 'utf8'); + const parsed = JSON.parse(raw) as StoreFile; + if (parsed?.version === 1 && Array.isArray(parsed.items)) return parsed; + } catch { + // missing or corrupt + } + return { version: 1, items: [] }; +} + +export async function saveStore(storePath: string, store: StoreFile): Promise { + await ensureDir(storePath); + const tmp = `${storePath}.${process.pid}.tmp`; + const body = `${JSON.stringify(store, null, 0)}\n`; + await writeFile(tmp, body, 'utf8'); + await rename(tmp, storePath); +} + +export function upsertItem(store: StoreFile, item: AggregatedItem): { store: StoreFile; isNew: boolean } { + const idx = store.items.findIndex((i) => i.id === item.id); + const isNew = idx < 0; + const next = { ...store, items: [...store.items] }; + if (idx >= 0) { + const prev = next.items[idx]; + next.items[idx] = { + ...item, + wpDraftId: prev.wpDraftId, + skippedReason: prev.skippedReason, + }; + } else next.items.push(item); + return { store: next, isNew }; +} + +export function shortlist( + store: StoreFile, + site: string, + limit: number, +): AggregatedItem[] { + return store.items + .filter((i) => i.site === site && !i.wpDraftId && !i.skippedReason) + .sort((a, b) => (a.publishedAt < b.publishedAt ? 1 : a.publishedAt > b.publishedAt ? -1 : 0)) + .slice(0, limit); +} diff --git a/writer-pipeline/src/token-metrics.ts b/writer-pipeline/src/token-metrics.ts new file mode 100644 index 0000000..a3b700f --- /dev/null +++ b/writer-pipeline/src/token-metrics.ts @@ -0,0 +1,22 @@ +/** Rough GPT-style token estimate (chars / 4). Good enough for before/after comparison. */ +export function estimateTokens(text: string): number { + if (!text) return 0; + return Math.ceil(text.length / 4); +} + +/** Reference pricing for reporting only — adjust in runbook when models change. */ +export const REF_INPUT_USD_PER_1M = 0.15; + +export function estimatedInputCostUsd(tokens: number): number { + return (tokens / 1_000_000) * REF_INPUT_USD_PER_1M; +} + +/** Build the minimal context the writer would send to an LLM after aggregator-first policy. */ +export function aggregatorReadContext(item: { title: string; summary: string; url: string }): string { + return [ + 'Use only the following structured source material (do not assume unseen article body):', + `Title: ${item.title}`, + `Summary: ${item.summary}`, + `Source URL: ${item.url}`, + ].join('\n'); +} diff --git a/writer-pipeline/src/types.ts b/writer-pipeline/src/types.ts new file mode 100644 index 0000000..03f6c9a --- /dev/null +++ b/writer-pipeline/src/types.ts @@ -0,0 +1,54 @@ +export interface FeedSource { + id: string; + url: string; + enabled: boolean; + note?: string; +} + +export interface SiteSourcesConfig { + site: string; + feeds: FeedSource[]; +} + +export interface AggregatedItem { + id: string; + site: string; + sourceFeedId: string; + url: string; + title: string; + summary: string; + publishedAt: string; + ingestedAt: string; + ingestError?: string; + /** Set when a draft was created in WordPress */ + wpDraftId?: number; + skippedReason?: string; +} + +export interface StoreFile { + version: 1; + items: AggregatedItem[]; +} + +export interface CycleMetrics { + cycleId: string; + site: string; + startedAt: string; + finishedAt: string; + feedsAttempted: number; + feedsSucceeded: number; + feedsFailed: number; + newItemsIngested: number; + shortlistSize: number; + /** Estimated prompt tokens if the writer uses only aggregator fields (read path) */ + tokensReadAggregatorPath: number; + /** Estimated tokens if the writer fetched full HTML for each shortlisted item (legacy read path) */ + tokensReadLegacyPath: number; + /** Assumed USD for read-phase only (see docs for model pricing reference) */ + estimatedReadCostUsdAggregator: number; + estimatedReadCostUsdLegacy: number; + draftsCreated: number; + dryRun: boolean; + fallbackLegacyFetchUsed: number; + errors: string[]; +} diff --git a/writer-pipeline/src/wp-publish.ts b/writer-pipeline/src/wp-publish.ts new file mode 100644 index 0000000..2a5e406 --- /dev/null +++ b/writer-pipeline/src/wp-publish.ts @@ -0,0 +1,76 @@ +import type { AggregatedItem } from './types.js'; + +export interface WpPublishConfig { + wpBase: string; + username: string; + appPassword: string; +} + +function stripTags(html: string): string { + return html.replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim(); +} + +function draftContent(item: AggregatedItem): string { + const excerpt = stripTags(item.summary).slice(0, 400); + return [ + '', + `

Resumo agregado (fonte primária antes de leitura LLM completa): ${excerpt}

`, + '', + '', + `

Artigo original (${item.sourceFeedId})

`, + '', + ].join('\n'); +} + +async function resolveCategoryId( + base: string, + authHeader: string, + slug: string, +): Promise { + const url = `${base}/wp/v2/categories?slug=${encodeURIComponent(slug)}`; + const res = await fetch(url, { + headers: { Accept: 'application/json', Authorization: authHeader }, + signal: AbortSignal.timeout(8000), + }); + if (!res.ok) return null; + const rows = (await res.json()) as { id: number }[]; + return rows[0]?.id ?? null; +} + +export async function createDraftFromAggregatedItem( + item: AggregatedItem, + cfg: WpPublishConfig, + categorySlug = 'nacional', +): Promise<{ id: number; link?: string }> { + const base = cfg.wpBase.replace(/\/$/, ''); + const token = Buffer.from(`${cfg.username}:${cfg.appPassword}`, 'utf8').toString('base64'); + const authHeader = `Basic ${token}`; + + const categoryId = await resolveCategoryId(base, authHeader, categorySlug); + const body: Record = { + title: item.title, + content: draftContent(item), + status: 'draft', + excerpt: stripTags(item.summary).slice(0, 300), + }; + if (categoryId) body.categories = [categoryId]; + + const res = await fetch(`${base}/wp/v2/posts`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + Authorization: authHeader, + }, + body: JSON.stringify(body), + signal: AbortSignal.timeout(15000), + }); + + if (!res.ok) { + const errText = await res.text().catch(() => ''); + throw new Error(`WP draft failed ${res.status}: ${errText.slice(0, 500)}`); + } + + const post = (await res.json()) as { id: number; link?: string }; + return { id: post.id, link: post.link }; +} diff --git a/writer-pipeline/tsconfig.json b/writer-pipeline/tsconfig.json new file mode 100644 index 0000000..6869e57 --- /dev/null +++ b/writer-pipeline/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "outDir": "dist", + "rootDir": "src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "resolveJsonModule": true, + "declaration": true, + "sourceMap": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/writer-pipeline/var/.gitignore b/writer-pipeline/var/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/writer-pipeline/var/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore