fix(MultiModalModel): Lazy-load SmartPdf and guard document processing across providers; ensure SmartPdf is initialized only when needed
This commit is contained in:
@@ -111,19 +111,30 @@ export interface ImageResponse {
|
||||
export abstract class MultiModalModel {
|
||||
/**
|
||||
* SmartPdf instance for document processing
|
||||
* Shared across all methods that need PDF functionality
|
||||
* Lazy-loaded only when PDF processing is needed to avoid starting browser unnecessarily
|
||||
*/
|
||||
protected smartpdfInstance: plugins.smartpdf.SmartPdf;
|
||||
protected smartpdfInstance: plugins.smartpdf.SmartPdf | null = null;
|
||||
|
||||
/**
|
||||
* Ensures SmartPdf instance is initialized and ready
|
||||
* Call this before using smartpdfInstance in document processing methods
|
||||
*/
|
||||
protected async ensureSmartpdfReady(): Promise<void> {
|
||||
if (!this.smartpdfInstance) {
|
||||
this.smartpdfInstance = new plugins.smartpdf.SmartPdf();
|
||||
await this.smartpdfInstance.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the model and any necessary resources
|
||||
* Should be called before using any other methods
|
||||
*/
|
||||
public async start(): Promise<void> {
|
||||
this.smartpdfInstance = new plugins.smartpdf.SmartPdf();
|
||||
await this.smartpdfInstance.start();
|
||||
// SmartPdf is now lazy-loaded only when needed for PDF processing
|
||||
// This avoids starting a browser unless document() method is actually used
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up any resources used by the model
|
||||
* Should be called when the model is no longer needed
|
||||
@@ -131,6 +142,7 @@ export abstract class MultiModalModel {
|
||||
public async stop(): Promise<void> {
|
||||
if (this.smartpdfInstance) {
|
||||
await this.smartpdfInstance.stop();
|
||||
this.smartpdfInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user