/** * @fileoverview Service for fetching and processing plain-text book files from * Project Gutenberg. Handles BOM stripping, boilerplate extraction via START/END * markers, CRLF normalization, HTML fallback, offset/limit chunking, and a 24-hour * in-process text cache keyed by Gutenberg ID. * @module services/gutenberg-text/gutenberg-text-service */ import type { Context } from '@cyanheads/mcp-ts-core'; import type { AppConfig } from '@cyanheads/mcp-ts-core/config'; import type { StorageService } from '@cyanheads/mcp-ts-core/storage'; import type { ServerConfig } from '../../config/server-config.js'; import type { Book } from '../gutendex/types.js'; import type { CachedText, TextChunk } from './types.js'; export declare class GutenbergTextService { private readonly textBaseUrl; constructor(_config: AppConfig, _storage: StorageService, serverConfig: ServerConfig); /** * Resolve the best text URL and format from a book's formats map. * Returns null when no readable format is available. */ private resolveTextUrl; /** * Fetch the raw bytes for a book URL and decode as UTF-8. The mirror serves * generated UTF-8 for both the plain-text and HTML cache files. * * The whole ladder runs under one budget, and an exhausted budget surfaces as * `text_fetch_failed` with the calling tool's declared recovery hint. The * message names the book rather than the resolved cache-path URL, which * carries the operator's configured mirror host; the original error stays on * `cause` for server-side logs. A caller cancel passes through unchanged. */ private fetchRaw; /** * Run the full text-processing pipeline for a given book. * Returns the stripped, normalized literary text. */ private processRaw; /** * Fetch, process, and cache the full stripped text for a book. * Throws no_text_format if no usable format; `fetchRaw` throws text_fetch_failed * when the mirror ladder exhausts its budget. */ fetchAndCacheText(book: Book, id: number, ctx: Context): Promise; /** * Chunk the cached text at the requested offset/limit, with soft paragraph-boundary * trimming (backtracks up to 500 chars to the nearest \n\n to avoid mid-paragraph cuts). */ chunkText(cached: CachedText, offset: number, limit: number): TextChunk; } export declare function initGutenbergTextService(config: AppConfig, storage: StorageService, serverConfig: ServerConfig): void; export declare function getGutenbergTextService(): GutenbergTextService; //# sourceMappingURL=gutenberg-text-service.d.ts.map