@@ -55,12 +55,23 @@ async function loadModel() {
5555 }
5656 }
5757
58- // 2. Check WebGPU
58+ // 2. Check WebGPU — GLM-OCR requires WebGPU (q4f16 external data files
59+ // cannot be loaded by WASM's Module.MountedFiles)
5960 if ( typeof navigator !== "undefined" && navigator . gpu ) {
6061 const adapter = await navigator . gpu . requestAdapter ( ) ;
6162 if ( adapter ) device = "webgpu" ;
6263 }
6364
65+ if ( device !== "webgpu" ) {
66+ self . postMessage ( {
67+ type : "error" ,
68+ message : "GLM-OCR requires WebGPU which is not available in this browser. " +
69+ "Please use Chrome 113+, Edge 113+, or another WebGPU-capable browser. " +
70+ "Alternatively, use Granite Docling or Florence-2 which work without WebGPU." ,
71+ } ) ;
72+ return ;
73+ }
74+
6475 // Progress callback factory
6576 const progressCb = ( label ) => ( progress ) => {
6677 if ( progress . status === "progress" ) {
@@ -108,16 +119,43 @@ async function loadModel() {
108119 } ) ;
109120 }
110121
111- // 3. Load with fallback
122+ // 3. Load with fallback to onnx-community mirror
112123 try {
113124 await loadFromHost ( ) ;
114125 } catch ( primaryErr ) {
126+ // Detect the known external-data incompatibility with onnxruntime-web 1.19.x
127+ const errMsg = primaryErr . message || "" ;
128+ if ( errMsg . includes ( "MountedFiles" ) || errMsg . includes ( "external data file" ) ) {
129+ self . postMessage ( {
130+ type : "error" ,
131+ message : "GLM-OCR is temporarily unavailable — the model's quantized weights require " +
132+ "a newer ONNX Runtime version that isn't yet compatible with this library. " +
133+ "Please use Granite Docling or Florence-2 for OCR in the meantime." ,
134+ } ) ;
135+ return ;
136+ }
137+
115138 console . warn ( `textagent model failed: ${ primaryErr . message } . Falling back to ${ MODEL_ORG_FALLBACK } …` ) ;
116139 self . postMessage ( { type : "status" , message : `Falling back to ${ MODEL_ORG_FALLBACK } models…` } ) ;
117140 MODEL_ID = MODEL_ID . replace ( 'textagent/' , MODEL_ORG_FALLBACK + '/' ) ;
118141 processor = null ;
119142 model = null ;
120- await loadFromHost ( ) ;
143+
144+ try {
145+ await loadFromHost ( ) ;
146+ } catch ( fallbackErr ) {
147+ const fbMsg = fallbackErr . message || "" ;
148+ if ( fbMsg . includes ( "MountedFiles" ) || fbMsg . includes ( "external data file" ) ) {
149+ self . postMessage ( {
150+ type : "error" ,
151+ message : "GLM-OCR is temporarily unavailable — the model's quantized weights require " +
152+ "a newer ONNX Runtime version that isn't yet compatible with this library. " +
153+ "Please use Granite Docling or Florence-2 for OCR in the meantime." ,
154+ } ) ;
155+ return ;
156+ }
157+ throw fallbackErr ;
158+ }
121159 }
122160
123161 self . postMessage ( { type : "loaded" , device : device } ) ;
0 commit comments