@@ -25,7 +25,7 @@ export class TranscriptWatcher {
2525 private logger : Logger ;
2626 private pollIntervalMs : number ;
2727 private initializedAt : number ;
28- private sqlJsPromise : Promise < SqlJsModule > | null = null ;
28+ private sqlJsPromise : Promise < SqlJsModule | null > | null = null ;
2929
3030 constructor ( logger : Logger ) {
3131 this . logger = logger ;
@@ -96,13 +96,20 @@ export class TranscriptWatcher {
9696 return found ;
9797 }
9898
99- private async getSqlJs ( ) : Promise < SqlJsModule > {
99+ private async getSqlJs ( ) : Promise < SqlJsModule | null > {
100100 if ( ! this . sqlJsPromise ) {
101- const initSqlJs = eval ( 'require' ) ( 'sql.js' ) as SqlJsInit ;
102- const wasmPath = eval ( 'require' ) . resolve ( 'sql.js/dist/sql-wasm.wasm' ) ;
103- this . sqlJsPromise = fsAsync
104- . readFile ( wasmPath )
105- . then ( ( wasmBinary ) => initSqlJs ( { wasmBinary : new Uint8Array ( wasmBinary ) } ) ) ;
101+ try {
102+ const requireFunc = eval ( 'require' ) as NodeRequire ;
103+ const initSqlJs = requireFunc ( 'sql.js' ) as SqlJsInit ;
104+ const wasmPath = requireFunc . resolve ( 'sql.js/dist/sql-wasm.wasm' ) ;
105+ this . sqlJsPromise = fsAsync
106+ . readFile ( wasmPath )
107+ . then ( ( wasmBinary ) => initSqlJs ( { wasmBinary : new Uint8Array ( wasmBinary ) } ) ) ;
108+ } catch ( e ) {
109+ this . logger . warn ( 'sql.js not available; SQLite transcript logs will be skipped.' ) ;
110+ this . logger . debugException ( e ) ;
111+ this . sqlJsPromise = Promise . resolve ( null ) ;
112+ }
106113 }
107114
108115 return this . sqlJsPromise ;
@@ -219,6 +226,7 @@ export class TranscriptWatcher {
219226 fallbackTimestamp ?: number ,
220227 ) : Promise < TranscriptHeartbeat [ ] > {
221228 const SQL = await this . getSqlJs ( ) ;
229+ if ( ! SQL ) return [ ] ;
222230 const db = new SQL . Database ( new Uint8Array ( await fsAsync . readFile ( filePath ) ) ) ;
223231
224232 try {
0 commit comments