UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

56 lines (55 loc) 2.75 kB
/** * File Content Summarization Pipeline * * Provides utilities to detect when attached file content exceeds the * model's available context budget and to plan / build prompts for * LLM-driven summarization of the largest files. * * Design rationale: * - Files are the #1 cause of context overflow when users attach * multiple large documents (PDFs, spreadsheets, source code). * - Rather than blindly truncating, we ask an LLM to produce a * *context-aware* summary that retains the information most * relevant to the user's actual question. * - The caller (FileSummarizationService) is responsible for the * actual LLM calls; this module is pure computation + types. */ import type { FileForSummarization, FileSummarizationCheckParams, FileSummarizationCheckResult, FileSummarizationPromptParams, FileSummarizationPlanEntry } from "../types/index.js"; /** Fraction of the context window reserved for non-file content overhead */ export declare const NON_FILE_RESERVE = 0.15; /** Minimum tokens a single file can be allocated in the plan */ export declare const MIN_PER_FILE_TOKENS = 500; /** Maximum tokens a single file can be allocated in the plan */ export declare const MAX_PER_FILE_TOKENS = 4000; /** * Files with fewer estimated tokens than this threshold are never * summarized — they're already small enough to include verbatim. */ export declare const FILE_SUMMARIZATION_THRESHOLD = 1000; /** * Check whether the attached files push the total input token count * beyond the model's available context window. * * When the total exceeds the budget, we calculate how many tokens are * available for files (after accounting for system prompt, conversation * history, current prompt, and tool definitions) and divide that * equally across all files to derive a per-file budget. */ export declare function shouldSummarizeFiles(params: FileSummarizationCheckParams): FileSummarizationCheckResult; /** * Build the LLM prompt used to summarize a single file's content. * * The prompt is *context-aware*: it includes the user's original question * so the LLM can prioritise the most relevant parts of the file. */ export declare function buildFileSummarizationPrompt(params: FileSummarizationPromptParams): string; /** * Decide which files need summarization and how much budget each gets. * * Strategy: * 1. Sort files largest-first. * 2. Walk through the list, marking the largest files for summarization * until the cumulative saved tokens bring us under budget. * 3. Files below `FILE_SUMMARIZATION_THRESHOLD` are never summarized. */ export declare function planFileSummarization(files: FileForSummarization[], params: FileSummarizationCheckParams): FileSummarizationPlanEntry[];