ng2-pdfjs-viewer
Version:
The most comprehensive Angular PDF viewer, powered by Mozilla PDF.js 6 — view, annotate, sign, fill forms, search, and read aloud from one component. 8.3M+ downloads, mobile-first, production-ready.
63 lines (61 loc) • 2.34 kB
TypeScript
interface PdfPageText {
page: number;
text: string;
}
interface PdfAiAssistantConfig {
endpoint: string;
apiKey?: string;
model?: string;
headers?: Record<string, string>;
maxContextChars?: number;
temperature?: number;
stream?: boolean;
}
interface PdfAiMessage {
role: "system" | "user" | "assistant";
content: string;
}
interface PdfAiPanelConfig extends PdfAiAssistantConfig {
title?: string;
placeholder?: string;
}
interface PdfAiPanelMessage {
role: "user" | "assistant";
content: string;
error?: string;
parts: Array<{
text?: string;
page?: number;
}>;
}
declare class PdfAiAssistant {
private readonly config;
constructor(config: PdfAiAssistantConfig);
/**
* Ask a free-form question about the document. `documentText` is the output
* of PdfJsViewerComponent.getDocumentText(); `history` carries prior turns
* for multi-turn chat.
*/
ask(question: string, documentText: PdfPageText[], history?: PdfAiMessage[], signal?: AbortSignal, onToken?: (full: string, delta: string) => void): Promise<string>;
/** One-shot document summary. */
summarize(documentText: PdfPageText[]): Promise<string>;
/**
* Raw chat-completions call for custom prompting. Pass `onToken` to stream the
* answer token-by-token (the callback receives the running full text and the
* latest delta); the Promise still resolves to the complete text. Streaming is
* requested only when `onToken` is given and `config.stream !== false`, and it
* falls back to a single JSON response if the endpoint doesn't stream.
*/
complete(messages: PdfAiMessage[], signal?: AbortSignal, onToken?: (full: string, delta: string) => void): Promise<string>;
/**
* Read an OpenAI-style Server-Sent Events stream, accumulating
* choices[0].delta.content and emitting each delta through onToken. Returns the
* full concatenated text. Tolerates chunk boundaries that split SSE lines, and
* skips frames it can't parse (keep-alive comments, non-`data:` lines) rather
* than failing the whole stream.
*/
private readStream;
private buildContext;
}
export { PdfAiAssistant };
export type { PdfAiAssistantConfig, PdfAiMessage, PdfAiPanelConfig, PdfAiPanelMessage, PdfPageText };